﻿// JScript source code
var errors = "";
var errorsa = "";    
var passwordField = false;
var mandatoryFieldsErrorFlag = false;
var sGeneralExp = "^[0-9a-zA-Z(),\.\/ & ';\:-]+$";
var sGeneralCityExp = "^[0-9a-zA-Z ,\.'\-]+$";
var sNumericExp = "^[\\s]*[0-9]+[\\s]*$";
var sAddressExp = "^[0-9a-zA-Z()\-,\.\/ & ]+$";
var sContactExp = "^[0-9a-zA-Z()\@,\. &\-]+$";
var sFloatExp = "^(([0-9])+([\.]([0-9])*)?)$";
var sEmailExp = "^[\s]*[a-zA-Z][a-z_0-9-\.]*[a-zA-Z|0-9]?@[a-zA-Z|0-9|\-]+([\.]([a-zA-Z][a-zA-Z][a-zA-Z]?)){1,2}[\s]*$";
var sAlphaExp = "^[a-zA-Z]*$";
var sPasswordWithoutSpaceExp = "^[^\ ]*$";
var sWebUrlExp = "(http|ftp|https):\/\/[\w_\-]+(\.[\w_\-]+)+([\w\.,@?^=%&amp;:/~\+#\-]*[\w\@?^=%&amp;/~\+#\-])?";
var sAlphaWithSpaceExp = "^[a-zA-Z ]*$"; 
var  sAlphaNumWithSpaceExp ="^[a-z A-Z 0-9]+[a-z A-Z 0-9]*$"; 
var sAlphaWithSpaceAndExp = "^([a-z A-Z]+([a-z A-Z &]*)?[a-zA-Z]+)$";
var sAlphaWithSpaceApostropheCommaExp = "^[a-z A-Z 0-9 ,]+[' a-z A-Z 0-9 ,]*$";
var sAlphaNumWithSpaceApostropheCommaColonExp = "^[A-Z a-z 0-9 ,]+[: ' , A-Z a-z 0-9 ]*$";
var sAlphaNumWithSpaceApostropheExp="^[A-Z a-z 0-9 ]+[ ' , A-Z a-z 0-9 ]*$";
var sAlphaNumericWithSpaceDotExp = "^[\s]*[a-zA-Z]+[a-zA-Z|0-9| |.]*[\s]*$";
var sChargesExp = "^[\s]*([0-9]{1,5})+([\.]?([0-9]{1,2}))?[\s]*$";
var sWorkExperienceExp = "^[\s]*([0-9]{1,2})+([\.]?([0-9]{1,2}))?[\s]*$";
var sPostalCodeExp = "^[\s]*(([0-9]{1,10})){1}[\s]*$";
var sEmailNameExp = "^[\s]*([a-zA-Z]*[a-z|A-Z|0-9\-\_\.])*[\s]*$";
var sPhoneNumberExp = "^[\s]*[0-9| |. + / ( ) -]*[\s]*$";
var sNewsletterTitleField="^[A-Z a-z 0-9 ,]+[: ' , ? A-Z a-z 0-9 ]*$";
var sDisplayNameExp="^[0-9a-zA-Z \\- @ _ . !]+$";
var s_Message = " ";
var sDisplayName_Message = s_Message + " should contain only letters, numbers, spaces, dot, hyphen, underscore, exclamation and @ symbol.";
var sWebURL_Message = s_Message + "should be in the format: http://websitename.xyz";
var sContact_Message = s_Message + " should contain only letters, numbers, spaces and , . & @ - ( )";
var sAddress_Message = s_Message + " should contain only letters,numbers, spaces comma (,) dot(.) ampersand (&) forward slash(/) and hyphen(-).";

var sGeneral_Message = s_Message + " should contain only letters, numbers, space, comma, colon, dot, semicolon, single quote, forward slash, hyphen and ampersand.";
var sGeneralCity_Message = s_Message + " should contain only letters, numbers, space, comma, dot, single quote, hyphen.";

