/*'*******************************************************************************
'   Function Name 		fnMandatoryTxtBox
'   Description		    It Gives an alert if a particular textBox is left Blank
'   Parameters          oObjectId -   passed as ObjectID of the element 
'						sQuestiontext - QuestionText
'
'   Modification(Log)
'   Date                  Author			       Remarks     
' 	13-Mar-2006   Kumar Brajesh[Infosys]        Initial version
'**********************************************************************************/		
var g_bFlag = false;
function fnMandatoryTxtBox(oObjectId, sQuestiontext)
{
var oObject;
var bFlag = true;

	oObject = document.getElementById(oObjectId);
	if (oObject != null)
	{
		if(oObject.value=="")
		{
			alert('Please enter value for ' + sQuestiontext);
			oObject.focus();
			bFlag = false;
		}
	}
	return bFlag;
}

/*'*******************************************************************************
'   Function Name 		fnMandatoryDropDown
'   Description		    It Gives an alert if the From a particular DropDown 
'                        not a single item is selected
'   Parameters          oObjectId -   passed as ObjectID of the element 
'						sQuestiontext - QuestionText
'
'   Modification(Log)
'   Date                  Author			       Remarks     
' 	13-Mar-2006   Kumar Brajesh[Infosys]        Initial version
'**********************************************************************************/	
function fnMandatoryDropDown(oObjectId, sQuestiontext)
{	
 var oObject;
 var bFlag = true;
	oObject = document.getElementById(oObjectId)
	if (oObject != null)
	{
		if(oObject.selectedIndex==0)
		{
			alert('Please enter value for ' + sQuestiontext);
			oObject.focus();
			bFlag = false;
		}
	}
return bFlag;
}
/*'*******************************************************************************
'   Function Name 		fnIsEmpty()
'   Description		    It Checks whether a Particular Field is Blank
'   Parameters          oObjectId -   passed as ObjectID of the element 
'   Modification(Log)
'   Date                  Author			       Remarks     
' 	13-Mar-2006   Kumar Brajesh[Infosys]        Initial version
'**********************************************************************************/

function fnIsEmpty(oObjectId)
{
var oObject;

 oObject = document.getElementById(oObjectId)
	if (oObject != null)
	{
	if (oObject.value == "" )
		return true
	else
		return false
	}
	else
	return true;
}
/*'*******************************************************************************
'   Function Name 		fnValidateSpecialCharector
'   Description		    It Gives an alert if Any special Charecter is Entered
'   Parameters          oObjectId -   passed as ObjectID of the element 
'						sQuestiontext - QuestionText
'
'   Modification(Log)
'   Date                  Author			       Remarks     
' 	13-Mar-2006   Kumar Brajesh[Infosys]        Initial version
'**********************************************************************************/	

function fnValidateSpecialCharacter(oObjectId, sQuestiontext)
{	
    var oObject;
    var bFlag = true;
	oObject = document.getElementById(oObjectId)
	
	var value;
	if (oObject != null)
	{
		// will send true if there is no entry and will not check for 
		// spaces as it wont trim spaces
		if (fnIsEmpty(oObjectId) == true)
			return true;
		value = oObject.value;
		strVal=/[^A-Za-z0-9]/;

		if(strVal.exec(value) != null )
		{
			alert('Please enter Valid value for ' + sQuestiontext);
			oObject.focus();
			bFlag = false;
		}
	}
    return bFlag ;
}

/********************************************************************************
'   Function Name 		fnValidateEmail
'   Description		    It Gives an alert if A wrong EmailID is entered or it left Blank
'   Parameters          oObjectId -   passed as ObjectID of the element 
'						sQuestiontext - QuestionText
'
'   Modification(Log)
'   Date                  Author			       Remarks     
' 	13-Mar-2006   Kumar Brajesh[Infosys]        Initial version
'**********************************************************************************/	

function fnValidateEmail(oObjectId, sQuestionText) 
{ 
    var oObject;
    var bFlag = true;
	oObject = document.getElementById(oObjectId)
	if (oObject != null)
	{
		var sValue = oObject.value;
		if(sValue=="")
		{
			alert('Please enter a ' + sQuestionText + ' to proceed ');
			oObject.focus();
			return false;
		}	
		if(sValue.length>126)
		{
			alert(sQuestionText + ' cannot be more than 126 chars long');
			oObject.focus();	
			return false;
		}
		var oRegExp = /^([a-zA-Z0-9_\-\.]+)@((\[[0-9]*\.[0-9]*\.[0-9]*\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]*|[0-9]*)(\]?)[a-zA-Z0-9]$/;
		//check for valid email
		if(!(oRegExp.test(sValue)))
		{
			alert('Please enter Valid value for ' + sQuestionText);
			oObject.focus();
			bFlag= false;
		}	
	}
return bFlag;
}

