

var n;
var p;
var p1;
var p2;

function checkSpecialcharacters(paramValue)
			{
			
			
					var vParam;
					vParam = paramValue.value; //Only to use with objects
					if(vParam != "")
					{
						var iChars = "!#$%^&*()+=-[]\\\';,/{}|\":<>?~";
							for (var i = 0; i < vParam.length; i++) 
							{
  								if (iChars.indexOf(vParam.charAt(i)) != -1) 
  								{
  									alert ("Special characters are not allowed.\nPlease remove them and try again.");
  									document.getElementById(paramValue.id).value="";
									document.getElementById(paramValue.id).focus();
  									return false;
								}
							}
						
						return true;
					}
			}
			
			
		
				function ValidateRequiredField(arrFieldIDs)
				{
					if(arrFieldIDs.length > 0)
					{
						for(var i=0;i<arrFieldIDs.length;i++)
						{
							
							if(trim(document.getElementById(arrFieldIDs[i]).value) == "" || document.getElementById(arrFieldIDs[i]).value == "[Choose]")
							{
								alert('Fields marked as * are required');
								return false;
							}
						}
								
					}
				}


			function checkEmailID(paraEmail)
			{
					var sEmail = document.getElementById(paraEmail).value;
			
					var atsym = sEmail.indexOf("@");
					var period = sEmail.lastIndexOf('.');
					var space = sEmail.indexOf(' ');
					var length = sEmail.length - 1;
					
					if ((atsym < 1) || (period <= atsym+1) || (period == length ) || (space != -1)) 
					{ 
							alert('Please enter a valid email address !');
							document.getElementById(paraEmail).value="";
							document.getElementById(paraEmail).focus();
							return false;
					}
					return true;
			}


		function CheckSpecialChar(vObject,vType)
		{
				var iChars;
				var AlertMsg;
				 
					if(vType == "String")
					{
					    if(vObject =='txtRenewalID')
					    {
					        iChars = "!#$%^&*()+=-[]\\\';,/{}|\":<>?";
					    }
					    else
					    {
						    iChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?1234567890";
						 }
						AlertMsg ="Special characters are not allowed!"; 
					}
					else if (vType == "Numeric")
					{
						iChars = "!@#$%^&*()+=-[]\\\;,./{}|\:<>?ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'''";
						AlertMsg ="Invalid Value";
						
					}
					else if (vType == "AlphaNumeric")
					{
					     iChars = "`~_!@#$%^*+=[]\\\';/{}|\":<>?";
						AlertMsg ="Special characters are not allowed!"; 
					}
					else if (vType == "ImagePath")
					{
					    
					     iChars = "'#%";
						AlertMsg ="Special characters are not allowed!"; 
					}
					else if(vType == "SingleQuote")
					{
					    iChars = "'";
						AlertMsg ="Single quote is not allowed!"; 
					}
					else if(vType == "Currency")
					{
					    iChars = "`~ _!@#%^&*+=[]\\\;,./{}|\:<>?'1234567890";
						AlertMsg ="Use Dollar Sign!"; 
					}
					for (var i = 0; i < document.getElementById(vObject).value.length; i++) 
					{
  						if (iChars.indexOf(document.getElementById(vObject).value.charAt(i)) != -1) 
  						{
				  		    
  							alert(AlertMsg);
  							document.getElementById(vObject).value="";
  							document.getElementById(vObject).focus();
  							return false;
  						}
					}
  					return true;	
		}


			function checkNumericValue(paraObject)
			{
					if(paraObject.value != "")
					{
						if(isNaN(paraObject.value)==true)
						{
							alert('Please enter numeric value.');
							document.getElementById(paraObject.id).value="";
  							document.getElementById(paraObject.id).focus();
							return false;
						}
					}
			}