var sPasswordWithoutSpace_Message = s_Message + ". It should not contain any space.";
var sName_Message = s_Message + " should contain only letters, no space.";
var sEmail_Message = s_Message + "Please enter a valid email address.";// in the format: username@domainname.xyz";
var sNumeric_Message = s_Message + " should contain only numbers.";
var sFloat_Message = s_Message + " should contain only numbers.";
var sPhoneNumber_Message = s_Message + "  should contain only numbers, add(+), minus(-), dot(.) forward slash(/) and space.";
var sAlpha_Message = s_Message + " should contain only letters.";
var sAlphaWithSpaceAnd_Message = s_Message + " should contain only letters, (&) , spaces, it should not start and end with (&). ";
var sAlphaNum_Message = sName_Message;
var sZip_Message = s_Message +" should be numeric and six digits.";
var sAlphaNumWithBraket_Message = s_Message +" should be a combination of letters, numbers, -, dot(.), comma, (, ) and should start with an alphabet.";
var sCompanyName_Message = s_Message +" should be a combination of letters, numbers, -, dot(.), comma(,), &, / and should start with an alphabet.";
var sRoleName_Message = s_Message + " should be a combination of letters, numbers, -, and should start with an alphabet.";
var sTimeWithSpace_Message = s_Message + " should be in the format: HH:MM AM or HH:MM PM.";
var sAlphaWithSpace_Message =  s_Message + " should contain only letters and spaces.";
var sAlphaNumWithSpace_Message =  s_Message + " should contain only letters, numbers and spaces.";
var sAlphaWithApostrophe_Message = s_Message + " should contain only letters and apostrophe.";
var sAlphaWithSpaceApostropheComma_Message = s_Message + " should contain only letters, numbers, spaces, comma (,) and apostrophe(')" ;
var sAlphaNumWithSpaceApostropheCommaColon_Message = s_Message + " should contain only letters, numbers, spaces, comma (,) apostrophe(') and colon(:)." ;
var sAlphaNumWithSpaceApostrophe_Message = s_Message + "should contain only letters, numbers, spaces and apostrophe (')." ;
var sAlphaNumericWithSpace_Message = s_Message + " should contain only letters, numbers and space.";
var sAlphaWithSpaceApostropheDot_Message =  s_Message + ". It should contain only letters, space, dot and apostrophe and should start with an alphabet." ;
var sPostalCode_Message = s_Message + " should contain only numbers and maximum of ten digits.";
var sDescription_Message = s_Message + " cannot contain more than 1024 characters.";
var sDescription_MessageBlank = s_Message + " cannot be blank.";
var sFeedLength_Message = s_Message + " should contain maximum 256 characters.";
var sEmailName_Message = s_Message + " should be a combination of letters, integers, -, _ , dot(.) and should start with an alphabet."; 
var sAlphaNumWithHyphenUnderScore_Message=s_Message + " should be a combination of letters, integers,hyphen(-),underscore(_) and should start with an alphabet."; 
var sDepartment_Message = s_Message + " should be a combination of letters, space, -, &, dot(.),(, ), # and should start with an alphabet.";
var sJobTitle_Message = s_Message + " should be a combination of letters, numbers, space, -, &, dot(.),comma, (, ), #, / and should start with an alphabet.";
var sQuizName_Message = s_Message + " should not contain \'<\' , \'>\' characters.";
var sStructure_Message = s_Message + " should not contain \'<\' , \'>\' characters.";
var sFillMandatoryFields_Message = " Please enter all the mandatory fields.";
var blankPasswordMsg = " Password Field cannot be blank.";
var sDescriptionFieldExpForNotificationTemplate_Message = s_Message + " should not contain \'<\' , \'>\' characters.";
var sAlphaNumWithSpaceApostropheCommaColonQuestionMark_Message = s_Message + "  should contain only letters, numbers, spaces, comma(,) question mark (?) apostrophe(') and colon(:)." ;
var sAlphaNum_Message = sName_Message;
var sFirstAlphaWithSpaceApostropheCommaExp_Message = s_Message + " should contain only letters,numbers,spaces,comma,apostrophe & colon. First character should be alphabet only" ;
var startdate;
var enddate;
var startday;
var startmonth;
var startyear;
var duration = 0;	
var starthr;
var startmin;
var startam;
var endhr;
var endmin;
var endam;
						
//*************************************************** Date Computation Function Ends Here. ************