/*'*******************************************************************************
'   Function Name 		fnValidateWorkPhone
'   Description		    It Gives an alert if A wrong EmailID is entered or it left Blank
'   Parameters          oObjectId -   passed as ObjectID of the element 
'						sQuestiontext - QuestionText
'
'   Modification(Log)
'   Date                  Author			       Remarks     
' 	13-Mar-2006   Kumar Brajesh[Infosys]        Initial version
'**********************************************************************************/
function fnValidateWorkPhone(oObjectId, sQuestionText)
{
var oObject;
var bFlag = true;
oObject=document.getElementById(oObjectId);
	if (oObject != null)
	{
	var sValue = oObject.value;
	if(sValue=="")
	{
		alert('Please enter a ' + sQuestionText + ' id to proceed ');
		oObject.focus();
		return false;
	}	
	strVal=/[A-Za-z0-9-]/;

    if(strVal.exec(sValue) == null )
	{
		alert('Please enter Valid value for ' + sQuestionText);
        oObject.focus();
		bFlag = false;
    }
  }
return bFlag ;
}
/*'*******************************************************************************
'   Function Name 		fnValidateNumeric
'   Description		    It Gives an alert if other than number is entered
'   Parameters          oObjectId -   passed as ObjectID of the element 
'						sQuestiontext - QuestionText
'
'   Modification(Log)
'   Date                  Author			       Remarks     
' 	13-Mar-2006   Kumar Brajesh[Infosys]        Initial version
'**********************************************************************************/

function fnValidateNumeric(oObjectId, sQuestiontext)
{	
    var oObject;
    var bFlag = true;
	oObject = document.getElementById(oObjectId);
	if (oObject != null)
	{
		var sValue=oObject.value;
		strVal=/[^0-9]/;
		if(strVal.exec(sValue) != null )
		{
			alert('Please enter only number  for ' + sQuestiontext);
			oObject.focus();
			bFlag = false;
		}
	}
    return bFlag ;
}

/*'*******************************************************************************
'   Function Name 		fnValidateAlphabet
'   Description		    It Gives an alert if other than Alphabet is entered
'   Parameters          oObjectId -   passed as ObjectID of the element 
'						sQuestiontext - QuestionText
'
'   Modification(Log)
'   Date                  Author			       Remarks     
' 	13-Mar-2006   Kumar Brajesh[Infosys]        Initial version
'**********************************************************************************/

function fnValidateAlphabet(oObjectId, sQuestiontext)
{	
    var oObject;
    var bFlag = true;
	oObject = document.getElementById(oObjectId);
	if (oObject != null)
	{
		var sValue=oObject.value;
		strVal=/[^a-zA-Z]/;
		if(strVal.exec(sValue) != null )
		{
			alert('Please enter only Alphabet  for ' + sQuestiontext);
			oObject.focus();
			bFlag = false;
		}
	}
    return bFlag ;
}	
	
/*'*******************************************************************************
'   Function Name 		fnValidatePhone
'   Description		    It Gives an alert if Any special Charecter is Entered
'   Parameters          oObjectId -   passed as ObjectID of the element 
'						sQuestiontext - QuestionText
'
'   Modification(Log)
'	Version		Date                  Author			       Remarks     
' 				13-Mar-2006   Kumar Brajesh[Infosys]        Initial version
'		2.0		10-July-2006  Nilesh Lokhande				Modified to check valid phone number
'**********************************************************************************/	

function fnValidatePhone(oObjectId, sQuestiontext)
{	
	var oObject;
    var bFlag = true;
	oObject = document.getElementById(oObjectId)
	
	var value;
	if (oObject != null)
	{
		// will send true if there is no entry and will not check for 
		// spaces as it wont trim spaces
		
		value = oObject.value;
		//************************************* Begin Ver 2.0 *************************************
		if(oObject.value=="")
		{
			alert('Please enter value for ' + sQuestiontext);
			oObject.focus();
			bFlag = false;
		}
		
		strVal=/[^A-Za-z0-9-]/;
		
		//************************************* End Ver 2.0 *************************************

		if(strVal.exec(value)!= null)
		{
			alert('Please enter Valid value for ' + sQuestiontext);
			oObject.focus();
			bFlag = false;
		}
	}
    return bFlag ;
}
	
/*'*******************************************************************************
'   Function Name 		fnMandatoryRadiobuttonList
'   Description		    It Gives an alert if the From a particular RadioButtonList is Not Selected
'                        not a single item is selected
'   Parameters          oObjectId -   passed as ObjectID of the element 
'						sQuestiontext - QuestionText
'
'   Modification(Log)
'   Date                  Author			       Remarks     
' 	13-Mar-2006   Kumar Brajesh[Infosys]        Initial version
'**********************************************************************************/	
function fnMandatoryRadiobuttonList(oObjectName, sQuestiontext)
{
	
	var oObjectArr;
	var bFlag = false;
	
	oObjectArr = document.getElementsByName(oObjectName);	
	if (oObjectArr != null)
	{
		if(oObjectArr.length > 0)
		{
			for(i=0;i<oObjectArr.length;i++)
			{			
				if(oObjectArr[i].checked == true)
				{  
					bFlag = true;
				}
			}
		
			if(bFlag == false)
			{
				alert('Please select a  value for ' + sQuestiontext);
				oObjectArr[0].focus();
			}	
			
			return bFlag;		
		}
	}
		
	return true;
}

