// JavaScript Document 

/*****************************************************************************\
+-----------------------------------------------------------------------------+
| Project        : freecita.com			                                      |
| FileName       : formvalidation.js        	                              |
| Version        : 1.0                                                        |
| Developer      : Ganesh Kadam                                               |
| Created On     : 08-07-2008                                                 |
| Modified On    : 08-07-2008                                                 |
| Modified By    : Ganesh Kadam                                               |
| Authorised By  : Ganesh Kadam                                               |
| Comments       : This file will conatain basic form validaion regular exp.  |
| Email          : ganeshkadam@greymatterindia.com                            |
+-----------------------------------------------------------------------------+
\*****************************************************************************/

function isurl(obj,stmnt)
{
	var objRegExp  =  /^(http|https):\/\/(([A-Z0-9][A-Z0-9_-]*)(\.[A-Z0-9][A-Z0-9_-]*)+)/i;
	var test = objRegExp.test(dotrim(obj.value));
	
	if(test == false)
	{
		alert(stmnt);
		obj.focus();
		return false;
	}
	return true;	
}

function isprice(obj,stmnt)
{
	var objRegExp  =  /^\d+\.\d{2}$/;
	var test = objRegExp.test(dotrim(obj.value));
	
	if(test == false)
	{
		alert(stmnt);
		obj.focus();
		return false;
	}
	return true;	
}

function dotrim(strComp)
{
	ltrim = /^\s+/
	rtrim = /\s+$/
	strComp = strComp.replace(ltrim,'');
	strComp = strComp.replace(rtrim,'');
	return strComp;
}
			
function ischecked(obj,stmnt,i)
{
	flag = false;
	for(j=0;j<=i;j++)
		if(obj[j].checked == true)
			flag = true;

	if(flag == false)
	{
		alert(stmnt);
		obj[0].focus();
		return false;			
	}
	return true;
}

function ischeckedbox(obj,stmnt,i)
{
	flag = false;	

	if(obj.checked == true)
		flag = true;
	
	if(flag == false)
	{
		alert(stmnt);
		obj.focus();
		return false;			
	}
	return true;
}

function isselected(obj,stmnt)
{
	if(obj.options[obj.selectedIndex].value == "")
	{
		alert(stmnt);
		obj.focus();
		return false;		
	}
	return true;
}

function isblank(obj,stmnt)
{
	if(dotrim(obj.value) == "")
	{
		alert(stmnt);
		obj.focus();
		return false;
	}
	return true;
}

//Added by Vivek to check the hidden elements as it does not require focus to be set.
function isblankWithNoFocus(obj,stmnt)
{
	if(dotrim(obj.value) == "")
	{
		alert(stmnt);
		return false;
	}
	return true;
}