function ValidatePhone(){
p=p1.value;
p2=p1.name;
if(p.length==3){
	//d10=p.indexOf('(')
	pp=p;
	d4=p.indexOf('(')
	d5=p.indexOf(')')
	if(d4==-1){
		pp="("+pp;
	}
	if(d5==-1){
		pp=pp+")";
	}
	//pp="("+pp+")";
	document.getElementById(p2).value="";
	document.getElementById(p2).value=pp;
}
if(p.length>3){
	d1=p.indexOf('(')
	d2=p.indexOf(')')
	if (d2==-1){
		l30=p.length;
		p30=p.substring(0,4);
		//alert(p30);
		p30=p30+")"
		p31=p.substring(4,l30);
		pp=p30+p31;
		//alert(p31);
		document.getElementById(p2).value="";
		document.getElementById(p2).value=pp;
	}
	}
if(p.length>5){
	p11=p.substring(d1+1,d2);
	if(p11.length>3){
	p12=p11;
	l12=p12.length;
	l15=p.length
	//l12=l12-3
	p13=p11.substring(0,3);
	p14=p11.substring(3,l12);
	p15=p.substring(d2+1,l15);
	document.getElementById(p2).value="";
	pp="("+p13+")"+p15;
	document.getElementById(p2).value=pp;

	//obj1.value="";
	//obj1.value=pp;
	}
	l16=p.length;
	p16=p.substring(d2+1,l16);
	l17=p16.length;
	if(l17>3&&p16.indexOf('-')==-1){
		p17=p.substring(d2+1,d2+4);
		p18=p.substring(d2+4,l16);
		p19=p.substring(0,d2+1);
		//alert(p19);
	pp=p19+p17+"-"+p18;
	document.getElementById(p2).value="";
	document.getElementById(p2).value=pp;
	
	}
}
//}
setTimeout(ValidatePhone,100)
}



		function getIt(m)
		{
				if(document.getElementById(m.id).value != "")
				{
				
					var iChars = "!@#$%^&*+=[]\\\;,./{}|\:<>?ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'''";

					for (var i = 0; i < document.getElementById(m.id).value.length; i++) 
					{
  						if (iChars.indexOf(document.getElementById(m.id).value.charAt(i)) != -1) 
  						{
  							alert('Invalid phone number');
  							document.getElementById(m.id).value="";
  							document.getElementById(m.id).focus();
  							return false;
  						}
					}
					if(document.getElementById(m.id).value.length > 13)
					{
							alert('Invalid phone number');
  							document.getElementById(m.id).value="";
  							document.getElementById(m.id).focus();
  							return false;
					}
						n=m.name;
						p1=m;
						ValidatePhone();
						
							
							if(document.getElementById(m.id).value.length > 13)
							{
									alert('Invalid phone number or fax');
									document.getElementById(m.id).value="";
  									document.getElementById(m.id).focus();
									return false;		
							}
				}
				
		}
function testphone(obj1){
p=obj1.value

p=p.replace("(","")
p=p.replace(")","")
p=p.replace("-","")
p=p.replace("-","")
if (isNaN(p)==true){
alert("Check phone");
return false;
}
}



function SingleSelect(chkobj)
{	
	for(var item = 0; item < document.forms[0].elements.length; item++)
	{
		if (document.forms[0].elements[item].type == 'checkbox' && document.forms[0].elements[item].id != chkobj.id) 
		{
			document.forms[0].elements[item].checked = false;
		}
	}	
}

function trim(inputString) 
	{
		if (typeof inputString != "string") { return inputString; }
		var retValue = inputString;
		var ch = retValue.substring(0, 1);
		while (ch == " ") 
		{ // Check for spaces at the beginning of the string
		retValue = retValue.substring(1, retValue.length);
		ch = retValue.substring(0, 1);
		}
		ch = retValue.substring(retValue.length-1, retValue.length);
		while (ch == " ") 
		{ // Check for spaces at the end of the string
		retValue = retValue.substring(0, retValue.length-1);
		ch = retValue.substring(retValue.length-1, retValue.length);
		}
		while (retValue.indexOf("  ") != -1)
		{ // Note that there are two spaces in the string - look for multiple spaces within the string
		retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
		}
		return retValue; // Return the trimmed string back to the user
	} 