function bValidate(formElement, validationType, isMandatory, alertName)
{
 	switch(validationType){
			case "Alpha":
			    formElement.value = trim(formElement.value);
				if(bCheck(formElement, sAlphaExp, isMandatory, alertName, sAlpha_Message)==false)
				{
					formElement.focus();
					return false;
				}
			break;					
			case "Numeric":
			    formElement.value = trim(formElement.value);
				if(bCheck(formElement, sNumericExp, isMandatory, alertName, sNumeric_Message)==false)
				{
					formElement.focus();
					return false;
				}
			break;	
			case "Float":
			    formElement.value = trim(formElement.value);
			   
				if(bCheck(formElement, sFloatExp, isMandatory, alertName, sFloat_Message)==false)
				{
					formElement.focus();
					
					return false;
				}
			break;		
			case "PhoneNumber":
			    formElement.value = trim(formElement.value);
			    if(bCheck(formElement, sPhoneNumberExp, isMandatory, alertName, sPhoneNumber_Message)==false)
			    {
					formElement.focus();
					return false;
				}
			break;
		  case "":
		        formElement.value = trim(formElement.value);
				if(isMandatory == "True")
				{		
					if (formElement.value=="")
					{						
					    if(mandatoryFieldsErrorFlag == false) 
					    {
					        errors +=alertName + " can not be blank." +'<br/>';  
						    mandatoryFieldsErrorFlag = true;
						}
						formElement.focus();
						return false;
					}
				}
			break;	
			case "PasswordWithoutSpace":
			    passwordField = true;
			    if(bCheck(formElement, sPasswordWithoutSpaceExp , isMandatory, alertName, sPasswordWithoutSpace_Message)==false)
			    {
					formElement.focus();
					return false;
				}
			break;			
			case "WebUrl":
			    formElement.value = trim(formElement.value);
			    if(bCheck(formElement, sWebUrlExp , isMandatory, alertName, sWebURL_Message)==false)
			    {
					formElement.focus();
					return false;
				}
			break;			
			case "Address":
			    formElement.value = trim(formElement.value);
			    if(bCheck(formElement, sAddressExp , isMandatory, alertName, sAddress_Message)==false)
			    {
					formElement.focus();
					return false;
				}
			break;
			case "General":
			    formElement.value = trim(formElement.value);
			    if(bCheck(formElement, sGeneralExp , isMandatory, alertName, sGeneral_Message)==false)
			    {
					formElement.focus();
					return false;
				}
			break;
			case "DisplayName":
			    formElement.value = trim(formElement.value);
			    if(bCheck(formElement, sDisplayNameExp , isMandatory, alertName, sDisplayName_Message)==false)
			    {
					formElement.focus();
					return false;
				}
			break;
			case "GeneralCity":
			    formElement.value = trim(formElement.value);
			    if(bCheck(formElement, sGeneralCityExp , isMandatory, alertName, sGeneralCity_Message)==false)
			    {
					formElement.focus();
					return false;
				}
			break;
			case "Contact":
			    formElement.value = trim(formElement.value);
			    if(bCheck(formElement, sContactExp , isMandatory, alertName, sContact_Message)==false){
					formElement.focus();
					return false;
				}
			break;
            case "AlphaWithSpaceApostropheComma":
                formElement.value = trim(formElement.value);
                if(formElement.value.indexOf("''") > 0)
				{
					formElement.focus();
					return false;
				}
				if(bCheck(formElement, sAlphaWithSpaceApostropheCommaExp, isMandatory, alertName, sAlphaWithSpaceApostropheComma_Message)==false){
					formElement.focus();
					return false;
				}
            break;
            case "AlphaNumWithSpaceApostropheCommaColon":
                formElement.value = trim(formElement.value);
                if(formElement.value.indexOf("''") > 0)
				{
					formElement.focus();
					return false;
				}
				if(bCheck(formElement, sAlphaNumWithSpaceApostropheCommaColonExp, isMandatory, alertName, sAlphaNumWithSpaceApostropheCommaColon_Message)==false){
					formElement.focus();
					return false;
				}
            break;      
            case "AlphaNumWithSpaceApostrophe":
           
                formElement.value = trim(formElement.value);
                if(formElement.value.indexOf("''") > 0)
				{
					//alert(alertName + " is in invalid format. Consecutive apostrophe are not allowed.");
					formElement.focus();
					return false;
				}
				if(bCheck(formElement, sAlphaNumWithSpaceApostropheExp, isMandatory, alertName, sAlphaNumWithSpaceApostrophe_Message)==false){
					formElement.focus();
					return false;
				}
            break;
			case "AlphaWithSpace":
			    formElement.value = trim(formElement.value);
				if(bCheck(formElement, sAlphaWithSpaceExp, isMandatory, alertName, sAlphaWithSpace_Message)==false){
					formElement.focus();
					return false;
				}
			break;
			
			case "AlphaNumWithSpace":		
			    formElement.value = trim(formElement.value);
				if(bCheck(formElement, sAlphaNumWithSpaceExp, isMandatory, alertName, sAlphaNumWithSpace_Message)==false){
					formElement.focus();
					return false;
				}
			break;			
			case "AlphaWithSpaceAnd":
			    formElement.value = trim(formElement.value);
			    if(bCheck(formElement, sAlphaWithSpaceAndExp, isMandatory, alertName, sAlphaWithSpaceAnd_Message)==false){
					formElement.focus();
					return false;
				}
			break;
			case "AlphaNumericWithSpaceDot":
			
			    formElement.value = trim(formElement.value);
			 
			    if(bCheck(formElement, sAlphaNumericWithSpaceDotExp, isMandatory, alertName, sAlphaNumericWithSpace_Message)==false){
					formElement.focus();
					return false;
				}
			break;	
			case "EmailName":
			    formElement.value = trim(formElement.value);
				if(formElement.value.indexOf("..") > 0)
				{
					formElement.focus();
					return false;
				}
				if(formElement.value.indexOf("--")>0)
				{
					formElement.focus();
					return false;
				}
				if(formElement.value.indexOf("__")>0)
				{
					formElement.focus();
					return false;
				}
			break;			
			case "PostalCode":
			    formElement.value = trim(formElement.value);
				if(bCheck(formElement, sPostalCodeExp, isMandatory, alertName, sPostalCode_Message)==false )
					{
					 //   errors +='<li>'+ alertName + sPostalCode_Message +'<br/></li>'; 
					    formElement.focus();
					    return false;
				    }
			break;			
			case "Email":
			    if (formElement != null)
			    {			      
			        formElement.value = trim(formElement.value);
				    if(isMandatory == "True")
				    {
				        if(formElement.value == "")
					    {
    				        if(mandatoryFieldsErrorFlag == false) 
					        {
					            errors += alertName + "can not be blank."+'<br/>';  
					            mandatoryFieldsErrorFlag = true;
					        }
						    formElement.focus();
						    return false;
					    }
					    else
					    {   if(emailCheck(formElement.value) == false)
						    {
							    errors +=sEmail_Message+'<br/>';  
							    formElement.focus();
							    return false;
						    }
						    else
						    {
						        if(bCheck(formElement, sEmailExp, isMandatory, "", sEmail_Message)==false)
						        {   
					                formElement.focus();
					                 return false;
				                }
						    }
					    }
				    }
				    else{
					        if(formElement.value != "")
					        {
						        if(emailCheck(formElement.value) == false)
						        {
							        formElement.focus();
							        errors += sEmail_Message+'<br/>';  
							        return false;
						        }
						        else
						        {
						            if(bCheck(formElement, sEmailExp, isMandatory, alertName, sEmail_Message)==false)
						            {
					                    formElement.focus();
					                   // errors +='<li>'+alertName+formElement.value+sEmail_Message+'<br/></li>';  
					                    return false;
				                    }
						        }
					        }    					    
				    }
		    }
			break;
			case "Date":
			    formElement.value = trim(formElement.value);
				if(isMandatory == "True"){
					if(formElement.value != ""){
						if(validateDate(formElement.value)== false){
							errors += alertName + " is in invalid format. It should be in MM/DD/YY format.";
							formElement.focus();
							return false;
						}
					}
					else{
					 	formElement.focus();
						return false;
					}
				}
				else if(isMandatory == "False" && formElement.value != ""){
					if(validateDate(formElement.value)== false){
							alert(alertName + " is in invalid format. The field should be in DD/MM/YYYY format.");
							formElement.focus();
							return false;
					}
				}
				break;				
			case "AlphaNumWithSpaceApostropheCommaColonQuestionMark":			
			    formElement.value = trim(formElement.value);
			    if( formElement.value=="")
			    {
			        errors += alertName + " can not be blank.";
			        formElement.focus();
					return false;
			    }
                if(formElement.value.indexOf("''") > 0)
				{
				
					//alert(alertName + " is in invalid format. Consecutive apostrophe are not allowed.");
					formElement.focus();
					return false;
				}
				if(bCheck(formElement, sNewsletterTitleField, isMandatory, alertName, sAlphaNumWithSpaceApostropheCommaColonQuestionMark_Message)==false){
					formElement.focus();
					return false;
				}
               break; 
		}			
	return true;
}