function isnumber(obj,stmnt)
{ 
	var objRegExp  =  /(^-?\d\s\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/;
	var test = objRegExp.test(dotrim(obj.value));
	if(test == false)
	{
		alert(stmnt);
		obj.focus();
		return false;
	}
	return true;
}

//Added by Vivek to check the numeric. It will not allow space in the value.
function isnumberWithoutSpace(obj,stmnt)
{ 
	var objRegExp  =  /(^-?\d\s\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/;
	var test = objRegExp.test(obj.value);
	if(test == false)
	{
		alert(stmnt);
		obj.focus();
		return false;
	}
	return true;
}

function isnotnumber(obj,stmnt)
{ 
	var objRegExp  =  /(^-?\d\s\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/;
	var test = objRegExp.test(dotrim(obj.value));
	if(test == true)
	{
		alert(stmnt);
		obj.focus();
		return false;
	}
	return true;
}
function isvalidphonenumber(obj,stmnt)
{ 
	//(233) 232-3242
	var digits = "0123456789";
	var phoneNumberDelimiters = "()- ";
	var validWorldPhoneChars = phoneNumberDelimiters + "+";
	//var minDigitsInIPhoneNumber = 10;
	
	var strPhone = dotrim(obj.value);
	s=stripCharsInBag(strPhone,validWorldPhoneChars);
	//if(isInteger(s) && s.length >= minDigitsInIPhoneNumber)
	if(isInteger(s) && parseInt(s) > 0)
		return true;
	else
	{
		alert(stmnt);
		obj.focus();
		return false;
	}

}
function stripCharsInBag(s, bag)
{  
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}
function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function isemail(obj,stmnt)
{ 
	//var objRegExp  = /^[a-z0-9]([a-z0-9_\-\.]*)@([a-z0-9_\-\.]*)(\.[a-z]{2,3}(\.[a-z]{2}){0,2})$/i;
	
	var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[(2([0-4]\d|5[0-5])|1?\d{1,2})(\.(2([0-4]\d|5[0-5])|1?\d{1,2})){3} \])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
	
	var test = re.test(dotrim(obj.value));
	if(test == false)
	{
		alert(stmnt);
		obj.focus();
		return false;
	}
	return true;
}

//Added By Vivek - Function returns true or false -- Start
function isValidEmail(objVal)
{ 
	var objRegExp  = /^[a-z0-9]([a-z0-9_\-\.]*)@([a-z0-9_\-\.]*)(\.[a-z]{2,3}(\.[a-z]{2}){0,2})$/i;
	var test = objRegExp.test(dotrim(objVal));
	if(test == false)
	{
		return false;
	}
	return true;
}
//Added By Vivek - Function returns true or false -- End

function iscreditcard(obj,stmnt) { 
	
	// v2.0
	var ccNumb = obj.value;
	var valid = "0123456789" // Valid digits in a credit card number
	var len = ccNumb.length; // The length of the submitted cc number
	var iCCN = parseInt(ccNumb); // integer of ccNumb
	var sCCN = ccNumb.toString(); // string of ccNumb
	sCCN = sCCN.replace ('/^\s+|\s+$/g',''); // strip spaces
	var iTotal = 0; // integer total set at zero
	var bNum = true; // by default assume it is a number
	var bResult = false; // by default assume it is NOT a valid cc
	var temp; // temp variable for parsing string
	var calc; // used for calculation of each digit
	
	// Determine if the ccNumb is in fact all numbers
	for (var j=0; j<len; j++) {
		temp = "" + sCCN.substring(j, j+1);
		if (valid.indexOf(temp) == "-1"){bNum = false;}
	}
	
	// if it is NOT a number, you can either alert to the fact, or just pass a failure
	if(!bNum){
	/*alert("Not a Number");*/bResult = false;
	}
	
	// Determine if it is the proper length
	if((len == 0)&&(bResult)){ // nothing, field is blank AND passed above # check
	bResult = false;
	} else{ // ccNumb is a number and the proper length - let's see if it is a valid card number
	if(len >= 15){ // 15 or 16 for Amex or V/MC
	for(var i=len;i>0;i--){ // LOOP throught the digits of the card
	calc = parseInt(iCCN) % 10; // right most digit
	calc = parseInt(calc); // assure it is an integer
	iTotal += calc; // running total of the card number as we loop - Do Nothing to first digit
	i--; // decrement the count - move to the next digit in the card
	iCCN = iCCN / 10; // subtracts right most digit from ccNumb
	calc = parseInt(iCCN) % 10 ; // NEXT right most digit
	calc = calc *2; // multiply the digit by two
	// Instead of some screwy method of converting 16 to a string and then parsing 1 and 6 and then adding them to make 7,
	// I use a simple switch statement to change the value of calc2 to 7 if 16 is the multiple.
	switch(calc){
	case 10: calc = 1; break; //5*2=10 & 1+0 = 1
	case 12: calc = 3; break; //6*2=12 & 1+2 = 3
	case 14: calc = 5; break; //7*2=14 & 1+4 = 5
	case 16: calc = 7; break; //8*2=16 & 1+6 = 7
	case 18: calc = 9; break; //9*2=18 & 1+8 = 9
	default: calc = calc; //4*2= 8 & 8 = 8 -same for all lower numbers
	}
	iCCN = iCCN / 10; // subtracts right most digit from ccNum
	iTotal += calc; // running total of the card number as we loop
	} // END OF LOOP
	if ((iTotal%10)==0){ // check to see if the sum Mod 10 is zero
	bResult = true; // This IS (or could be) a valid credit card number.
	} else {
	bResult = false; // This could NOT be a valid credit card number
	}
	}
	}
	// change alert to on-page display or other indication as needed.
	
	if(!bResult) {
		alert(stmnt);
		obj.focus();
		return false;
	} else {
		return bResult; // Return the results
	}
 }
 function validateEmail(fld) { 
	
	var tfld = dotrim(fld.value); // value of field with whitespace trimmed off 
	var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ; 
	var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ; 
	
	if (!emailFilter.test(tfld)) { //test email for illegal characters 
		alert("Please enter a valid email address.\n");
		return false;
	} else if (fld.value.match(illegalChars)) { 
		alert("The email address contains illegal characters.\n");
		return false;
	} 
	return true; 
} 
 function IsNumbers(strString)
{
  var strValidChars = "0123456789.";
  var strChar;
  var blnResult = true;
  if (strString.length == 0) return false;
    for (i = 0; i < strString.length && blnResult == true; i++)
	  {
    	strChar = strString.charAt(i);
	    if (strValidChars.indexOf(strChar) == -1)
    	{
	      blnResult = false;
    	}
	  }
	  return blnResult;
}

function textCounter(field,cntfield,maxlimit) {
		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;
		}	
	}

/*************************************************************************
*      To check the emal address it is validate or not.					 *
*	   Add By :- Jagdish Gade                                            *
*      Date:- 2-August-2008         									 *
**************************************************************************/

// Email validate function
function emailCheck (emailStr) {
         /* The following pattern is used to check if the entered e-mail address
            fits the user@domain format.  It also is used to separate the username
            from the domain. */
         var emailPat=/^(.+)@(.+)$/
         /* The following string represents the pattern for matching all special
            characters.  We don't want to allow special characters in the address.
            These characters include ( ) < > @ , ; : \ " . [ ]    */
         var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
         /* The following string represents the range of characters allowed in a
            username or domainname.  It really states which chars aren't allowed. */
         var validChars="\[^\\s" + specialChars + "\]"
         /* The following pattern applies if the "user" is a quoted string (in
            which case, there are no rules about which characters are allowed
            and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
            is a legal e-mail address. */
         var quotedUser="(\"[^\"]*\")"
         /* The following pattern applies for domains that are IP addresses,
            rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
            e-mail address. NOTE: The square brackets are required. */
         var ipDomainPat=/^\[(\d)\.(\d)\.(\d)\.(\d)\]$/
         /* The following string represents an atom (basically a series of
            non-special characters.) */
         var atom=validChars + '+'
         /* The following string represents one word in the typical username.
            For example, in john.doe@somewhere.com, john and doe are words.
            Basically, a word is either an atom or quoted string. */
         var word="(" + atom + "|" + quotedUser + ")"
         // The following pattern describes the structure of the user
         var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
         /* The following pattern describes the structure of a normal symbolic
            domain, as opposed to ipDomainPat, shown above. */
         var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")


         /* Finally, let's start trying to figure out if the supplied address is
            valid. */

         /* Begin with the coarse pattern to simply break up user@domain into
            different pieces that are easy to analyze. */
         var matchArray=emailStr.match(emailPat)
         if (matchArray==null) {
           /* Too many/few @'s or something; basically, this address doesn't
              even fit the general mould of a valid e-mail address. */
                 alert("Entered Email address is not valid. (check @ and .'s)")
                 return false
         }
         var user=matchArray[1]
         var domain=matchArray[2]

         // See if "user" is valid
         if (user.match(userPat)==null) {
             // user is not valid
             //alert("The Email doesn't seem to be valid.");
             alert("Entered Email address is not valid.");
             return false
         }

         /* if the e-mail address is at an IP address (as opposed to a symbolic
            host name) make sure the IP address is valid. */
         var IPArray=domain.match(ipDomainPat)
         if (IPArray!=null) {
             // this is an IP address
                   for (var i=1;i<=4;i++) {
                     if (IPArray[i]>255) {
                         alert("Destination IP address is invalid!")
                         return false
                     }
             }
             return true
         }

         // Domain is symbolic name
         var domainArray=domain.match(domainPat)
         if (domainArray==null) {
                 //alert("The domain name doesn't seem to be valid.")
                 alert("Entered Email address is not valid.")
             return false
         }

         /* domain name seems valid, but now make sure that it ends in a
            three-letter word (like com, edu, gov) or a two-letter word,
            representing country (uk, nl), and that there's a hostname preceding
            the domain or country. */

         /* Now we need to break up the domain to get a count of how many atoms
            it consists of. */
         var atomPat=new RegExp(atom,"g")
         var domArr=domain.match(atomPat)
         var len=domArr.length
         if (domArr[domArr.length-1].length<2 ||
             domArr[domArr.length-1].length>3) {
            // the address must end in a two letter or three letter word.
            alert("The address must end in a three-letter domain, or two letter country.")
            return false
         }

         // Make sure there's a host name preceding the domain.
         if (len<2) {
            var errStr="This address is missing a hostname!"
            alert(errStr)
            return false
         }

         // If we've gotten this far, everything's valid!
         return true;
         }
	
    function validDate(fromDate,toDate)  
	{   
        var dtCh= '-';
		var pos1=fromDate.indexOf(dtCh);
		var pos2=fromDate.indexOf(dtCh,pos1+1);
		
		var fromYear=fromDate.substring(0,pos1);
		var fromMonth=fromDate.substring(pos1+1,pos2);
		var fromDay=fromDate.substring(pos2+1);
		 
		var end1=toDate.indexOf(dtCh);
		var end2=toDate.indexOf(dtCh,end1+1);
		
		var toYear=toDate.substring(0,end1);
		var toMonth=toDate.substring(end1+1,end2);
		var toDay=toDate.substring(end2+1);
		var eDate = new Date(toYear,toMonth-1,toDay);  
		
		// from date validation
		if (isNaN(fromDay) || isNaN(fromMonth) || isNaN(fromYear)) { 
		   alert('Invalid number. Please ensure the day, month and  year are valid numbers.');  
		   return false;  
		} 
		// check month range 
		if (fromMonth < 01 || fromMonth > 12) {  
		   alert('Invalid Month. Please ensure that the month is  between 1 and 12 inclusive.');  
		   return false;  
		} 
		// check day range 
		if (fromDay < 01 || fromDay > 31) {  
		   alert('Invalid Day. Please ensure that the day is between    1 and 31 inclusive.');  
		   return false;  
		} 
		// check day/month combination 
		if ((fromMonth==04 || fromMonth==06 || fromMonth==09 || fromMonth==11) && fromDay==31) { 
		   alert('Invalid Day/Month combination. Please ensure that    you have a valid day/month combination.'); 
		   return false; 
		} 
		// check for february 29th 
		if (fromMonth == 02) {  
		   var isleap = (fromYear % 4 == 0 && (fromYear % 100 != 0 || fromYear %    400 == 0)); 
		   if (fromDay>29 || (fromDay==29 && !isleap)) {  
		      alert('Invalid Day. This year is not a leap year. Please enter a value less than 29 for the day.'); 
		      return false 
		   } 
		} 
		// todate validation
		if (isNaN(toDay) || isNaN(toMonth) || isNaN(toYear)) { 
		   alert('Invalid number. Please ensure the day, month and  year are valid numbers.');  
		   return false;  
		} 
		// check month range 
		if (toMonth < 01 || toMonth > 12) {  
		   alert('Invalid Month. Please ensure that the month is  between 1 and 12 inclusive.');  
		   return false;  
		} 
		// check day range 
		if (toDay < 01 || toDay > 31) {  
		   alert('Invalid Day. Please ensure that the day is between 1 and 31 inclusive.');  
		   return false;  
		} 
		// check day/month combination 
		if ((toMonth==04 || toMonth==06 || toMonth==09 || toMonth==11) && toDay==31) { 
		   alert('Invalid Day/Month combination. Please ensure that you have a valid day/month combination.'); 
		   return false; 
		} 
		// check for february 29th 
		if (toMonth == 02) {  
		   var isleap = (toYear % 4 == 0 && (toYear % 100 != 0 || toYear %    400 == 0)); 
		   if (toDay>29 || (toDay==29 && !isleap)) {  
		      alert('Invalid Day. This year is not a leap year. Please enter a value less than 29 for the day.'); 
		      return false 
		   } 
		} 
		var sDate = new Date(fromYear,fromMonth-1,fromDay);  
		// what is the difference between the start date and end date 
		diff = eDate - sDate; 
		// get the difference in days 
		diff = Math.ceil(diff/1000/60/60/24); 
		if (diff < 0) { 
		   alert('Invalid Date. Please specify To Date that is in the future and not the past.');  
		   return false 
		} 
		return true;
	}   
	
	//Added by Vivek - 20-Aug-08 This function masks the Phone number field
	function formatTelNo (telNo)
	{
		//disable phone number formatting in Safari
		if(navigator.userAgent.indexOf( "Safari" ) < 0)
		{
		    // If it's blank, save yourself some trouble by doing nothing.
		    if (telNo.value == "") return;
		
		    
		
		    var phone = new String (telNo.value);
		    
		    phone = phone.substring(0,14);
		
		    /*
		    "." means any character. If you try to use "(" and ")", the regular expression becomes 
		    complicated sice both are reserve characters and escaping them sometimes fails. So just 
		    use "." for any character and replace it later.
		    */
		    if (phone.match (".[0-9]{3}.[0-9]{3}-[0-9]{4}") == null)
		    {
		        /*
		        Following "if" is for user making any changes to the formatted tel. no. If you don't put this 
		        "if" condition, the user can not correct a digit by first deleting it and then entering a 
		        correct one, since this will fire two "onkeyup" events : first one on deleting a 
		        character and second one on entering the correct one. The first "onkeyup" event will fire this 
		        function which will reformatt the tel no before the user gets a chace to correct the digit. This 
		        will surely confuse the user. The "if" condition below eliminates that.
		        */
		        if (phone.match (".[0-9]{2}.[0-9]{3}-[0-9]{4}|" + ".[0-9].[0-9]{3}-[0-9]{4}|" +
		            ".[0-9]{3}.[0-9]{2}-[0-9]{4}|" + ".[0-9]{3}.[0-9]-[0-9]{4}") == null)
		        {
		            /*
		            You will reach here only if the user is still typing the number or if he/she has 
		            messed up already formatted number. 
		            */
		            var phoneNumeric = phoneChar = "", i;
		            // Loop thru what user has entered.
		            for (i=0;i<phone.length;i++)
		            {
		                // Go thru what user has entered one character at a time.
		                phoneChar = phone.substr (i,1);
		    
		                // If that character is not a number or is a White space, ignore it. Only if it is a digit, 
		                // concatinate it with a number string.
		                if (!isNaN (phoneChar) && (phoneChar != " ")) phoneNumeric = phoneNumeric + phoneChar;
		            }
		    
		            phone = "";
		            // At this point, you have picked up only digits from what user has entered. Loop thru it.
		            for (i=0;i<phoneNumeric.length;i++)
		            {
		                // If it's the first digit, throw in "(" before that.
		                if (i == 0) phone = phone + "(";
		                // If you are on the 4th digit, put ") " before that.
		                if (i == 3) phone = phone + ") ";
		                // If you are on the 7th digit, insert "-" before that.
		                if (i == 6) phone = phone + "-";
		                // Add the digit to the phone charatcer string you are building.
		                phone = phone + phoneNumeric.substr (i,1)
		            }
		        }
		    }
		    else
		    { 
		        // This means the tel no is in proper format. Make sure by replacing the 0th, 4th and 8th character.
		        phone = "(" + phone.substring (1,4) + ") " + phone.substring (5,8) + "-" + phone.substring(9,13); 
		    }
		    // So far you are working internally. Refresh the screen with the re-formatted value.
		    if (phone != telNo.value) telNo.value = phone;
		}
	}

	function isZip(s, msg) {
		// Check for correct zip code
		reZip = new RegExp(/(^\d{5}$)|(^\d{5}-\d{4}$)/);
		if (!reZip.test(s)) {
			alert(msg);
			return false;
		}
		
		if(parseInt(s)<=0) {
			alert(msg);
			return false;			
		}
		
		return true;
	}
	//Function checks whether the enter key is been hit on text box.
	function checkEnter(e){ //e is event object passed from function invocation
		var characterCode //literal character code will be stored in this variable
	
		if(e && e.which){ //if which property of event object is supported (NN4)
			e = e
			characterCode = e.which //character code is contained in NN4's which property
		} else {
			e = event
			characterCode = e.keyCode //character code is contained in IE's keyCode property
		}
	
		if(characterCode == 13){ //if generated character code is equal to ascii 13 (if enter key)
			return true;
		} else {
			return false;
		}
	}
	
	//Function hides the select boxes on the page.
	function hideSelectElements(frm) {
		for(i=0;i<frm.elements.length;i++) {
			if(frm.elements[i].type == 'select-one') {
				frm.elements[i].style.visibility = 'hidden';
			}
		}
	}
	
	//Function that shows the select boxes on the page.
	function showSelectElements(frm) {
		for(i=0;i<frm.elements.length;i++) {
			if(frm.elements[i].type == 'select-one') {
				frm.elements[i].style.visibility = 'visible';
			}
		}
	}
	
	//Function sets the focus on first Input element
	function init() {
		document.getElementsByTagName('input')[0].focus();
	}
	
		//Function to check the Blank Spaces..
	function isSpaceAvailable(field) {
		var passVal = field.value;
		
		var len = passVal.length;
		for (var i=0; i<len; i++) {
			if(passVal.charAt(i)==' '){
				return true;
				break;
			}
		}
	}
	
	
	/**
	** Added By : SP
	** Function to clear the textboxes  Blank ..
	**/
	
	function clearAllTextBoxes(){
			var node_list =  document.getElementsByTagName('input');
			for (var i = 0; i < node_list.length; i++) {
				var node = node_list[i];
				if (node.getAttribute('type') == 'text') {
					if("category"!=node.getAttribute('id')){
   				 		node.value='';
					}
					else {
						node.value=document.getElementById('category').value;
					}
			 	}
			}	
		}
		

	/**
	 * Function clears the text box for vendor (Request Service) 
	 * Added by Vivek
	 */
	function clearAllServiceTextBoxes(){
		var node_list =  document.getElementsByTagName('input');
		for (var i = 0; i < node_list.length; i++) {
			var node = node_list[i];
			objName= node.getAttribute('name');
			if (node.getAttribute('type') == 'text') {
				if(objName.indexOf('service') != -1){
				 		node.value='';
				}
		 	}
		}	
	}		
		
		function checkSpecialCharacters(field,msg){
		   var iChars = "!@#$%^&*()+=-[]\\\';./{}|\":<>?";
		   var fieldVal = field.value;
        	for (var i = 0; i < fieldVal.length; i++) {
                if (iChars.indexOf(fieldVal.charAt(i)) != -1) {
                alert (msg);
                field.focus();
                 field.select();
                return false;
        		}
                }
                return true;
		}   
		
		/**** Added by Jagdish For hide & show category list box on IE6 ******/
//		function hiddeText(shows){				
//			if(shows==''){
//				if(document.getElementById('serviceList') != null) {
//					document.getElementById('serviceList').style.display='none';
//					document.getElementById('selectedServices').style.display='none';	
//				}
//			}
//			else{
//				if(document.getElementById('serviceList') != null) {
//					document.getElementById('serviceList').style.display='';
//					document.getElementById('selectedServices').style.display='';	
//				}
//			}
//		}
		
		/********** function vlidate the html char in text box ***********/
		
		function checkHtmTag(str){
			 if(str.match(/([\<])([^\>]{1,})*([\>])/i)!=null) {
		        return false;
				}
			    else{
		         	return true;
			    }

			
		}
		
		
		/** Added By Atul on 18-09-2008 **/
		// check to see if input is alphabetic
		function isAlphabetic(val)
		{
		   if (val.match(/^[a-zA-Z ]+$/))
		      {
		         return true;
		       }
		      else
		      {
		         return false;
		      } 
		}

		/** Added by Atul , to format date in us format **/
		function changeFormat(givendate)
		   { // From M/D/Y to Y/M/D
		   
		     var dtCh= '/';
			 var pos1=givendate.indexOf(dtCh);
			 var pos2=givendate.indexOf(dtCh,pos1+1);
			
			 var fromMonth=givendate.substring(0,pos1);
			 var fromDay=givendate.substring(pos1+1,pos2);
			 var fromYear=givendate.substring(pos2+1);
			  
			 var newdate;
			 
			 newdate = fromYear +"-"+fromMonth+"-"+fromDay; 
			 
			 return newdate;
		   }
		   
		   /** Added By Atul, to check alphanumeric with spaces , comma , - , ' **/
		   function isAlphanumeric(sText,message)
             {
                var ValidChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890 -,_";
                var Char;
               
                 for (i = 0; i < sText.length ; i++ )
                   {
                    Char = sText.charAt(i);
                    if (ValidChars.indexOf(Char) == -1)
                          {
                          	 alert(message);
                             return false;
                          }
                   }
                 return true;
              }
        function checkValidString(field,msg){
		   var iChars = "!@#$%^&*()+=-[]\\\';./{}|\":<>?0123456789";
		   var fieldVal = field.value;
        	for (var i = 0; i < fieldVal.length; i++) {
                if (iChars.indexOf(fieldVal.charAt(i)) != -1) {
                alert (msg);
                field.focus();
                 field.select();
                return false;
        		}
                }
                return true;
		}   
		function checkValidStrings(field,msg){
		   var iChars = "!@#$%^&*+=[]\\\';./{}|\":<>?";
		   var fieldVal = field.value;
        	for (var i = 0; i < fieldVal.length; i++) {
                if (iChars.indexOf(fieldVal.charAt(i)) != -1) {
                alert (msg);
                field.focus();
                 field.select();
                return false;
        		}
                }
                return true;
		} 

		function checkValidStringsForBusinessName(field,msg){
		   var iChars = "!@#$%^*+=[]\\\';./{}|\":<>?";
		   var fieldVal = field.value;
        	for (var i = 0; i < fieldVal.length; i++) {
                if (iChars.indexOf(fieldVal.charAt(i)) != -1) {
                alert (msg);
                field.focus();
                 field.select();
                return false;
        		}
                }
                return true;
		} 		
		
			
		function checkValidPhoneNo(ph){
			var stripped = ph.replace(/[\s()+-]|ext\.?/gi, "");
			if(stripped==0){
				return false;
			}
			else {
				return true;
			}
			
		}    
              


/**
 * DHTML date validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

//Added by SP on 29 Sept 2008

 function validDateUS(fromDate,toDate)  
	{   
        var dtCh= '/';
		var pos1=fromDate.indexOf(dtCh);
		var pos2=fromDate.indexOf(dtCh,pos1+1);
		
		var fromMonth = fromDate.substring(0,pos1);
		var fromDay = fromDate.substring(pos1+1,pos2);
		var fromYear = fromDate.substring(pos2+1);
		 
		var end1=toDate.indexOf(dtCh);
		var end2=toDate.indexOf(dtCh,end1+1);
		
		var toMonth = toDate.substring(0,end1);
		var toDay = toDate.substring(end1+1,end2);
		var toYear = toDate.substring(end2+1);
		var eDate = new Date(toYear,toMonth-1,toDay);  
		
		// from date validation
		if (isNaN(fromMonth) || isNaN(fromDay) || isNaN(fromYear)) { 
		   alert('Invalid number. Please ensure the month, day and  year are valid numbers.');  
		   return false;  
		} 
		// check month range 
		if (fromMonth < 01 || fromMonth > 12) {  
		   alert('Invalid Month. Please ensure that the month is  between 1 and 12 inclusive.');  
		   return false;  
		} 
		// check day range 
		if (fromDay < 01 || fromDay > 31) {  
		   alert('Invalid Day. Please ensure that the day is between    1 and 31 inclusive.');  
		   return false;  
		} 
		// check day/month combination 
		if ((fromMonth==04 || fromMonth==06 || fromMonth==09 || fromMonth==11) && fromDay==31) { 
		   alert('Invalid Day/Month combination. Please ensure that    you have a valid day/month combination.'); 
		   return false; 
		} 
		// check for february 29th 
		if (fromMonth == 02) {  
		   var isleap = (fromYear % 4 == 0 && (fromYear % 100 != 0 || fromYear %    400 == 0)); 
		   if (fromDay>29 || (fromDay==29 && !isleap)) {  
		      alert('Invalid Day. This year is not a leap year. Please enter a value less than 29 for the day.'); 
		      return false 
		   } 
		} 
		// todate validation
		if (isNaN(toDay) || isNaN(toMonth) || isNaN(toYear)) { 
		   alert('Invalid number. Please ensure the day, month and  year are valid numbers.');  
		   return false;  
		} 
		// check month range 
		if (toMonth < 01 || toMonth > 12) {  
		   alert('Invalid Month. Please ensure that the month is  between 1 and 12 inclusive.');  
		   return false;  
		} 
		// check day range 
		if (toDay < 01 || toDay > 31) {  
		   alert('Invalid Day. Please ensure that the day is between 1 and 31 inclusive.');  
		   return false;  
		} 
		// check day/month combination 
		if ((toMonth==04 || toMonth==06 || toMonth==09 || toMonth==11) && toDay==31) { 
		   alert('Invalid Day/Month combination. Please ensure that you have a valid day/month combination.'); 
		   return false; 
		} 
		// check for february 29th 
		if (toMonth == 02) {  
		   var isleap = (toYear % 4 == 0 && (toYear % 100 != 0 || toYear %    400 == 0)); 
		   if (toDay>29 || (toDay==29 && !isleap)) {  
		      alert('Invalid Day. This year is not a leap year. Please enter a value less than 29 for the day.'); 
		      return false 
		   } 
		} 
		var sDate = new Date(fromYear,fromMonth-1,fromDay);  
		// what is the difference between the start date and end date 
		diff = eDate - sDate; 
		// get the difference in days 
		diff = Math.ceil(diff/1000/60/60/24); 
		if (diff < 0) { 
		   alert('Invalid Date. Please specify To Date that is in the future and not the past.');  
		   return false 
		} 
		return true;
	}   


		function validateNo(numStr)
		{	
		
			var str = '1234567890.';
			for(var idx=0; idx<numStr.length; idx++)
			{
				var char = numStr.charAt(idx);
				var match = false;
			
			for(var idx1=0; idx1<str.length; idx1++)
			{
				if(char == str.charAt(idx1))
					match = true;
			}
			
			if (!match)
				return false;
			}
				return true;
		}
		
	//Added by Vivek - This is to remove the error Not Implemented onLoad event of any HTML body/window.
	function addLoadEvent(func){
		var oldonload = window.onload;
		if(typeof window.onload != 'function'){
			window.onload = func;
		} else {
			window.onload = function() {
				if (oldonload) {
				        oldonload();
				      }
	      		func();
				//oldonload();
				//func();
			}
		}
	}

	//Added by SP to aviod the & and / from the input
	 function checkChar(obj){
	 	 var str = obj.value;
	     if(str.charAt(str.length-1)=='&' || str.charAt(str.length-1)=='/'){
	     	//document.getElementById('catName').value = str.substring(0,(str.length-1));
	     	obj.value = str.substring(0,(str.length-1));
	     } 
	     
	     for(i=0;i<str.length;i++)
	     {
	     	if(str.charAt(i)=='&' || str.charAt(i)=='/'){
	     	 obj.value = str.substring(0,i);
	     	 exit;
	     	}    	
	     }     
	  }
	  
	  // Added By Ganesh, to check alphanumeric with spaces , comma , - , '
	  function isAnnouncementAlphanumeric(sText,message) {
        var ValidChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890 -,_?!@.;";
        var Char;
       
         for (i = 0; i < sText.length ; i++ )
           {
            Char = sText.charAt(i);
            if (ValidChars.indexOf(Char) == -1)
              {
              	 alert(message);
                 return false;
              }
           }
         return true;
      }
      //chks whether an object exists or not in the document.
	  function chkObject(theVal) {
		if (document.getElementById(theVal) != null) {
				return true;
		} else {
			return false;
		}
	
	 }	

	 function validateAlphaNumericPassword(objPass){

	var sizechar = 6;			//length for password
	var upassID=objPass;
	var upass_string = upassID.value;
	var upass_string_len = upass_string.length;

    var valid="123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
    validCnt = 0;

    for (var i=0; i<upass_string_len; i++) {
        if (valid.indexOf(upass_string.charAt(i)) < 0) {
           validCnt++;
        }
    }
    
    if(validCnt==upass_string_len){
		alert('Your password contains invalid characters.');
		upassID.focus();
		return false;
    }

	var num_valid="123456789";
	var numcnt =0;

    for (var i=0; i<upass_string_len; i++) {
    	 if (num_valid.indexOf(upass_string.charAt(i)) < 0) {
            numcnt++;	    
        }    
        
    }
   
    if(numcnt == upass_string_len){
    		alert('Your password contains only characters. Please enter an alphanumeric password like -alpha123-');
			upassID.focus();
            return false;
    }
    

	var alph_valid="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
	var alphaCnt = 0;

    for (var i=0; i<upass_string_len; i++) {
    	
    	 if (alph_valid.indexOf(upass_string.charAt(i)) < 0) {        	
            alphaCnt++;
    	 	
        }
    }
    
    if(alphaCnt == upass_string_len){
    	alert('Your password contains only numbers. Please enter an alphanumeric password like -alpha123-');
		upassID.focus();
        return false;
    }    
    
	return true;
 }
	 