
function Validate()
{
	isAlphabet(document.getElementById('ncfname'), 'Please Avoid Using & or ^ or ? in the First Name');
	isAlphabet(document.getElementById('nclname'), 'Please Avoid Using & or ^ or ? in the Last Name');
	isNumeric(document.getElementById('WPhone'), 'Work Phone should contain numbers only Please');
	isNumeric(document.getElementById('ncpager'), 'Pager should contain numbers only Please');
	isNumeric(document.getElementById('ncpagerpin'), 'Pager PIN should contain numbers only Please');
	isNumeric(document.getElementById('Hphone'), 'Home Phone should contain numbers only Please');
	emailValidator(document.getElementById('ncemail'), 'Not a Valid Email');	
}

function isAlphabet(elem, helperMsg){
	//alert(elem);
	var alphaExp = /^([^&\^\?]*)([a-zA-Z])+([^&\^\?]*)$/;
	if(elem.value.match(alphaExp)){
		return true;
	}else{
		//alert(document.getElementById("error"));
		document.getElementById("error").innerHTML = helperMsg;
		//elem.focus();
		return false;
	}
}


function isNumeric(elem,  helperMsg){
	var numericExpression = /^[0-9]+$/;
	if(elem.value.match(numericExpression)){
		return true;
	}else{
		document.getElementById("error").innerHTML = helperMsg;
		//elem.focus();
		return false;
	}
}