function bCheck(formElement, sExp, isMandatory, alertName, msg)
{   	
    //alert(sExp);
	objRegExp = new RegExp(sExp, 'gi');

	objRegExp = new RegExp(sExp);	
	//Don't trim for a password field & make the flag false;
	if(passwordField == true)
	{
	    passwordField = false;
	}
	else
	{ // Trim all fields other than password
	    formElement.value = trim(formElement.value);
	}
	
	if(isMandatory == 'True')
	{
		if(formElement.value !="")
		{		    		    
			if(objRegExp.test(formElement.value)==false)
			{
				errors +=alertName+msg+'<br/>';  
				return false;
			}
		}
		else
		{   if(mandatoryFieldsErrorFlag == false) 
			{
				errors += alertName + " can not be blank" + '.<br/>';  
		        mandatoryFieldsErrorFlag = true;
		    }
			return false;
		}
	}
	else{
		if(formElement.value!=""){
			if(objRegExp.test(formElement.value)==false){
				//alert(alertName+msg);
				errors +=alertName+msg+'<br/>';  
				return false;
			}
		}
	}	
	return true;
}
/*
 * Validates date strings.
 *
 * Parameter: field    - field containing the date string
 * Internal Calls: isInteger() and isNotBlank()
 * Returns:   true (valid date) or false (not valid) boolean
 */