/*'*******************************************************************************
'   Function Name 	fnControlValidation
'   Description		Common window to the forms to validate the "Call to Action" controls'                        
'   Parameters          obj -   object type of the control
'			objNameId - Name/Id value of the associated control
'
'   Modification(Log)
'   Date                Author			       Remarks     
' 	15-May-2006   	Arun S        		Initial version
'**********************************************************************************/	

function fnControlValidation(obj, objNameId) {
	if(g_bFlag!=true)
	{
		var oElementObj = document.getElementById(objNameId)
		
		if(obj=="textbox") {
		var formValue = oElementObj.value;
			if(formValue=="") {
				oElementObj.focus();
				return false;
			} 
		}
		if (obj=="checkbox"){
			if (fnGetSelectedItemFromCheckBoxRadioList(obj, objNameId)=="") {				
				return false;
			}
		}
		if(obj=="radio"){			
			if (fnGetSelectedItemFromCheckBoxRadioList(obj, objNameId)=="") {
				return false;
			}
		}
		
		if(obj=="listbox"){	
			if (fnGetSelectedItemFromListBox(obj, objNameId)==false) {
				oElementObj.focus();
				return false;
			}
		}	
		
		if(obj=="dropDown"){	
			if (fnGetSelectedItemFromDropDown(obj, objNameId)==false) {
				oElementObj.focus();
				return false;
			}
		}
		g_bFlag = true;
	}	
}
 
 /*'*******************************************************************************
 '   Function Name 	fnGetSelectedItemFromCheckBoxRadioList
 '   Description		Check the values from Radiobutton / Checkbox list
 '   Parameters         objType-   object type of the control
 '			objNameIdVal - Name/Id value of the associated control
 '
 '   Modification(Log)
 '   Date                Author			       Remarks     
 ' 	15-May-2006   	Arun S        		Initial version
 '**********************************************************************************/	

function fnGetSelectedItemFromCheckBoxRadioList(objType, objNameIdVal) {
	var objectToCheck;
	var object;
	var objCurrentNameIdValue="";
	var result="";
	object = document.getElementsByName(objNameIdVal);
	if (objType=="radio") {
		objectToCheck="radio"	
	} else {
		objectToCheck="checkbox"	
	}	
	if (object.length > 0) {
		for (var i = 0; i < object.length; i++) {          		
			if (objType=="radio") objCurrentNameIdValue = object[i].name;
			if (objType=="checkbox") objCurrentNameIdValue = object[i].id;			
			if (objCurrentNameIdValue==objNameIdVal) {                    
				if (object[i].checked) {                    	
					return "Y";                        
				}                    
			}	
		}	
	} else {
		objNameIdVal = "CUSShowForm_UA1:" + objNameIdVal;			
		if(document.getElementsByName(objNameIdVal)[0].checked) {
			return "Y";
		}
	}
	return result;
} 
 /*'*******************************************************************************
 '   Function Name 	fnGetSelectedItemFromDropDown
 '   Description		Check the values from Dropdown
 '   Parameters         obj-   object type of the control
 '			objNameId - Name/Id value of the associated control
 '
 '   Modification(Log)
 '   Date                Author			       Remarks     
 ' 	15-May-2006   	Arun S        		Initial version
 '**********************************************************************************/	

function fnGetSelectedItemFromDropDown(obj, objNameId){	
	var myFormObject = document.getElementById(objNameId)	
	if (myFormObject!=null){
		if(myFormObject.selectedIndex==0){		
			return false;
		}	
	}
}
 /*'*******************************************************************************
 '   Function Name 	fnGetSelectedItemFromListBox
 '   Description		Check the values from List box
 '   Parameters         obj-   object type of the control
 '			objNameId - Name/Id value of the associated control
 '
 '   Modification(Log)
 '   Date                Author			       Remarks     
 ' 	15-May-2006   	Arun S        		Initial version
 '**********************************************************************************/	

function fnGetSelectedItemFromListBox(obj, objNameId){	
var myFormObject = document.getElementById(objNameId);
	if(myFormObject.selectedIndex==-1){	
		return false;
	}
}


function fnCheckCallToActionControls(oObjectArr){
	var sTemp="";
	var blnCheck=false;
	g_bFlag=false;
	var objQuestion="";
	var j=0;
	var oCtrls = oObjectArr.split('$');		
	for (i=0;i<oCtrls.length;++i)
	{	
		var oControl = oCtrls[i].split('|');										
		if (fnControlValidation(oControl[0],oControl[1])==false){									
		} else {
			blnCheck=true;			
		}
		if(sTemp!=oControl[2]){
		objQuestion=objQuestion + "\n" + ++j + ") " + oControl[2];	
		}
		sTemp = oControl[2];
	}
	if(blnCheck==false){
		alert("Select atleast one option from " + objQuestion);
	}		
	return g_bFlag;
}