function emailValidator(elem, helperMsg){
	var emailExp =  /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/
	if(elem.value.match(emailExp)){
		return true;
	}else{
		document.getElementById("error").innerHTML = helperMsg;
		//elem.focus();
		return false;
	}
}
function test(ncfname,nclname,WPhone,ncpager,ncpagerpin,HPhone,ncemail,primarycontact,contacttype)
        {
        	document.getElementById(ncfname).value = "";
			document.getElementById(nclname).value = "";
			document.getElementById(WPhone).value = "";
			document.getElementById(ncpager).value = "";
			document.getElementById(ncpagerpin).value = "";
			document.getElementById(HPhone).value = "";
			document.getElementById(ncemail).value = "";
			document.getElementById(primarycontact).value = "";
			document.getElementById(contacttype).value = "";
       }
       
          function testRequired(id,helperMsg)

            {

                  var scope = document.getElementById("scopeOneSpan");

                  var id=id;

                  var textArea = document.getElementById(lookupIdByTagId(id, scope));

                  //alert(textArea.title);                 

                  var Msg = helperMsg;                

            }                 

            

           /* function textCounter(field,cntfield,maxlimit)

            {

                  var scope = document.getElementById("scopeOneSpan");

                  

                  var field = document.getElementById(lookupIdByTagId(field, scope));

                  var  cntfield = document.getElementById(lookupIdByTagId(cntfield, scope));

                  if (field.value.length > maxlimit) // if too long...trim it!

                  field.value = field.value.substring(0, maxlimit);

                  // otherwise, update 'characters left' counter

                  else

                  cntfield.value = maxlimit - field.value.length;

            }*/
       
  
       function Validate()
		{		
		/*	var btn = valButton(form.group1);
						
			if (btn == null) 
			{
				alert('No button selected');
				document.getElementById("r1").focus(); 
			}
			else 
			{
				alert('Button value ' + btn + ' selected'); 
			}
			*/
	
   		var scope = document.getElementById("scopeOneSpan");
    
   		var form = document.getElementById(lookupIdByTagId("form", scope));
   		//alert(form);
    	
    	//alert("hi");
		
		
	
		}
		
	/*	function descRequired(obj, helperMsg)
		{
			var alphaExp = "";			
			if(obj.value==""){
				document.getElementById("error").innerHTML = helperMsg;
				//obj.focus();
				return false
			}
			else{
				document.getElementById("error").innerHTML = "";
				alert("Value= "+ obj.value);
				return true;
			}	
		}*/	
		
		function valButton(btn) 
		{
		    var cnt = -1;
		    
		    for (var i=((btn.length)-1); i > -1; i--)
		    {
		        if (btn[i].checked) {cnt = i; i = -1;}
		    }
		    if (cnt > -1) return btn[cnt].value;
		    else return null;
		}
		
		
		
		/*----------------------------------------------------------------------------------------------------------------------------------------*/
		
		///////////////////// Hemang Function's ///////////////////////////////
		
		
		function test()
		{
			//alert('Hi....');
		}
		
		
		
		 /*1. Function to chk whether it is valid sold to ----- Starts here 
		 		Calls zeroPad()
		  */
		  
		  
	/* validation functions for CSR starts */
		  
		  
	var soldToFormError = false;	  
		
	function isValidSoldTo(soldToNumberId, soldToErrorId, soldToLocationsId) {
	
		var soldToNumberObj = document.getElementById(soldToNumberId);
		var soldToErrorObj = document.getElementById(soldToErrorId);
		
		soldToErrorObj.style.color = "#cc0000";
		
		// hide the error div
		soldToErrorObj.style.display = "none";
		// set the errror flag to false so user can go to next page (form can be submitted)
		soldToFormError = false;
		     	       	
	    var soldToNumber = soldToNumberObj.value;
	    
	    var paddedSoldToNumber = zeroPad(soldToNumber);
	    //alert(paddedSoldToNumber);
		         	
		if (paddedSoldToNumber.length > 0) {	  	 
			if (paddedSoldToNumber.length > 10) {
		     	soldToErrorObj.innerHTML = "Sold To value must be 10 digits";
		     	soldToErrorObj.style.display = "block";
		     	soldToFormError = true;
		     	//soldToNumberObj.focus();
			} else {
				var soldToLocationObj = document.getElementById(soldToLocationsId);
				for (var i = 0; i < soldToLocationObj.length; i++) {
					var soldToDesc = soldToLocationObj.options[i].value;
					//alert(soldToDesc);
					var usersSoldToNumber = soldToDesc.substring(1,11);
					//alert(usersSoldToNumber)
					if (paddedSoldToNumber == usersSoldToNumber) {
               			soldToLocationObj.options[i].selected = true;
               			var isFound = "yes"
              			break
           			}
         		}
         		if (isFound != "yes") {
            		soldToErrorObj.innerHTML = "Sold to is not associated with user";
		     		soldToErrorObj.style.display = "block";
		     		soldToFormError = true;
		     		//soldToNumberObj.focus();
         		}		       
			}  
		}    	
	}
	
	function displayCreateCasePage1(soldToFormId) {
		//alert(document.getElementById("soldToForm"));
		if(!soldToFormError) {
			document.getElementById(soldToFormId).submit();
		}
	}      
	   
	   // Function to Rtrim the string.........
		function RTrim(str)
		{
		   var w_space = String.fromCharCode(32);
		   var v_length = str.length;
		   var strTemp = "";
		   if(v_length < 0)
		   {
		      return ""
		   }
		   var iTemp = v_length -1
		
		   while(iTemp > -1)
		   {
		      if(str.charAt(iTemp) != w_space)
		      {
		         strTemp = str.substring(0,iTemp +1)
		         break;
		      }
		      iTemp = iTemp-1
		
		   }
		   return strTemp
		}

		// Function to Ltrim the string.........
		function LTrim(str)
		{
		   var w_space = String.fromCharCode(32)
		   if(v_length < 1)
		   {
		      return ""
		   }
		   var v_length = str.length
		   var strTemp = ""
		
		   var iTemp = 0
		
		   while(iTemp < v_length)
		   {
		      if(str.charAt(iTemp) != w_space)
		      {
		         strTemp = str.substring(iTemp,v_length)
		         break
		      }
		      iTemp = iTemp + 1
		   }
		   return strTemp
		}
		
		
		// Function to Trim the string.....Calls Rtrim() and LTrim()
		function trim(str)
		{
		   if(str.length < 1)
		   {
		      return ""
		   }
		
		   str = RTrim(str);
		   str = LTrim(str);
		   if(str == "")
		   {
		      return ""
		   }
		   else
		   {
		      return str;
		   }
		}
		
		
		// Function to Pad the soldToNumebr entered with zero's and trim the string....Calls Trim()
		function zeroPad(str)
		{
		   if(str.length < 1)
		   {
		      return ""
		   }
		   str = trim(str);
		
		   if (str.length > 0)
		   {
		      while(str.length < 10)
		      {
		         str = "0" + str
		      }
		   }
		   return str
		}
		
		
	function sameAsAbove(rbFirstNameId,ocFirstNameId,rbLastNameId,ocLastNameId,rbPhoneId,ocPhoneId,rbEmailId,ocEmailId) {
		document.getElementById(ocFirstNameId).value = document.getElementById(rbFirstNameId).value;
		document.getElementById(ocLastNameId).value = document.getElementById(rbLastNameId).value;
		document.getElementById(ocPhoneId).value = document.getElementById(rbPhoneId).value;
		document.getElementById(ocEmailId).value = document.getElementById(rbEmailId).value;
		
		isValidName('rbFirstName','rbFirstNameError', 'Reported By First Name');
		isValidName('rbLastName','rbLastNameError', 'Reported By Last Name');
		isMandatory('rbPhone','rbPhoneError', 'Reported By Phone');
		isValidEmailAddress('rbEmail','rbEmailError', 'Reported By Email');
		isValidName('ocFirstName','ocFirstNameError', 'Onsite Contact First Name');
		isValidName('ocLastName','ocLastNameError', 'Onsite Contact Last Name');
		isMandatory('ocPhone','ocPhoneError', 'Onsite Contact Phone');
		isValidEmailAddress('ocEmail','ocEmailError', 'Onsite Contact Email');
	}
		
	function enterManually(ocFirstNameId,ocLastNameId,ocPhoneId,ocEmailId) {
		document.getElementById(ocFirstNameId).value = "";
		document.getElementById(ocLastNameId).value = "";
		document.getElementById(ocPhoneId).value = "";
		document.getElementById(ocEmailId).value = "";
		
		isValidName('rbFirstName','rbFirstNameError', 'Reported By First Name');
		isValidName('rbLastName','rbLastNameError', 'Reported By Last Name');
		isMandatory('rbPhone','rbPhoneError', 'Reported By Phone');
		isValidEmailAddress('rbEmail','rbEmailError', 'Reported By Email');
		isValidName('ocFirstName','ocFirstNameError', 'Onsite Contact First Name');
		isValidName('ocLastName','ocLastNameError', 'Onsite Contact Last Name');
		isMandatory('ocPhone','ocPhoneError', 'Onsite Contact Phone');
		isValidEmailAddress('ocEmail','ocEmailError', 'Onsite Contact Email');
			
		/*document.getElementById(ocFirstName).disabled = false;
		document.getElementById(ocLastName).disabled = false;
		document.getElementById(ocPhone).disabled = false;
		document.getElementById(ocEmail).disabled = false;*/
	}
	
	function isValidName(nameId, nameErrorId, fieldName) {
	
		var nameObj = document.getElementById(nameId);
		var nameErrorObj = document.getElementById(nameErrorId);
		
		nameErrorObj.style.color = "#cc0000";
		
		// hide the error div
		nameErrorObj.style.display = "none";
			     	       	
	    var name = nameObj.value;
	    
	    if(name != "") {
			if (name.match(/[(),@#<>'!~&]/)) {
				//nameErrorObj.innerHTML = "Error: Contact name cannot contain the following characters: (),@#<>'!~&";
				nameErrorObj.innerHTML = "This " + fieldName + " field can't contain the following characters: (),@#<>'!~&";
		     	nameErrorObj.style.display = "block";
		     	//createCase1Error = true;	
		     	return false;
			}
		} else {
			nameErrorObj.innerHTML = "This " + fieldName + " field is required";
	     	nameErrorObj.style.display = "block";
	     	//createCase1Error = true;
	     	return false;
		}
		return true;
	}
	
	/*	function isValidNumeric(elemId,NumericErrorId)
		{
				var elemObj = document.getElementById(elemId);
				var errorObj = document.getElementById(NumericErrorId);
				
				errorObj.style.color = "#cc0000";
				errorObj.style.display = "block";
				
				var elemValue = elemObj.value;
				
				if(elemValue != "")
				 {
				
						var numericExpression = /^[0-9]+$/;	
						
						if(elemValue.match(numericExpression))
						{
							errorObj.style.display = "none";
						}
						else
						{
							errorObj.innerHTML = "should contain numbers only Please";
							//elemObj.focus();
						}
				} 
				else 
				{
						errorObj.innerHTML = "This field is mandatory";
						//elemObj.focus();
				}	
		}*/
		
	function isMandatory(elemId, errorId, fieldName) {
	
		var elemObj = document.getElementById(elemId);
		var errorObj = document.getElementById(errorId);
		
		errorObj.style.color = "#cc0000";
		
		// hide the error div
		errorObj.style.display = "none";
				     	       	
	    var elemValue = elemObj.value;
	    
	    if(elemValue == "") {
			errorObj.innerHTML = "This " + fieldName + " field is required";
	     	errorObj.style.display = "block";
	     	//createCase1Error = true;
	     	return false;
		}
		return true;
	}
	
			/* To check whether it is valid email id */
	/*	
		function isValidEmailAddress(isValidEmailId, isValidEmailErrorId)
		{
			//	document.getElementById(isValidEmailErrorId).innerHTML = "";
				
				isValidEmail = document.getElementById(isValidEmailId);
				emailErrorObj = document.getElementById(isValidEmailErrorId); 
				
				emailErrorObj.style.color = "#cc0000";
				emailErrorObj.style.display = "block";	 
				
				var emailExp =  /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/
				
				if(isValidEmail.value.match(emailExp))
				{
					emailErrorObj.style.display = "none";
				}
				else
				{
					emailErrorObj.innerHTML = "Not a valid Email Address";
					//isValidEmail.focus();
				}
	  	}*/
	
	function isValidEmailAddress(emailId, emailErrorId, fieldName) {
	
		var emailObj = document.getElementById(emailId);
		var emailErrorObj = document.getElementById(emailErrorId);
		
		emailErrorObj.style.color = "#cc0000";
		
		// hide the error div
		emailErrorObj.style.display = "none";
	     	       	
	    var email = emailObj.value;
	    
	    if(email != "") {
	    	var emailExp =  /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/
			if (!(email.match(emailExp))) {
				emailErrorObj.innerHTML = "This " + fieldName + " field is invalid";
		     	emailErrorObj.style.display = "block";
		     	//createCase1Error = true;
		     	return false;	
			}
		} else {
			emailErrorObj.innerHTML = "This " + fieldName + " field is required";
	     	emailErrorObj.style.display = "block";
	     	//createCase1Error = true;
	     	return false;
		}
		return true;
	}
	
	function displayCreateCasePage2(caseForm1Id) {
		if(isValidName('rbFirstName','rbFirstNameError', 'Reported By First Name') & 
			isValidName('rbLastName','rbLastNameError', 'Reported By Last Name') & 
			isMandatory('rbPhone','rbPhoneError', 'Reported By Phone') &
			isValidEmailAddress('rbEmail','rbEmailError', 'Reported By Email') &
			isValidName('ocFirstName','ocFirstNameError', 'Onsite Contact First Name') &
			isValidName('ocLastName','ocLastNameError', 'Onsite Contact Last Name') &
			isMandatory('ocPhone', 'ocPhoneError', 'Onsite Contact Phone') &
			isValidEmailAddress('ocEmail','ocEmailError', 'Onsite Contact Email')) {
				document.getElementById(caseForm1Id).submit();
		}
	}
	
	
	
	/*var issueTypeSel = false;
	var workedWhenSel = false;
	
	function issueTypeSelected() {
		issueTypeSel = true;
	}
	
	function workedWhenSelected() {
		workedWhenSel = true;
	}
	
	
	
	function isIssueTypeSelected(issueTypeName, issueTypeErrorId) {
			
		var issueTypeErrorObj = document.getElementById(issueTypeErrorId);
		issueTypeErrorObj.style.color = "#cc0000";
		// hide the error div
		issueTypeErrorObj.style.display = "none";
		
		if (!issueTypeSel) {
			issueTypeErrorObj.innerHTML = "Please select an issue type";
	     	issueTypeErrorObj.style.display = "block";
			return false;
		}
		return true;
	}
	
	function isWorkedWhenSelected(workedWhenName, workedWhenErrorId) {
			
		var workedWhenErrorObj = document.getElementById(workedWhenErrorId);
		workedWhenErrorObj.style.color = "#cc0000";
		// hide the error div
		workedWhenErrorObj.style.display = "none";
		
		if (!workedWhenSel) {
			workedWhenErrorObj.innerHTML = "Please indicate whether the function has ever worked before";
	     	workedWhenErrorObj.style.display = "block";
			return false;
		}
		return true;
	}*/
	
	function displayCreateCasePage3(caseForm2Id) {
		
		if(isValidName('descTA','descError', 'Problem Statement') & 
			isIssueTypeSelected('issueType','issueTypeError') &
			isWorkedWhenSelected('workedWhen','workedWhenError')) {
				document.getElementById(caseForm2Id).submit();
		}
	}

  	/*function isRadioButtonChecked(radioButtonObj) {
  		for (var i=0; i<radioButtonObj.length; i++) {
		    if (radioButtonObj[i].checked) { return i; }
  		}
  		return -1;
	}*/  	
	
	function submitCase(caseForm3Id, submitButtonId) {
		if(isMandatory('recentChanges', 'recentChangesError', 'Recent Changes')) {
			document.getElementById(caseForm3Id).submit();
			document.getElementById(submitButtonId).value="Please Wait ...";
			document.getElementById(submitButtonId).disabled=true;
		}
	}
	
	/* validation functions for CSR ends */
  
	
	function isValidCDetail(isValidAlphabetId, isValidAlphabetErrorId, helperMsg) 
		{
			//	document.getElementById(isValidAlphabetErrorId).innerHTML = "";
				
				alphabetErrorObj = document.getElementById(isValidAlphabetErrorId);
				
				alphabetErrorObj.style.color = "#cc0000";
				alphabetErrorObj.style.display = "block";	 			
				
				validAlphabet = document.getElementById(isValidAlphabetId).value;			
				
				// var alphaExp = /^([^&\^\?]*)([a-zA-Z])+([^&\^\?]*)$/;
				//[^&\^\?\%\*\-\+\=\!\@\#\_\;\:\.\,\`\~]
				//alert(validAlphabet);
				var alphaExp = /^([^&\^\?\%\*\-\+\=\!\@\#\_\;\:\.\,\`\~\(\)\|\{\}\<\>]*)([a-zA-Z])+([^&\^\?\%\*\-\+\=\!\@\#\_\;\:\.\,\`\~\(\)\|\{\}\<\>]*)$/;
				
				if(validAlphabet.match(alphaExp))
				{
					alphabetErrorObj.style.display = "none";
				}
				else
				{
						alphabetErrorObj.innerHTML = helperMsg;
						//document.getElementById(isValidAlphabetId).focus();
				}
		}
		
		
		/* To check whether it is valid phone number or not */
	
		/*function isValidNumeric(elemId, errorId)
		{
				var elemObj = document.getElementById(elemId);
				var errorObj = document.getElementById(errorId);
				
				errorObj.style.color = "#cc0000";
				errorObj.style.display = "block";
				
				var elemValue = elemObj.value;		
		
				var numericExpression = /^[0-9]+$/
				
				if(elemValue.match(numericExpression))
				{
					errorObj.style.display = "none";
				}
				else
				{
					errorObj.innerHTML = 'Please enter only numbers';
					elemObj.focus();
				}
		}*/
		

	  	
	  	
	  	/* Fucntions To validate createcase3.jsp values */
	  /*	
	  	function descRequired(desc, descRequiredErrorId, helperMsg)
		{
				var alphaExp = "";
				
				desc = document.getElementById(desc);
				errorObj = document.getElementById(descRequiredErrorId);
				
				errorObj.style.color = "#cc0000";
				errorObj.style.display = "block";	 
				
				description = desc.value; 
							
				if(description=="")
				{
					errorObj.innerHTML = helperMsg;
					//desc.focus();
				}
				else
				{
					errorObj.innerHTML = "";
					errorObj.style.display = "none";
				}	
		}
		*/
		       
       function textCounter(field,cntfield,maxlimit) 
       {
       		field = document.getElementById(field);

          	cntfield = document.getElementById(cntfield);
       		
			if (field.value.length > maxlimit) 
			{// if too long...trim it!
				field.value = field.value.substring(0, maxlimit);
			}				
			// otherwise, update 'characters left' counter
			else
			{
				cntfield.value = maxlimit - field.value.length;
				if(cntfield.value == 0)
				{
					//code to give user the msg about 'max limit reached'
				}
			}
		}
		
		function textCounterNew(field, maxlimit) {
       
      		var textAreaTitle = field.lang;
      		
      		//alert(textAreaTitle);
      		
      		// getting counter field's id from text area's title
      		var counterId = "c" + textAreaTitle;

          	cntfield = document.getElementById(counterId);
       		
			if (field.value.length > maxlimit) 
			{// if too long...trim it!
				field.value = field.value.substring(0, maxlimit);
			}				
			// otherwise, update 'characters left' counter
			else
			{
				cntfield.value = maxlimit - field.value.length;
				if(cntfield.value == 0)
				{
					//code to give user the msg about 'max limit reached'
				}
			}
       
       
     /*  var textAreaId = field.id;
       var counterId = "c" + textAreaId;
       
       alert(counterId);
       
       var cf = document.getElementById(counterId);
       
       alert(cf);*/
       
       //	alert(field.id);
       
       		//field = document.getElementById(field);
       		//alert(document.getElementById("c" + field.id);

          /*	cntfield = document.getElementById(cntfield);
          	alert(cntfield.id);
       		
			if (field.value.length > maxlimit) 
			{// if too long...trim it!
				field.value = field.value.substring(0, maxlimit);
			}				
			// otherwise, update 'characters left' counter
			else
			{
				cntfield.value = maxlimit - field.value.length;
				if(cntfield.value == 0)
				{
					//code to give user the msg about 'max limit reached'
				}
			}*/
		}		
       
	  	/* Function : Requires that user must enter something */
	  	
	  	
	  	/*----------------------------------------------------------------------------------------------------------------------------------------*/
	   
	   ////////////////////////////     VArun's Functions        //////////////////////////////////////
	   
	   function isValidAlphabet(isValidAlphabetId, isValidAlphabetErrorId) 
	   {
				alphabetErrorObj = document.getElementById(isValidAlphabetErrorId);
				
				alphabetErrorObj.style.color = "#cc0000";
				alphabetErrorObj.style.display = "block";	 			
				
				validAlphabet = document.getElementById(isValidAlphabetId).value;			
				
				// var alphaExp = /^([^&\^\?]*)([a-zA-Z])+([^&\^\?]*)$/;
				//[^&\^\?\%\*\-\+\=\!\@\#\_\;\:\.\,\`\~]
				//alert(validAlphabet);
				var alphaExp = /^([^&\^\?\%\*\-\+\=\!\@\#\_\;\:\.\,\`\~\(\)\|\{\}\<\>]*)([a-zA-Z])+([^&\^\?\%\*\-\+\=\!\@\#\_\;\:\.\,\`\~\(\)\|\{\}\<\>]*)$/;
				
				if(validAlphabet.match(alphaExp))
				{
					alphabetErrorObj.style.display = "none";
				}
				else
				{
						alphabetErrorObj.innerHTML = 'Please enter alphabets only....';
						//document.getElementById(isValidAlphabetId).focus();
				}
		}
		
	/* validation functions for OALK starts */
	   
	function displayLicenseKeyPage(licenseKeyFormId) {
	
		if(isModelSelected('modelNumber','modelNumberError','Model Number') & 
			isMandatory('serialNumber','serialNumberError','Serial Number')) {
				document.getElementById(licenseKeyFormId).submit();
		}
	}	
	
	function isModelSelected(modelNumberId, modelErrorId, fieldName){
	
		var elemObj = document.getElementById(modelNumberId);
		
		var index = elemObj.selectedIndex;
		var errorObj = document.getElementById(modelErrorId);
			
		errorObj.style.color = "#cc0000";
		
		// hide the error div
		errorObj.style.display = "none";
		
		if(index == 0) {
			errorObj.innerHTML = "The selected " + fieldName + " is invalid";
	     	errorObj.style.display = "block";
	     	//createCase1Error = true;
	     	return false;
		}	
		return true;
	}

 	/* validation functions for OALK ends */
 	
 		
 		
 	/* Site Contact Functions Starts---------------------------------------------------------------- */
 	
 	function addSiteContact(addFormId){
 			if( isValidAlphabets('firstName','firstNameErrorId')&
				isValidAlphabets('lastName','isValidAlphabetErrorId2')&
				validatePhone('workPhone', 'workPhoneError', 'Work Phone')&
				//isMandatory('workPhone','workPhoneError','Work Phone')&
				isNotMandatoryNumeric('homePhone', 'homePhoneError', 'Home Phone')&
	     	    isValidEmailAddress('email','emailError','Email') &
	     	    isContactTypeSelected('contacttype','contactTypeError','Contact Type') ){
					document.getElementById(addFormId).submit();
			}
	}
	
		function  isContactTypeSelected(contactType, contactTypeError, helperMsg){
 			var contactType = document.getElementById(contactType);
 			var contactTypeError = document.getElementById(contactTypeError);
 			
 			contactTypeError.style.color = "#cc0000";
			// hide the error div
			contactTypeError.style.display = "none";
 			 			
 			//alert(contactType.selectedIndex);
 			if (contactType.selectedIndex == 0){
 				contactTypeError.innerHTML = "The " + helperMsg + " field is mandatory";
	     		contactTypeError.style.display = "block";
	     		return false;
			}
			return true;
	}
 	

 	function updateSiteContact(updateFormId){
 			if(	 /*validatePhone('homePhone', 'homePhoneError')&*/
	      		 validatePhone('workPhone', 'workPhoneError', 'Work Phone')&
	      		 isNotMandatoryNumeric('homePhone', 'homePhoneError', 'Home Phone')&
	      		 isValidEmailAddress('email','emailError','Email')){
					document.getElementById(updateFormId).submit();
			}
	}
	
	function deleteSiteContact(deleteFormId){
		document.getElementById(deleteFormId).submit();
	}
	
	function validatePhone(elemId,errorId,fieldName){
		isMandatory(elemId, errorId, fieldName)
		isValidNumeric(elemId, errorId, fieldName);		
	}
	
	
	function isValidNumeric(elemId,errorId,fieldName)
	{
			var elemeObj = document.getElementById(elemId);
			
			var errorObj = document.getElementById(errorId);
			errorObj.style.color = "#cc0000";
			
			// to show the div
			errorObj.style.display = "block";
			
			var elemValue = elemeObj.value;		
	
			var numericExpression = /^[0-9+-]{2,50}$/;

			if(elemValue.match(numericExpression))
			{
				errorObj.style.display = "none";
			}
			else
			{
				//alert ('It is not numeric');
				//errorObj.innerHTML = 'Please enter only numbers for '+fieldName;
				errorObj.innerHTML =  'Not a valid phone number';
				//elemObj.focus();
				return false;
			}
			return true;
	}
		
	function isNotMandatoryNumeric(elemId,errorId,fieldName){
		
			var elemObj = document.getElementById(elemId);
			var errorObj = document.getElementById(errorId);
			
			//alert ('elemObj --> ' + elemObj);
			//alert ('errorObj --> ' + errorObj);
		
			errorObj.style.color = "#cc0000";
		
			// hide the error div
			errorObj.style.display = "none";
				     	       	
	   		var elemValue = elemObj.value;
	    	elemValue = trim(elemValue);
	    	//alert ('elemValue --> ' + elemValue);
	    
	   		if(elemValue == "") {
	   			//alert ('It is empty..So, valid');
	   			return true;
	    	}
	    	else{
		    	//alert ('isValidNumeric(elemId, errorId, fieldName) --> ' + isValidNumeric(elemId, errorId, fieldName));
	    		return isValidNumeric(elemId, errorId, fieldName);
	    	}
		}
		
		
		
		function isValidAlphabets(isValidAlphabetId, isValidAlphabetErrorId) 
	   {
				alphabetErrorObj = document.getElementById(isValidAlphabetErrorId);
				
				alphabetErrorObj.style.color = "#cc0000";
				alphabetErrorObj.style.display = "block";	 			
				
				validAlphabet = document.getElementById(isValidAlphabetId).value;			
				
				// var alphaExp = /^([^&\^\?]*)([a-zA-Z])+([^&\^\?]*)$/;
				//[^&\^\?\%\*\-\+\=\!\@\#\_\;\:\.\,\`\~]
				//alert(validAlphabet);
				var alphaExp = /^([^&\^\?\%\*\-\+\=\!\@\#\_\;\:\.\,\`\~\(\)\|\{\}\<\>]*)([a-zA-Z])+([^&\^\?\%\*\-\+\=\!\@\#\_\;\:\.\,\`\~\(\)\|\{\}\<\>]*)$/;
				
				if(validAlphabet.match(alphaExp))
				{
					alphabetErrorObj.style.display = "none";
					return true;
				}
				else
				{
						alphabetErrorObj.innerHTML = 'Please enter alphabets only....';
						//document.getElementById(isValidAlphabetId).focus();
						return false;
				}
		}
		
		
		function checkRadio(selectForm,actionName,errorId)
		{
		var errorObj = document.getElementById(errorId);
				errorObj.style.color = "#cc0000";
				errorObj.style.display = "block";

		var radioCheck = document.getElementsByName('contact');
 		var i=0;
 		var j=0;
 		for(;i<radioCheck.length;i++)
 		{
 		if( radioCheck[i].checked)
 		{
 		errorObj.style.display = "none";
 		//alert("Radio button Checked "+i);
 			if(actionName=="Update")
 			{
 				document.getElementById(selectForm).action = document.getElementById(selectForm).action + actionName;
 			}
 		//alert(document.getElementById(selectForm).action);
		document.getElementById(selectForm).submit();
		return true;
		}

 	}
 	errorObj.innerHTML = 'Please Choose a record to Update or Delete ';
	//elemObj.focus();			
  	//alert("Please Choose a record to Update or Delete");
 	return false;

 }
	/* Site Contact Function Ends */
	
	///////////////////////////////////////////// Part Replacement Functions ///////////////////////////////////////////////

	/* isValidSoldTo overridden here for part's replacement */
	function isValidSoldTo(soldToNumberId, soldToErrorId, soldToLocationsId, partErrorId) {
	
		var soldToNumberObj = document.getElementById(soldToNumberId);
		var soldToErrorObj = document.getElementById(soldToErrorId);
		var partErrorId = document.getElementById(partErrorId);
		
		soldToErrorObj.style.color = "#cc0000";
		
		
		// hide the error div
		soldToErrorObj.style.display = "none";
		//partErrorId.style.display = "none";
		// set the errror flag to false so user can go to next page (form can be submitted)
		soldToFormError = false;
		     	       	
	    var soldToNumber = soldToNumberObj.value;
	    
	    var paddedSoldToNumber = zeroPad(soldToNumber);
	    //alert(paddedSoldToNumber);
		         	
		if (paddedSoldToNumber.length > 0) {	  	 
			if (paddedSoldToNumber.length > 10) {
		     	soldToErrorObj.innerHTML = "Sold To value must be 10 digits";
		     	//partErrorId.innerHTML = "";
		     	soldToErrorObj.style.display = "block";
		     	soldToFormError = true;
		     	//soldToNumberObj.focus();
			} else {
				var soldToLocationObj = document.getElementById(soldToLocationsId);
				for (var i = 0; i < soldToLocationObj.length; i++) {
					var soldToDesc = soldToLocationObj.options[i].value;
					//alert(soldToDesc);
					var usersSoldToNumber = soldToDesc.substring(1,11);
					//alert(usersSoldToNumber)
					if (paddedSoldToNumber == usersSoldToNumber) {
               			soldToLocationObj.options[i].selected = true;
               			var isFound = "yes"
              			break
           			}
         		}
         		if (isFound != "yes") {
            		soldToErrorObj.innerHTML = "Sold to is not associated with user";
            		//partErrorId.innerHTML = "";
		     		soldToErrorObj.style.display = "block";
		     		soldToFormError = true;
		     		//soldToNumberObj.focus();
         		}		       
			}  
		}    	
	}
	
	function displayPartsSummaryPage(replacePartsFormId) {
		if(isPartsSelectionValid('partsSelect', 'partsError')) {
				document.getElementById(replacePartsFormId).submit();
		}
	}
	
	function isPartsSelectionValid(partsSelect, partsError)	{
		
		partsErrorObj = document.getElementById(partsError);
		partsErrorObj.style.color = "#cc0000";
		
		// hide the error div
		partsErrorObj.style.display = "none";
		
	    var count = 0;
	    
	    partsSelectObj = document.getElementById(partsSelect);
			  			  
		for(var i = 0; i < partsSelectObj.length; i++) {	
	  		if(partsSelectObj.options[i].selected) {			       		
				count++;
			}
	    }

	    if(count == 0) {
	    	partsErrorObj.style.display = "block";
			partsErrorObj.innerHTML = 'Please select a value from the Selectbox';		 
  		  	return false;
	  	}
	  	if (count > 5) {
	  		partsErrorObj.style.display = "block";
			partsErrorObj.innerHTML = 'Your selection exceeds the maximum number of items allowed in this order. You may order up to 5 different items in one case';
		    return false;
	  	} 
	  	return true;
	}

// Used in 'ShippingInfo' page....called when clicked on 'Next' Button
function displaySummaryPage(shippingFormId) {
	
	if( isMandatory('ocName', 'ocNameError', 'Name') &
		isMandatory('ocPhone', 'ocPhoneError', 'Phone') &
    	isValidEmailAddress('ocEmail','ocEmailError', 'Email')) {
	   		document.getElementById(shippingFormId).submit();
    }
}


/* used in error.jsp */
function changeColorB(changeColorId)
{
	var changeColorId = document.getElementById(changeColorId);
	
	changeColorId.style.color = "#000000";
}

function changeColorR(changeColorId)
{
	var changeColorId = document.getElementById(changeColorId);
	
	changeColorId.style.color = "#cc0000";
}

/*  2 special function for createCasePage2....are there ... but copied here for testing....are locked above....*/
 var workedWhenSel = false;
	
	function workedWhenSelected() {
			workedWhenSel = true;
	}
	
	
	
	function isWorkedWhenSelected(workedWhenName, workedWhenErrorId) {
				
			var workedWhenErrorObj = document.getElementById(workedWhenErrorId);
			workedWhenErrorObj.style.color = "#cc0000";
			// hide the error div
			workedWhenErrorObj.style.display = "none";
			
			if (!workedWhenSel) {
				workedWhenErrorObj.innerHTML = "Please indicate whether the function has ever worked before";
		     	workedWhenErrorObj.style.display = "block";
				return false;
			}
			return true;
	}
	
	
	
	
	var issueTypeSel = false;

function issueTypeSelected() {
		issueTypeSel = true;
	}
	

function isIssueTypeSelected(issueTypeName, issueTypeErrorId) {
			
		var issueTypeErrorObj = document.getElementById(issueTypeErrorId);
		issueTypeErrorObj.style.color = "#cc0000";
		// hide the error div
		issueTypeErrorObj.style.display = "none";
		
		if (!issueTypeSel) {
			issueTypeErrorObj.innerHTML = "Please select an issue type";
	     	issueTypeErrorObj.style.display = "block";
			return false;
		}
		return true;
	}
	
	
	/* Function to check if radio button selected or not..........used in siteContacts.jsp */
var radioSelected = false;


function radioSelect() {
radioSelected = true;
}
function findSel(selectForm,actionName,errorId) {
//alert('Its here in checkRadio ');
var errorObj = document.getElementById(errorId);
errorObj.style.color = "#cc0000";
errorObj.style.display = "block";
if(radioSelected) {
errorObj.style.display = "none";
if(actionName=="Update"){
document.getElementById(selectForm).action = document.getElementById(selectForm).action + actionName;
}
//alert(document.getElementById(selectForm).action);
document.getElementById(selectForm).submit();
} else {
errorObj.innerHTML = 'Please Choose a record to Update or Delete ';
}
}


	////////////// General function /////to validate phone number
	
	function validatePhone(phoneId, errorId)
	{
		var numericExpression = /^[0-9+-]{2,50}$/;
		
		var phoneObj = document.getElementById(phoneId);
		var errorObj = document.getElementById(errorId);
		
		errorObj.style.color = "#cc0000";
		errorObj.style.display = "none";
		
		//alert(phoneObj.value );
		//alert(phoneObj.value.length);
		//alert(phoneObj.value.charAt(phoneObj.value.length - 1) );
		//var endChar = phoneObj.value.charAt(phoneObj.value.length - 1);
		//var dash = -;
		//var beginChar = phoneObj.value.charAt(0);
		
		//alert(endChar);
		//alert('Match --->  '+ endChar.match('+'));
		
	
		if(phoneObj.value.match(numericExpression)){
			errorObj.innerHTML = '';		
			return true;
		}
		else{
			errorObj.innerHTML = 'Not a valid phone number';
			errorObj.style.display = "block";				
			return false;
		}		
	}
	
function validatePhoneField(phoneId, errorId , helperMsg)
{
	if( isMandatory(phoneId,errorId, helperMsg) ) 
	{
		if(validatePhone(phoneId, errorId))
				return true;		
		//else
	//		return false;
	}
	//else
	//{
		return false;
	//}
}


function disableSubmitBtn(summaryForm, submitButtonId)
{
               document.getElementById(summaryForm).submit();
               document.getElementById(submitButtonId).value="Please Wait ...";
               document.getElementById(submitButtonId).disabled=true;
}
	
	
	
function wrapText(text,lengthInPixels,splitter){
	//alert("Hi...");
 
	try{
		if(!text){throw('arg1');}
		
		var result = '';
		var line = '';	
		var parentDiv = document.createElement('div');
		var contentDiv = document.createElement('div');
		
		if(!lengthInPixels){lengthInPixels=100;}
		if(!splitter){splitter=' ';}
		
		parentDiv.style.width = '0px';
		parentDiv.style.height = '0px';
		parentDiv.style.overflow = 'hidden';
		parentDiv.appendChild(contentDiv);
		document.body.appendChild(parentDiv);

		for(var i=0; i<text.length; i++){
			contentDiv.innerHTML += text.charAt(i);
			if(parentDiv.scrollWidth < lengthInPixels){
				line += text.charAt(i);
			}else{
				result += line+splitter;
				contentDiv.innerHTML = '';
				line = '';
			}
		}		

		if(line.length>0){result += line;}
		return result;
		
	}
	catch(ex){
		if(ex=='arg1'){
			//alert('wrapText: Argument 1 is mandatory.');
			return text;
		}else{
			throw('Unexpected error: '+ex.toString());
		}
	}
}
	