function bIsDate(sValue) 
{
    var valid = true;
    var sDate = sValue;
    var Slash1Pos = sDate.indexOf("/",0);
    var Slash2Pos = sDate.indexOf("/",Slash1Pos + 1);
    var mm = sDate.substring(0,Slash1Pos);
    var dd = sDate.substring(Slash1Pos + 1,Slash2Pos);
    var yyyy = sDate.substring(Slash2Pos + 1,sDate.length);

    // Validate date
    if (bIsInteger(mm) == false || bIsInteger(dd) == false || bIsInteger(yyyy) == false)
    {   
        valid = false;
    }
    if (yyyy.length != 4)
    {
        valid = false;
    }
    if(yyyy < 2000 )
    {
		valid = false;
    }
	if(yyyy > 2080)
	{
		valid = false;
    }
    else 
    if (mm < 1 || mm > 12)
    {
        valid = false;
    }
    else 
    if (dd < 1 || dd > 31)
    {
        valid = false;
    }
    else 
    if (mm == 2) 
    {
        if (dd > 29)
        {
            valid = false ;
        }
        else 
        if (dd == 29)
        {
            if (yyyy % 100 == 0 && yyyy % 400 != 0)
            {
                valid = false;
            }
            else 
            if (yyyy % 4 != 0)
            {
                valid = false;
            }
        }
    }
    else 
    if (mm == 4 || mm == 6 || mm == 9 || mm == 11) 
    {
        if (dd > 30)
        {
            valid = false;
        }
    }
    if (valid == false) 
    {        
    }
    return valid;
}

function bIsInteger(sInteger) {

    var isInt = true;
    inputStr = sInteger.toString(); // in case not a string already
    for (var i = 0; i < inputStr.length; i++)
    {
        var oneChar = inputStr.charAt(i);
        if (oneChar < "0" || oneChar > "9") 
        {
            isInt = false;
            i = inputStr.length; // break out of loop when bad char found
        }
    } return isInt;
}

//added to make email validation more perfect.
function emailCheck (emailStr) 
{
	var emailPat=/^(.+)@(.+)$/;
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]";
	var validChars="\[^\\s" + specialChars + "\]";
	var quotedUser="(\"[^\"]*\")";
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	var atom=validChars + '+';
	var word="(" + atom + "|" + quotedUser + ")";
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
	var matchArray=emailStr.match(emailPat);
	if (matchArray==null) 
	{
		return false;
	}
	var user=matchArray[1];
	var domain=matchArray[2];

	// See if "user" is valid 
	if (user.match(userPat)==null) 
	{
		return false;
	}

	//if domain is ip address.
	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null) 
	{
		// this is an IP address
		for (var i=1;i<=4;i++) 
		{
			if (IPArray[i]>255) 
			{
			   return false;
			}
		}
		return true;
	}

	// Domain is symbolic name
	var domainArray=domain.match(domainPat);
	if (domainArray==null) 
	{
		return false;
	}

	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)
    {
	     return false;
	}

	// Make sure there's a host name preceding the domain.
	if (len<2) {
	return false;
	}

	// If we've gotten this far, everything's valid!
	return true;
}


function validateDate(sValue) {

    var valid = true;
    var sDate = sValue;
    var Slash1Pos = sDate.indexOf("/",0);
    var Slash2Pos = sDate.indexOf("/",Slash1Pos + 1);
    var mm = sDate.substring(0,Slash1Pos);
    var dd = sDate.substring(Slash1Pos + 1,Slash2Pos);
    var yyyy = sDate.substring(Slash2Pos + 1,sDate.length);
		
    // Validate date
    if (bIsInteger(mm) == false || bIsInteger(dd) == false || bIsInteger(yyyy) == false)
    {   valid = false;
    }

    if (yyyy.length != 4)
    {
        valid = false;
    }
    else 
    if (mm < 1 || mm > 12)
    {
        valid = false;
    }
    else 
    if (dd < 1 || dd > 31)
    {
        valid = false;
    }
    else 
    if (mm == 2)
    {
        if (dd > 29)
        {
            valid = false ;
        }
        else 
        if (dd == 29) 
        {
            if (yyyy % 100 == 0 && yyyy % 400 != 0)
            {
                valid = false;
            }
            else 
            if (yyyy % 4 != 0)
            {
                valid = false;
            }
        }
    } 
    else 
    if (mm == 4 || mm == 6 || mm == 9 || mm == 11)
    {
        if (dd > 30)
        {
            valid = false;
        }
    }
    return valid;
}


//function to check the new password and confirm password are same
function bCheckPassword(password,confirmpassword)
{	
   if(password.toString() == "")
	{
	    var passwordMsg = blankPasswordMsg;
	    if(mandatoryFieldsErrorFlag == false) 
	    {
		
	        errors+='<li>'+sFillMandatoryFields_Message+'<br/></li>'; 
	        mandatoryFieldsErrorFlag = true;
	    }
	    if(confirmpassword.toString() =="")
	    {
	        var passwordMsg = " Confirm Password field cannot be blank.";
	        if(mandatoryFieldsErrorFlag == false) 
			{
			    errors+='<li>'+sFillMandatoryFields_Message+'<br/></li>';  
	            mandatoryFieldsErrorFlag = true;
	        }
	        return false; 
	    }
	    return false;
	}else if(confirmpassword.toString() =="")
	{
	    var passwordMsg = " Confirm Password field cannot be blank.";
	    if(mandatoryFieldsErrorFlag == false) 
	    {
		    errors+='<li>'+sFillMandatoryFields_Message+'<br/></li>';  
	        mandatoryFieldsErrorFlag = true;
	    }
	    return false;  
	}
	if (password.toString()!= confirmpassword.toString())
	{
		
		var passwordMsg = "The New Password and Confirm Password fields should be the same.";
		errors+='<li>'+passwordMsg+'<br/></li>';   
		return false;
	}
	else
	{
		return true;
	}
}