function validatetime(paraObject)
 {
  
  var strval = document.getElementById(paraObject).value;
  var strval1;
    
  //minimum lenght is 6. example 1:2 AM
  if(strval.length < 6)
  {
   alert("Invalid time. Time format should be HH:MM AM/PM.");
   document.getElementById(paraObject).value="";
   document.getElementById(paraObject).focus();
   return false;
  }
  
  //Maximum length is 8. example 10:45 AM
  if(strval.lenght > 8)
  {
   alert("invalid time. Time format should be HH:MM AM/PM.");
   document.getElementById(paraObject).value="";
   document.getElementById(paraObject).focus();
   return false;
  }
  
  //Removing all space
  strval = trimAllSpace(strval); 
  
  //Checking AM/PM
  if(strval.charAt(strval.length - 1) != "M" && strval.charAt(strval.length - 1) != "m")
  {
   alert("Invalid time. Time shoule be end with AM or PM.");
   document.getElementById(paraObject).value="";
   document.getElementById(paraObject).focus();
   return false;
   
  }
  else if(strval.charAt(strval.length - 2) != 'A' && strval.charAt(strval.length - 2) != 'a' && strval.charAt(strval.length - 2) != 'p' && strval.charAt(strval.length - 2) != 'P')
  {
   alert("Invalid time. Time shoule be end with AM or PM.");
   document.getElementById(paraObject).value="";
   document.getElementById(paraObject).focus();
   return false;
   
  }
  
  //Give one space before AM/PM
  
  strval1 =  strval.substring(0,strval.length - 2);
  strval1 = strval1 + ' ' + strval.substring(strval.length - 2,strval.length)
  
  strval = strval1;
      
  var pos1 = strval.indexOf(':');
  document.getElementById(paraObject).value = strval;
  
  if(pos1 < 0 )
  {
   alert("invlalid time. A colon(:) is missing between hour and minute.");
   document.getElementById(paraObject).value="";
   document.getElementById(paraObject).focus();
   return false;
  }
  else if(pos1 > 2 || pos1 < 1)
  {
   alert("invalid time. Time format should be HH:MM AM/PM.");
   document.getElementById(paraObject).value="";
   document.getElementById(paraObject).focus();
   return false;
  }
  
  //Checking hours
  var horval =  trimString(strval.substring(0,pos1));
   
  if(horval == -100)
  {
   alert("Invalid time. Hour should contain only integer value (0-11).");
   document.getElementById(paraObject).value="";
   document.getElementById(paraObject).focus();
   return false;
  }
      
  if(horval > 12)
  {
   alert("invalid time. Hour can not be greater that 12.");
   document.getElementById(paraObject).value="";
   document.getElementById(paraObject).focus();
   return false;
  }
  else if(horval < 0)
  {
   alert("Invalid time. Hour can not be hours less than 0.");
   document.getElementById(paraObject).value="";
   document.getElementById(paraObject).focus();
   return false;
  }
  //Completes checking hours.
  
  //Checking minutes.
  var minval =  trimString(strval.substring(pos1+1,pos1 + 3));
  
  if(minval == -100)
  {
   alert("Invalid time. Minute should have only integer value (0-59).");
   document.getElementById(paraObject).value="";
   document.getElementById(paraObject).focus();
   return false;
  }
    
  if(minval > 59)
  {
     alert("Invalid time. Minute can not be more than 59.");
     document.getElementById(paraObject).value="";
     document.getElementById(paraObject).focus();
     return false;
  }   
  else if(minval < 0)
  {
   alert("Invalid time. Minute can not be less than 0.");
   document.getElementById(paraObject).value="";
   document.getElementById(paraObject).focus();
   return false;
  }
   
  //Checking minutes completed.  
  
  //Checking one space after the mintues 
  minpos = pos1 + minval.length + 1;
  if(strval.charAt(minpos) != ' ')
  {
   alert("Invalid time. Space missing after minute. Time should have HH:MM AM/PM format.");
   document.getElementById(paraObject).value="";
   document.getElementById(paraObject).focus();
   return false;
  }

  return true;

 }
function trimAllSpace(str)
 {
  var str1 = '';
  var i = 0;
  while(i != str.length)
  { 
   if(str.charAt(i) != ' ')  str1 = str1 + str.charAt(i); i ++;
   }
    return str1; 
 }	
 
 function trimString(str) { var str1 = ''; var i = 0; while ( i != str.length) { if(str.charAt(i) != ' ') str1 = str1 + str.charAt(i); i++; } var retval = IsNumeric(str1); if(retval == false) return -100; else return str1; }
 
 function IsNumeric(strString) { var strValidChars = "0123456789"; var strChar; var blnResult = true;}	