//function to check the old password and new password are same
function bCheckSamePassword(oldpassword,newpassword)
{	
    if (oldpassword.value == newpassword.value)
	{
	    var passwordMsg = "New Password cannot be same as the Old Password.";
	    errors+='<li>'+passwordMsg+'<br/></li>';  
		return false;
	}
	else
	{
		return true;
    }
}
function checkPasswordStrength(str)
{
        var lbl = document.getElementById("divPasswordStrength");
        if(lbl != null && lbl != "")
        {
            lbl.style.display = "block";
        }
        var txtPassword = document.getElementById("txtPassword");
        var passwd = txtPassword.value;
       
        var intScore   = 0;
		var strVerdict = "No Password";
        
		// PASSWORD LENGTH
		if (passwd.length<5)                         // length 4 or less
		{
			intScore = (intScore+3);
		}
		else if (passwd.length>4 && passwd.length<8) // length between 5 and 7
		{
			intScore = (intScore+6);
		}
		else if (passwd.length>7 && passwd.length<16)// length between 8 and 15
		{
			intScore = (intScore+12);
		}
		else if (passwd.length>15)                    // length 16 or more
		{
			intScore = (intScore+18);
		}				
		// LETTERS (Not exactly implemented as dictacted above because of my limited understanding of Regex)
		if (passwd.match(/[a-z]/))                              // [verified] at least one lower case letter
		{
			intScore = (intScore+1);
		}
		
		if (passwd.match(/[A-Z]/))                              // [verified] at least one upper case letter
		{
			intScore = (intScore+5);
		}		
		// NUMBERS
		if (passwd.match(/\d+/))                                 // [verified] at least one number
		{
			intScore = (intScore+5);
		}
		
		if (passwd.match(/(.*[0-9].*[0-9].*[0-9])/))             // [verified] at least three numbers
		{
			intScore = (intScore+5);
		}			
		// SPECIAL CHAR
		if (passwd.match(/.[!,@,#,$,%,^,&,*,?,_,~]/))            // [verified] at least one special character
		{
			intScore = (intScore+5);
		}																		 // [verified] at least two special characters
		if (passwd.match(/(.*[!,@,#,$,%,^,&,*,?,_,~].*[!,@,#,$,%,^,&,*,?,_,~])/))
		{
			intScore = (intScore+5);
		}		
		// COMBOS
		if (passwd.match(/([a-z].*[A-Z])|([A-Z].*[a-z])/))        // [verified] both upper and lower case
		{
			intScore = (intScore+2);
		}
		if (passwd.match(/(\d.*\D)|(\D.*\d)/))                    // [FAILED] both letters and numbers, almost works because an additional character is required
		{
			intScore = (intScore+2);
		} 																  // [verified] letters, numbers, and special characters
		if (passwd.match(/([a-zA-Z0-9].*[!,@,#,$,%,^,&,*,?,_,~])|([!,@,#,$,%,^,&,*,?,_,~].*[a-zA-Z0-9])/))
		{
			intScore = (intScore+2);
		}	
		if(intScore <= 10)
		{
		   strVerdict = "Very Weak Password";
		   lbl.style.backgroundColor  = "gray";
		}
		else if (intScore > 10 && intScore <= 20)
		{
		   strVerdict = "Weak Password";
		   lbl.style.backgroundColor  = "tomato";
		}
		else if (intScore > 20 && intScore <= 30)
		{
		   strVerdict = "Medium Strength Password";
		   lbl.style.backgroundColor  = "yellow";
		}
		else if (intScore > 30 && intScore <= 40)
		{
		   strVerdict = "Strong Password";
		   lbl.style.backgroundColor  = "palegreen";
		}
		else
		{
		   strVerdict = "Very Strong Password";
		   lbl.style.backgroundColor  = "silver";
		}		
      lbl.innerHTML = strVerdict;   
}
function trim(stringToTrim) 
{
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}
function isTextBoxMaxLength(txtBox,maxChar) 
{
    var txtLength;
    if(txtBox)
    {
        txtLength = txtBox.value.length;
        if(txtLength<maxChar)
        {
            return true;
        }
        else
        {
            return false;            
        }
    }
}
   
//------------------------------------------------------------------------------------------
//Added by: Archana Date: 12 June 07
//Purpose : To validate newsletter while adding 
function validateDateOfMMDDYYYY(sValue) {

    var valid = true;
    var sDate = sValue;

    var Slash1Pos = sDate.indexOf("/",0);
    var Slash2Pos = sDate.indexOf("/",Slash1Pos + 1);
    var mm = sDate.substring(0,Slash1Pos);
    var dd = sDate.substring(Slash1Pos + 1,Slash2Pos);
    var yyyy = sDate.substring(Slash2Pos + 1,sDate.length);
		

    // Validate date
    if (bIsInteger(mm) == false || bIsInteger(dd) == false || bIsInteger(yyyy) == false)
    {
        valid = false;
    }

    if (yyyy.length != 4)
    {
        valid = false;
    }
    else 
    if (mm < 1 || mm > 12)
    {
        valid = false;
    }
    else 
    if (dd < 1 || dd > 31)
    {
        valid = false;
    }
    else 
    if (mm == 2) 
    {
        if (dd > 29)
        {
            valid = false ;
        }
        else 
        if (dd == 29)
        {
            if (yyyy % 100 == 0 && yyyy % 400 != 0)
            {
                valid = false;
            }
            else 
            if (yyyy % 4 != 0)
            {
                valid = false;
            }
        }
    } 
    else 
    if (mm == 4 || mm == 6 || mm == 9 || mm == 11)
     {
        if (dd > 30)
        {
            valid = false;
        }
    }
    return valid;
}

//To avoid post back
function IgnoreEnterKey(e)
{
   // alert("IgnoreEnterKey");
   
    var controlTagName;
    var inputType;
    if(e.srcElement)
    {
        controlTagName = e.srcElement.tagName;
        inputType = e.srcElement.type;
    }
    else
    {
        controlTagName = e.target.tagName;
        inputType = e.target.getAttribute("type");
    }
    
    var textBox = "";
    if(controlTagName == "INPUT" && inputType == "text" || inputType == "password")
    {
        textBox = "true";
    }
    else if(controlTagName == "INPUT")
    {
        textBox = "false";
    }
    
    if(controlTagName == "TEXTAREA" || controlTagName == "IMG" || controlTagName == "A" )
    {
        // Do nothing allow enter key 
    }
    else if(textBox == "true")
    {
        if (e.keyCode == 13)
        {
            if (e.stopPropagation) 
            {
                e.stopPropagation();
                e.preventDefault();  
            }
            else
            {
                e.returnValue=false;
                e.cancel = true;
            }
        }
    }
    else
    {
        if (e.keyCode == 13)
        {
            if (e.stopPropagation) 
            {
                e.stopPropagation();
                e.preventDefault();
            }
            else
            {
                e.returnValue=false;
                e.cancel = true;
            }
        }
    }
}

function AddDays()
{   
    var month;
    var length;
    var len;
    var oNewOption;
    month = document.getElementById('ddlMonth').value;
    
    if(month == "2")
    {
        length = document.getElementById('ddlDayOfMonth').options.length;
        
        if(length == 31)
        { 
            len = document.getElementById('ddlDayOfMonth').options.length-1;
            for (var i=length; i>=len; i--)
            {
                document.getElementById('ddlDayOfMonth').options[i] = null;
            }
        }
        else if(length == 32)
        {
            len = document.getElementById('ddlDayOfMonth').options.length-2;
            for (var i=length; i>=len; i--)
            {
                document.getElementById('ddlDayOfMonth').options[i] = null;
            }
        }
        var year;
        year = document.getElementById('ddlBirthYear').value;
        if(year%4 != 0)
        {
            
            selectedMonth = document.getElementById('ddlMonth').selectedIndex;
            selectedDate = document.getElementById('ddlDayOfMonth').selectedIndex;
            
            if(selectedMonth==2) //selected month is feb
            {
                //Index starts from 0, so here we are checking if selected date is 29, if yes then make it 28
                if(selectedDate == 29)
                {
                    document.getElementById('ddlDayOfMonth').selectedIndex = "28";
                }
                length = document.getElementById('ddlDayOfMonth').options.length;
                len = document.getElementById('ddlDayOfMonth').options.length-1;
               
                for (var i=length; i>=len; i--)
                {
                    document.getElementById('ddlDayOfMonth').options[i] = null;
                }                
            }
        }
    }
    else if(month =="1" || month =="3" || month =="5" || month =="7" || month =="8" || month =="10" || month =="12")
    {
        length = document.getElementById('ddlDayOfMonth').options.length;
        if(length == 29)
        {
            
            oNewOption = document.createElement("OPTION");
            oNewOption.text = "29";
            oNewOption.value = "29";
            document.getElementById('ddlDayOfMonth').options[length] = oNewOption;
            
            oNewOption = document.createElement("OPTION");
            oNewOption.text = "30";
            oNewOption.value = "30";
            length = document.getElementById('ddlDayOfMonth').options.length;
            document.getElementById('ddlDayOfMonth').options[length] = oNewOption;
            
            oNewOption = document.createElement("OPTION");
            oNewOption.text = "31";
            oNewOption.value = "31";
            length = document.getElementById('ddlDayOfMonth').options.length;
            document.getElementById('ddlDayOfMonth').options[length] = oNewOption;
        }
        else 
        if(length == 30)
        {
            oNewOption = document.createElement("OPTION");
            oNewOption.text = "30";
            oNewOption.value = "30";
            document.getElementById('ddlDayOfMonth').options[length] = oNewOption;
            
            
            oNewOption = document.createElement("OPTION");
            oNewOption.text = "31";
            oNewOption.value = "31";
            length = document.getElementById('ddlDayOfMonth').options.length;
            document.getElementById('ddlDayOfMonth').options[length] = oNewOption;
        }
        else if(length == 31)
        {
            oNewOption = document.createElement("OPTION");
            oNewOption.text = "31";
            oNewOption.value = "31";
            document.getElementById('ddlDayOfMonth').options[length] = oNewOption;
        }
    
    }
    else
    {
        length = document.getElementById('ddlDayOfMonth').options.length;
        
        if(length == 32)
        {
            len = document.getElementById('ddlDayOfMonth').options.length-1;

            for (var i=length; i>=len; i--)
            {
                document.getElementById('ddlDayOfMonth').options[i] = null;
            }
            
        }
        else if(length == 30)
        {
            oNewOption = document.createElement("OPTION");
            oNewOption.text = "30";
            oNewOption.value = "30";
            document.getElementById('ddlDayOfMonth').options[length] = oNewOption;
           
        } 
        else if(length == 29)
        {
            oNewOption = document.createElement("OPTION");
            oNewOption.text = "29";
            oNewOption.value = "29";
            document.getElementById('ddlDayOfMonth').options[length] = oNewOption;
            
            oNewOption = document.createElement("OPTION");
            oNewOption.text = "30";
            oNewOption.value = "30";
            length = document.getElementById('ddlDayOfMonth').options.length;
            document.getElementById('ddlDayOfMonth').options[length] = oNewOption;          
        } 
    }
}

function CheckLeapYear()
{
    var year;
    year = document.getElementById('ddlBirthYear').value;
    var length;
    var len;
    var LeapYearday ="29";
    var selectedMonth;
    var selectedDate;
  
    selectedMonth = document.getElementById('ddlMonth').selectedIndex;
    selectedDate = document.getElementById('ddlDayOfMonth').selectedIndex;        
    
    if(selectedMonth==2)
    {
        if(year%4 != 0)
        {          
            //Index starts from 0, so here we are checking if selected date is 29, if yes then make it 28
            if(selectedDate == 29)
            {
                document.getElementById('ddlDayOfMonth').selectedIndex = "28"; 
            }   
            document.getElementById('ddlDayOfMonth').options.length =LeapYearday;
            document.getElementById('ddlDayOfMonth').options[LeapYearday] = null;
        }
        else
        {
            document.getElementById('ddlDayOfMonth').options.length ="29";
            oNewOption = document.createElement("OPTION");
            oNewOption.text = "29";
            oNewOption.value = "29";
            document.getElementById('ddlDayOfMonth').options[29] = oNewOption;
        }
    }    
}
function CheckDate()
{
    var year;
    year = document.getElementById('ddlBirthYear').value;
    
    if ( document.getElementById('ddlBirthYear').selectedIndex > 0 )
    {    
        if(year%4 != 0)
        {            
           var selectedMonth = document.getElementById('ddlMonth').selectedIndex;
           var selectedDate = document.getElementById('ddlDayOfMonth').selectedIndex;
           
           if(selectedMonth==2) //selected month is feb
            {
                //Index starts from 0, so here we are checking if selected date is 29, if yes then make it 28
                if(selectedDate == 29)
                {
                    document.getElementById('ddlDayOfMonth').selectedIndex = "28";
                    var length = document.getElementById('ddlDayOfMonth').options.length;
                    var len = document.getElementById('ddlDayOfMonth').options.length-1;
                    for (var i=length; i>=len; i--)
                    {
                        document.getElementById('ddlDayOfMonth').options[i] = null;
                    }           
                }
            }
        }
     }   
}

//function to check the new password and confirm password are same
function bValidatePassword(password)
{	
    if(password.toString() == "")
	{
    	errors = blankPasswordMsg;
    	return false;
	}
	return true;
}
function CheckImageFileType(ImageFileName)
{ 
    var extension =   ImageFileName.substring(ImageFileName.length-3);
    if(extension == "png" || extension == "gif" || extension == "bmp" || extension == "PNG" || extension == "GIF" || extension == "BMP")
    {
        return true;
    }
    else
    {
       errors += "Only .bmp, .gif, and .png file formats are allowed."; 
       return false;
    }
}