﻿// JScript FILE
// LOUIE D DULNUAN JR.
   function Sample_mouseover(imgItem,image)
    {      
       document.getElementById(imgItem).style.backgroundColor = image;
    }

    // ***** SCRIPT TO GO TO URL *****
    function gotoURL(URL)
    {
        window.location.href=URL;
    }
    function changeMenuHeader(imgItem1,imgItem2,imgItem3,imgItem4,image1,image2,image3,image4)
    {

       var cImage1 = document.getElementById(imgItem1);
       cImage1.src = image1;
       cImage1.width = 133;
       cImage2.height= 25;
       var cImage2 = document.getElementById(imgItem2);
       cImage2.src = image2;
       cImage2.width = 133;
       cImage2.height= 25;
       var cImage3 = document.getElementById(imgItem3);
       cImage3.src = image3;
       cImage3.width = 133;
       cImage3.height= 25;
       var cImage4 = document.getElementById(imgItem4);
       cImage4.src = image4;
       cImage4.width = 133;
       cImage4.height= 25;
       
    }
     function newWindow(URL)
    {
    var win_width = 800;
    var win_height = 600;
    var loc_left = (screen.width/2) - (win_width/2);
	var loc_top = (screen.height/2) - (win_height/2);
    var name = "bank";
	var style = "top=" + loc_top + ", left=" + loc_left +
		"toolbar=yes,location=yes,directories=yes," + 
		"status=yes,menubar=yes,scrollbars=yes," + 
		"resizable=yes,copyhistory=yes,width=" + win_width +
		",height=" + win_height;
	var c_win = window.open(URL,name,style);
	c_win.focus();
    }
    // ***** END SCRIPT *****
    function Logout()
    {  //alert('louie');
        var ans = confirm("Are you sure you want to logout?");
        if (ans == true)
        {
             window.location.href='Login.aspx?Logout=1';
             
        }
       
    }
    // ***** SCRIPT FOR CONTROL VALIDATION *****
    function checkEmptyControl(ctrlvalue)
    {  
        //var txtCntrl = document.getElementById(ctrlname);
        if(ctrlvalue=='0')
        {
            alert('Please enter a value');
            return false;
        }
        else return true;
        
    }
    // ***** END SCRIPT *****
    
    // ***** SCRIPT FOR ENABLE AND DISABLE OF CONTROLS *****
    function disablecontrol(ctrlname)
    {
       var buttonctrl = document.getElementById(ctrlname);
       buttonctrl.Enabled = false;      
    }
    function enablecontrol(ctrlname)
    {
       var buttonctrl = document.getElementById(ctrlname);
       buttonctrl.Enabled = false;
    }
    // ***** END SCRIPT *****
    
    // ***** SCRIPT TO HIDE CONTROLS *****
    function HideControls(ctrlname1,ctrlname2,blnFlag)
    {
       var buttonctrl1 = document.getElementById(ctrlname1);
       var buttonctrl2 = document.getElementById(ctrlname2);
       
       buttonctrl1.Visible = false;
       buttonctrl1.Visible=false;

 
    }
    // ***** END SCRIPT *****
   
    // ***** SRCIPT TO CHANGE IMAGE OR FONTS *****   
    function changeMenu(imgItem,image)
    {      
       document.getElementById(imgItem).style.backgroundImage="url"+"('"+image+"')"  
    }
    function swapFontSize(LBitem,blnTag,intfontsize)
    {      
     
       var cImage = document.getElementById(LBitem);
       if (blnTag==true)
       {
       
            cImage.style.fontstyle='Bold';
            cImage.style.fontSize = intfontsize;
        }
        else
        {
            cImage.style.fontstyle='Normal';
            cImage.style.fontSize = intfontsize; 
        }       
    }
    function swapFontColor(LBitem,blnTag,varfontcolor)
    {      
     
       var cImage = document.getElementById(LBitem);
       if (blnTag==true)
       {
            cImage.style.color = varfontcolor;
        }
        else
        {
            cImage.style.color = varfontcolor; 
        }       
    }
    function swapBGimage(imgItem,BGmenu,BGimage,varfontcolor)
    {
       //var cImage = document.getElementById(imgItem);
       //cImage.innerHTML='<img src=' + BGimage + '>';

       var cImage1 = document.getElementById(imgItem);
       var cImage2 = document.getElementById(BGmenu);
       //cImage.innerHTML='<img src=' + BGimage + '>';
       cImage2.ForeColor = varfontcolor;
       alert(varfontcolor);
       
       
    }
    function swapImage(imgItem,image)
    {      
        //alert('try');
       var cImage = document.getElementById(imgItem);
       cImage.src = image;
    }
    function swapImageMenu(imgItem,image)
    {
       var cImage = document.getElementById(imgItem);
       cImage.src = image;
       cImage.width = 115;
       cImage.height= 25;
    }
    function changeSubMenu(imgItem,LBitem,intflag)
    {      
        var cLinkButton = document.getElementById(LBitem);
        var cImage = document.getElementById(imgItem);
       
        
        if(intflag=='0')
        {
       
        cLinkButton.style.fontstyle='Bold';
        cLinkButton.style.fontSize = 17;
        cLinkButton.style.color = "#23256C" //"#5E90AF";
        
        cImage.src='images/arrow.gif'; 
        
        }
        else
        {  
         
        cLinkButton.style.fontstyle='Normal';
        cLinkButton.style.fontSize = 14;
        cLinkButton.style.color = "blue"//"#8A5A64";
        
        cImage.src='images/arrow copy.bmp';  
        
        }  
    }
    // ***** END SCRIPT *****
    
    
    //SCRIPT FOR WINDOWS POPUP
    function GotoPopup(urlPath, windowName,win_width,win_height){ 
    
	var loc_left = (screen.width/2) - (win_width/2);
	var loc_top = (screen.height/2) - (win_height/2);
	var url = urlPath;
	var name = windowName;
	var style = "top=" + loc_top + ", left=" + loc_left +
		"toolbar=no,location=no,directories=no," + 
		"status=no,menubar=yes,scrollbars=no," + 
		"resizable=no,copyhistory=no,width=" + win_width +
		",height=" + win_height;
		
		
	//var style = "dialogWidth:" + win_width + "px;dialogHeight:" + win_height + "px;"
	//var c_win = window.showModalDialog(url,name,"dialogWidth:400px;dialogHeight:200px;");	
	var c_win = window.open(url,name,style);
	c_win.focus();	
	}
	 function GotoPopupPrint(urlPath, windowName,win_width,win_height){    
    
	var loc_left = (screen.width/2) - (win_width/2);
	var loc_top = (screen.height/2) - (win_height/2);
	var url = urlPath;
	var name = windowName;
	var style = "top=" + loc_top + ", left=" + loc_left +
		"toolbar=no,location=no,directories=no," + 
		"status=no,menubar=yes,scrollbars=yes," + 
		"resizable=no,copyhistory=no,width=" + win_width +
		",height=" + win_height;
	
	//var c_win = window.showModalDialog(url,name,style);	
	var c_win = window.open(url,name,style);
	c_win.focus();	
	}
	 function GotoPopupResizable(urlPath, windowName,win_width,win_height){ 
	 win_width=800;
	 win_height =600;
	var loc_left = (screen.width/2) - (win_width/2);
	var loc_top = (screen.height/2) - (win_height/2);
	var url = urlPath;
	var name = windowName;
	var style = "top=" + loc_top + ", left=" + loc_left +
		"toolbar=yes,location=yes,directories=yes," + 
		"status=yes,menubar=yes,scrollbars=yes," + 
		"resizable=yes,copyhistory=yes,width=" + win_width +
		",height=" + win_height;
	var c_win = window.open(url,name,style);
	c_win.focus();	}
	//SCRIPT FOR WINDOWS POPUP
    function GotoPopupModal(url, windowName,win_width,win_height){    
	var c_win = window.showModalDialog(url,windowName,"status:yes;resizable=yes;dialogWidth:" + win_width +"px;dialogHeight:" + win_height + "px;");
	c_win.focus();		
	}
	
	//SCRIPT FOR WINDOWS POPUPMODAL
    function GotoPopupModal(urlPath, windowName,win_width,win_height){ 
    
	var loc_left = (screen.width/2) - (win_width/2);
	var loc_top = (screen.height/2) - (win_height/2);
	var url = urlPath;
	var name = windowName;
		
	var style = "dialogWidth:" + win_width + "px;dialogHeight:" + win_height + "px;"
	var c_win = window.showModalDialog(url,name,style);	
	//var c_win = window.showModalDialog(url,name,"dialogWidth:600px;dialogHeight:400px;");	
	c_win.focus();
	}
	
	// ***** END SCRIPT *****
	
	
	//GRID UTILITIES
	// Utility File for MouseOver activity

    var cGridItemClassName;
    var oGridItemClassName = "griditemover";
    var nGridItemClassName = "font";

    var cBGColor;
    var sBGColor="#faebd7";

    var cGridItem

    function ItemMouseOver(objItem){
	    if(cGridItem != objItem){		
		    cGridItemClassName = objItem.className;
		    cGridItemStyle = objItem.style;
		    objItem.className = oGridItemClassName;
	    }
	    else{
		    objItem.className = oGridItemClassName;
	    }
    }

    function ItemMouseOut(objItem){
	    if(cGridItem != objItem){
		    objItem.className = cGridItemClassName;		
	    }
	    else{
		    objItem.className = cGridItemClassName;
	    }
    }

    function ItemMouseClick(objItem){		
	    if((cGridItem != null)&&(cGridItem!=objItem)){				
		    cGridItem.className=nGridItemClassName;		
		    cGridItem.style.backgroundColor = cBGColor;
	    } 		
    			
	if(sBGColor==objItem.style.backgroundColor){
		return false;
	}			
	
	cBGColor = objItem.style.backgroundColor;	
	cGridItem=objItem;
	cGridItem.className = nGridItemClassName;
	cGridItem.style.backgroundColor= sBGColor;		
	return true;
    }


    function SetFocusToControl(obj){
	    obj.focus();
    }


    //In JS //d9f1f9

    var oldgridSelectedColor; 
    function setMouseOverColor(element) 
    { 
        if(element.style.backgroundColor!='#cccccc') 
        {
            oldgridSelectedColor = element.style.backgroundColor; 
            element.style.backgroundColor='#d9f1f9'; 
            //element.style.cursor='hand'; 
        } 
        
    } 
    function setMouseOutColor(element) 
    {
        if(element.style.backgroundColor!='#cccccc') 
        {
            element.style.backgroundColor=oldgridSelectedColor; 
            element.style.textDecoration='none'; 
        } 
       
    } 

    function setMouseClickColor(element) 
    {
    if(element.style.backgroundColor=='#d9f1f9') 
        {
            element.style.backgroundColor='#cccccc'; 
        }

    else if(element.style.backgroundColor=='#cccccc') 
        {
            element.style.backgroundColor='white'; 
        }

    }

function PrintThis(){
//if (window.print)
//	{alert(1);
	//alert('Use "Landscape" page orientation in printing this document.');
	window.print() ;
//	}
}
function ValidateInputLogin(fieldName,fieldValue)
{

        var strNeg = "'<>'";
		var strChar;	
		var objVar;
		if(fieldName==undefined)
		{
		    objVar = fieldName.id;
		}
		else
		{
		    objVar= fieldName;
		}
		
		for (i = 0; i < fieldValue.length; i++)
		{		
			strChar = fieldValue.charAt(i);
			if (strNeg.indexOf(strChar) > 0)
			{
			alert("You have provided an invalid character.");
			fieldName.value = fieldValue.replace(strChar, '');
			//fieldName.select();
			fieldName.focus();
			return (false)
			}			
		}
}
function ValidateInput(fieldName,fieldValue)
{

        var strNeg = "'<>'";
		var strChar;	
		var objVar;
		if(fieldName==undefined)
		{
		    objVar = fieldName.id;
		}
		else
		{
		    objVar= fieldName;
		}
		
		for (i = 0; i < fieldValue.length; i++)
		{
			strChar = fieldValue.charAt(i);
			if (strNeg.indexOf(strChar) > 0)
			{
			alert("You have provided an invalid character.");
			fieldName.value = fieldValue.replace(strChar, '');
			//fieldName.select();
			fieldName.focus();
			return (false)
			}			
		}
}
function ValidateInputEmail(fieldName,fieldValue)
{

        var strNeg = "'<>'";
		var strChar;	
		var objVar;
		if(fieldName==undefined)
		{
		    objVar = fieldName.id;
		}
		else
		{
		    objVar= fieldName;
		}
		
		for (i = 0; i < fieldValue.length; i++)
		{
			strChar = fieldValue.charAt(i);
			if (strNeg.indexOf(strChar) > 0)
			{
			alert("You have provided an invalid character.");
			fieldName.value = fieldValue.replace(strChar, '');
			//fieldName.select();
			fieldName.focus();
			return (false)
			}			
		}
}
function ValidateInputPassword(fieldName,fieldValue)
{

        var strNeg = "'<>'\{/[]}^";
		var strChar;	
		var objVar;
		if(fieldName==undefined)
		{
		    objVar = fieldName.id;
		}
		else
		{
		    objVar= fieldName;
		}
		
		for (i = 0; i < fieldValue.length; i++)
		{
			strChar = fieldValue.charAt(i);
			if (strNeg.indexOf(strChar) > 0)
			{
			alert("You have provided an invalid character.");
			fieldName.value = fieldValue.replace(strChar, '');
			//fieldName.select();
			fieldName.focus();
			return (false)
			}			
		}
}
function ValidateInputEmailBody(fieldName,fieldValue)
{

        var strNeg = "'<>/\{[]}";
		var strChar;	
		var objVar;
		if(fieldName==undefined)
		{
		    objVar = fieldName.id;
		}
		else
		{
		    objVar= fieldName;
		}
		
		for (i = 0; i < fieldValue.length; i++)
		{
			strChar = fieldValue.charAt(i);
			if (strNeg.indexOf(strChar) > 0)
			{
			alert("You have provided an invalid character.");
			fieldName.select();					
			fieldName.focus();
			return (false)
			}			
		}
}
function ValidNumberDate(fieldName,fieldValue,DDYY)
{

        var strNeg = "1234567890";
        var strInvalidChar = "'<>'\{/[]}^";
		var strChar;	
		var objVar;
		if(fieldName==undefined)
		{
		    objVar = fieldName.id;
		}
		else
		{
		    objVar= fieldName;
		}
		if(fieldValue.length > 0)
		{		
		    for (i = 0; i < fieldValue.length; i++)
		    {
			    strChar = fieldValue.charAt(i);
			    if (strInvalidChar.indexOf(strChar) > 0)
			    {
			        alert("You have provided an invalid character.");
			        fieldName.select();					
			        fieldName.focus();
			        return (false)
			    }
			    
			    if (strNeg.indexOf(strChar) > -1)
			    {
			    //do nothing
			    }
			    else
			    {
			    //alert(strNeg.indexOf(strChar));
			    alert("Please enter valid numeric values.");
			    fieldName.select();					
			    fieldName.focus();
			    return (false)
			    }			
		    }
		var d=new Date();
		if(DDYY=='year')
		{
		    
            var year=d.getFullYear();            
		    if((fieldValue > 1930) && (fieldValue < year + 1))
		    {		
    		    
		    }
		    else
		    {
		        alert("Please enter year between 1930 up to " + year + " .");
		        return (false)
		    }
		}
		else
		{
		    if((fieldValue > 0) && (fieldValue < 32))
		    {		
    		    
		    }
		    else
		    {
		        alert("Please enter valid days.");
		        return (false)
		    }
		}
		}		
		
		
		
}
function ValidContacts(fieldName,fieldValue)
{

        var strNeg = "1234567890-.(),";
        var strInvalidChar = "'<>'\{/[]}^";
		var strChar;	
		var objVar;
		if(fieldName==undefined)
		{
		    objVar = fieldName.id;
		}
		else
		{
		    objVar= fieldName;
		}
		if(fieldValue.length > 0)
		{
		    for (i = 0; i < fieldValue.length; i++)
		    {
			    strChar = fieldValue.charAt(i);
			    if (strInvalidChar.indexOf(strChar) > 0)
			    {
			        alert("You have provided some invalid character.");
			        fieldName.select();					
			        fieldName.focus();
			        return (false)
			    }
			    if (strNeg.indexOf(strChar) < 0)
			    {
			    //do nothing
			    }
			    else
			    {
			    alert("Please enter valid numeric values.");
			    fieldName.select();					
			    fieldName.focus();
			    return (false)
			    }			
		    }
		}
		else
		{
		    alert("Please enter valid numeric values.");
		}
}
function ValidNumbers(fieldName,fieldValue)
{

        var strNeg = "1234567890-.,";
        var strInvalidChar = "'<>'\{/[]}^";
		var strChar;	
		var objVar;
		if(fieldName==undefined)
		{
		    objVar = fieldName.id;
		}
		else
		{
		    objVar= fieldName;
		}
		if(fieldValue.length > 0)
		{
		    for (i = 0; i < fieldValue.length; i++)
		    {
			    strChar = fieldValue.charAt(i);
			    if (strInvalidChar.indexOf(strChar) > 0)
			    {
			        alert("You have provided some invalid character.");
			        fieldName.select();
			        fieldName.focus();
			        return (false)
			    }
			    if (strNeg.indexOf(strChar) < 0)
			    {
			    //do nothing
			    }
			    else
			    {
			    alert("Please enter valid numeric values.");
			    fieldName.select();					
			    fieldName.focus();
			    return (false)
			    }			
		    }
		}
		else
		{
		    alert("Please enter valid numeric values.");
		}
}

function setSearchRegEx(objValidator,val)
{
    var regExpression = "";
    var valMessage = "Must be in the following format: ";
    var message = "";

    // set regex information depending on what drop down value they select.
    switch (document.getElementByID('ddlValue1.ClientID').value) {
        case "Value1":
            regExpression = "^[a-zA-Z0-9'*\s-]{1,75}$";
            message = valMessage + "[A-Z][0-9]'. #-";
            break;
        case "Value2":
            regExpression = "^\[0-9]{3}-\[0-9]{2}-\[0-9]{4}|\d{9}$";
            message = valMessage + "999-99-9999";
            break;
        case "Value3":
            regExpression = "[a-zA-Z0-9'*\s-]{1,50}$";
            message = valMessage + "[A-Z][0-9]'. #-";
            break;
        case "Valu4":
            regExpression = "^\[0-9]{3}-\[0-9]{3}-\[0-9]{4}$";
            message = valMessage + "999-999-9999";
            break;
        case "Value5":
            regExpression = "^[0-9]{1,10}$";
            message = valMessage + "9999999999";
            break;
        default:
            regExpression = "";
            message = "";
    }
    // set validation control values for the new drop down selected.
    val.validationexpression = regExpression;
    val.errormessage = message;
    val.title = message;

    // fire the validation function to validate what is currently in the textbox
    val.isvalid = val.evaluationfunction(val);
    //call the function to manipulate the UI
    validatorUpdateDisplay(val);
}

function validatorUpdateDisplay(val)
{
    if (val.isvalid) {

        //make the error invisible
        val.display = "none";
    }
    else {

        var browser = navigator.appName;

        //different browsers get updated differently, IE really the only main one to update differently.
        if (browser == "Microsoft Internet Explorer") {
            val.ValidatorCalloutBehavior._errorMessageCell.innerText = val.errormessage;
        }
        else {
            val.ValidatorCalloutBehavior._errorMessageCell.textContent = val.errormessage;
        }

        //make the error visible
        val.display = "inline";
    }          
}
function _CustomValidatorValidateNumbers(fieldName,fieldValue)
{

        var strNeg = "1234567890-.,";
        var strInvalidChar = "'<>'\{/[]}^";
		var strChar;	
		var objVar;
		var blnReturn = true;
		if(fieldName==undefined)
		{
		    objVar = fieldName.id;
		}
		else
		{
		    objVar= fieldName;
		}
		if(fieldValue.length > 0)
		{
		    for (i = 0; i < fieldValue.length; i++)
		    {
			    strChar = fieldValue.charAt(i);
			    if (strInvalidChar.indexOf(strChar) > 0)
			    {			        
			        fieldName.select();
			        fieldName.focus();
			        blnReturn= false;
			    }
			    if (strNeg.indexOf(strChar) < 0)
			    {
			    //do nothing
			    }
			    else
			    {			    
			    fieldName.select();					
			    fieldName.focus();
			    blnReturn= false;
			    }			
		    }
		}
		else
		{
		   blnReturn= false;
		}
		return blnReturn;
}

//Validates user input for signup profile
function ValidateSignUpProfile(txtAcctName, lblAccntNameId, txtAcctNo, lblAcctNo, txtUser, lblUser, txtPWord, lblPWord, txtRetype, lblRetype, txtAnswerId, lblAnswerId, ddlSecQuest, lblSecQuest, txtFNid, lblFNid, txtMNid, lblMNid, txtLNid, lblLNid, txtDesignateId, lblDesignateId, txtPhoneId, lblPhoneId, txtMobileId, lblMobileId, txtEmailId, lblEmailId, txtBDate, lblBDate, txtMMNameId, lblMMNameId, appStage)
{
    var AcctProfileError = 0;
    var LoginProfileError = 0;
    var UserProfileError = 0;
    
    AcctProfileError = ValidateAccountProfile(txtAcctName, lblAccntNameId, txtAcctNo, lblAcctNo)
    LoginProfileError = ValidateLoginProfile(txtUser, lblUser, txtPWord, lblPWord, txtRetype, lblRetype, txtAnswerId, lblAnswerId, ddlSecQuest, lblSecQuest, appStage)
    UserProfileError  = ValidateUserProfile(txtFNid, lblFNid, txtMNid, lblMNid, txtLNid, lblLNid, txtDesignateId, lblDesignateId, txtPhoneId, lblPhoneId, txtMobileId, lblMobileId, txtEmailId, lblEmailId, txtBDate, lblBDate, txtMMNameId, lblMMNameId, appStage)
   
    if (AcctProfileError > 0 || LoginProfileError > 0 || UserProfileError > 0)
    {
        return (false);
    }
    else
    {
        if (AcctProfileError == 0 && LoginProfileError == 0 && UserProfileError == 0)
        {
            return (true);
        }
    }
    
}

//Validates user input for account profile
function ValidateAccountProfile(txtAcctName, lblAccntNameId, txtAcctNo, lblAcctNo)
{
    var tempAcctNameStr = trimString(document.getElementById(txtAcctName).value);
    var tempAcctNoStr = trimString(document.getElementById(txtAcctNo).value);
    //var tempBillAddStr = trimString(document.getElementById(txtBillAdd).value);
    
    var errorcount = 0;
    
    //Account Name
    errorcount = errorcount + CheckIfBlank(tempAcctNameStr, lblAccntNameId, 'Please enter your account name.')
    //Account No
    errorcount = errorcount + BlankOrNotNumeric(tempAcctNoStr, lblAcctNo, 'Please enter your account number.', 'Please enter valid numeric value.')
    //Billing Address
    //errorcount = errorcount + CheckIfBlank(tempBillAddStr, lblBillAdd, 'Please enter your billing address.')
    
    return errorcount;
        
}

//Validates user input for login profile
function ValidateLoginProfile(txtUser, lblUser, txtPWord, lblPWord, txtRetype, lblRetype, txtAnswerId, lblAnswerId, ddlSecQuest, lblSecQuest, appStage)
{
    var tempAppStage = trimString(appStage);
    var tempUserStr = trimString(document.getElementById(txtUser).value);
    var tempPWordStr = trimString(document.getElementById(txtPWord).value);
    var tempRetypeStr = trimString(document.getElementById(txtRetype).value);
    var tempAnswerStr = trimString(document.getElementById(txtAnswerId).value);
    var userNameLength = tempUserStr.length;
    var userPWordLength = tempPWordStr.length;
    var ddlSecQuestIndex  = document.getElementById(ddlSecQuest).selectedIndex;
        
    var errorcount = 0;

    //User Name
    if (tempUserStr == "")
    {
        document.getElementById(lblUser).innerHTML = 'Please enter your username.';
        errorcount++;
    }
    else
    {
        if (userNameLength < 6 || userNameLength > 30)
        {
            document.getElementById(lblUser).innerHTML = 'Username must be 6 to 30 characters.';
            errorcount++;
        }
        else
        {
            document.getElementById(lblUser).innerHTML = '';
        }
    }
    //Password
    if (tempPWordStr == "")
    {
        document.getElementById(lblPWord).innerHTML = 'Please enter your password.';
        errorcount++;
    }
    else
    {
        if (userPWordLength < 8 || userPWordLength > 30)
        {
            document.getElementById(lblPWord).innerHTML = 'Password must be 8 to 30 characters.';
            errorcount++;
        }
        else
        {
            if (IsStrongPassword(tempPWordStr) == true)
            {
                document.getElementById(lblPWord).innerHTML = '';
            }
            else
            {
                document.getElementById(lblPWord).innerHTML = 'Please enter a strong password.Use numeric, alpha numeric and one of these special characters (|:;?!\/#@*%()+=-$^\'~`").';
                errorcount++;
            }
        }
    }
    
    //Retype Password
    if (tempRetypeStr == "")
    {
        document.getElementById(lblRetype).innerHTML = 'Please re-type your password.';
        errorcount++;
    }
    else
    {
        if (tempRetypeStr != tempPWordStr)
        {
            document.getElementById(lblRetype).innerHTML = 'Your password and re-typed password do not match.';
            errorcount++;
        }
        else
        {
            document.getElementById(lblRetype).innerHTML = '';
        }
    }
    
    //Answer
    errorcount = errorcount + CheckIfBlank(tempAnswerStr, lblAnswerId, 'Please enter your answer.')


    //Security Question ddlSecQuestIndex
    if (ddlSecQuestIndex == 0)
    {
        document.getElementById(lblSecQuest).innerHTML = 'Please choose a security question.';
        errorcount++;
    }
    else
    {
        document.getElementById(lblSecQuest).innerHTML = '';
    }    
    
    if (tempAppStage == "loginProfileUpdate")
    {
        if (errorcount > 0)
        {
            return (false);
        }
        else
        {
            return (true);
        }
    }
    else
    {
        if (tempAppStage == "userSignUp")
        {
            return errorcount;
        }
    }
    
}


//Validates user input for user profile
function ValidateUserProfile(txtFNid, lblFNid, txtMNid, lblMNid, txtLNid, lblLNid, txtDesignateId, lblDesignateId, txtPhoneId, lblPhoneId, txtMobileId, lblMobileId, txtEmailId, lblEmailId, txtBDate, lblBDate, txtMMNameId, lblMMNameId, appStage)
{
    var tempAppStage = trimString(appStage);
    var tempFNStr = trimString(document.getElementById(txtFNid).value);
    var tempMNStr = trimString(document.getElementById(txtMNid).value);
    var tempLNStr = trimString(document.getElementById(txtLNid).value);
    var tempDesignateStr = trimString(document.getElementById(txtDesignateId).value);
    var tempPhoneStr = trimString(document.getElementById(txtPhoneId).value);
    var tempMobileStr = trimString(document.getElementById(txtMobileId).value);
    var tempEmailStr = trimString(document.getElementById(txtEmailId).value);
    var tempBDateStr = trimString(document.getElementById(txtBDate).value);
    var tempMMNameStr = trimString(document.getElementById(txtMMNameId).value);
    var errorcount = 0;    

    //First Name
    //errorcount = errorcount + BlankOrInvalidEntry(tempFNStr, lblFNid, 'Please enter your first name.', 'Some of your input is not accepted.')
    //Middle Name
    //errorcount = errorcount + BlankOrInvalidEntry(tempMNStr, lblMNid, 'Please enter your middle name.', 'Some of your input is not accepted.')
    //Last Name
    //errorcount = errorcount + BlankOrInvalidEntry(tempLNStr, lblLNid, 'Please enter your last name.', 'Some of your input is not accepted.')
    //Designation
    //errorcount = errorcount + CheckIfBlank(tempDesignateStr, lblDesignateId, 'Please enter your designation.')
    //Phone Name
    //errorcount = errorcount + BlankOrNotValidContactNo(tempPhoneStr, lblPhoneId, 'Please enter your phone number.', 'Please enter a valid phone number.')
    //Mobile Name
    //errorcount = errorcount + CheckIfValidMobileNo(tempMobileStr, lblMobileId, 'Please enter your mobile number.', 'Please enter a valid mobile number.')
    
    //E-mail
    if (tempEmailStr == "")
    {
        document.getElementById(lblEmailId).innerHTML = 'Please enter your e-mail address.';
        errorcount++;
    }
    else
    {
        if (CheckEmailAddChars(tempEmailStr) == false)
        {
            document.getElementById(lblEmailId).innerHTML = 'Please enter a valid e-mail address.';
            errorcount++;
        }
        else
        {
            document.getElementById(lblEmailId).innerHTML = '';
        }
    }

    //Birthdate
//////    if (tempBDateStr == "")
//////    {
//////        document.getElementById(lblBDate).innerHTML = 'Please enter your birthday.';
//////        errorcount++;
//////    }
//////    else
//////    {
        if (len(tempBDateStr)>0)
        {
            document.getElementById(lblBDate).innerHTML = 'Please enter a valid date using the given format.';
            errorcount++;            
        }
        else
        {
            var d = new Date(tempBDateStr);
            var year = d.getFullYear();
            
            var currentDate = new Date();
            var currentYear = currentDate.getFullYear();
            
            if ((year < 1930) || (year > currentYear))
            {
                document.getElementById(lblBDate).innerHTML = 'Please enter a year between 1930 up to ' + currentYear + '.';
                errorcount++;
            }
            else
            {
                if (d > currentDate)
                {
                    document.getElementById(lblBDate).innerHTML = 'Please enter a valid date of birth.';
                    errorcount++;
                }
                else
                {
                    document.getElementById(lblBDate).innerHTML = '';
                }
            }
        }
//////    }

    //Mother's Maiden Name
//    errorcount = errorcount + CheckMothersMaidenName(tempMMNameStr, lblMMNameId, 'Please enter your mother\'s maiden name.', 'Some of your input is not accepted.')

    if (tempAppStage == "userProfileUpdate")
    {
        if (errorcount > 0)
        {
            return (false);
        }
        else
        {
            return (true);
        }
    }
    else
    {
        if (tempAppStage == "userSignUp")
        {
            return errorcount;
        }    
    }
    
    
}

//removes leading and trailing spaces from a string
function trimString(str) 
{
    while (str.charAt(0) == ' ')
        str = str.substring(1);
    while (str.charAt(str.length - 1) == ' ')
        str = str.substring(0, str.length - 1);
    return str;
}

function CheckIfAlphaCharacters(sText)
{
   var ValidChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz., ";
   var Char;

   var IsAlphaCharacters=true;

   for (i = 0; i < sText.length && IsAlphaCharacters == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsAlphaCharacters = false;
         }
      }

   return IsAlphaCharacters;
}

function CheckIfValidNumeric(sText)
{
   var ValidChars = "0123456789, ";
   var Char;

   var IsNumeric=true;

   for (i = 0; i < sText.length && IsNumeric == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumeric = false;
         }
      }

   return IsNumeric;   
}

function CheckIfValidContactNoChar(sText)
{
   var ValidChars = "0123456789+()-, ";
   var Char;

   var IsNumeric=true;

   for (i = 0; i < sText.length && IsNumeric == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumeric = false;
         }
      }

   return IsNumeric;   
}

function CheckIfBlank(tempStr, lblValue, blankErrorMsg)
{
    var errorcount = 0;
    
    if (tempStr == "")
    {
        document.getElementById(lblValue).innerHTML = blankErrorMsg;
        errorcount++;
    }
    else
    {
        document.getElementById(lblValue).innerHTML = '';
    }
    return errorcount;   
}


function BlankOrInvalidEntry(tempStr, lblValue, blankErrorMsg, invalidEntryMsg)
{
    var errorcount = 0;
    
    if (tempStr == "")
    {
        document.getElementById(lblValue).innerHTML = blankErrorMsg;
        errorcount++;
    }
    else
    {
        if (CheckIfAlphaCharacters(tempStr) == false)
        {
            document.getElementById(lblValue).innerHTML = invalidEntryMsg;
            errorcount++;
        }
        else
        {
            document.getElementById(lblValue).innerHTML = '';
        }
    }
    return errorcount;   
}

function CheckMothersMaidenName(tempStr, lblValue, blankErrorMsg, invalidEntryMsg)
{
    var errorcount = 0;
    
    if ((tempStr == "") || (tempStr == "na"))
    {
        document.getElementById(lblValue).innerHTML = blankErrorMsg;
        errorcount++;
    }
    else
    {
        if (CheckIfAlphaCharacters(tempStr) == false)
        {
            document.getElementById(lblValue).innerHTML = invalidEntryMsg;
            errorcount++;
        }
        else
        {
            document.getElementById(lblValue).innerHTML = '';
        }
    }
    return errorcount;   
}

function BlankOrNotNumeric(tempStr, lblValue, blankErrorMsg, invalidEntryMsg)
{
    var errorcount = 0;
    
    if (tempStr == "")
    {
        document.getElementById(lblValue).innerHTML = blankErrorMsg;
        errorcount++;
    }
    else
    {
        if (CheckIfValidNumeric(tempStr) == false)
        {
            document.getElementById(lblValue).innerHTML = invalidEntryMsg;
            errorcount++;
        }
        else
        {
            document.getElementById(lblValue).innerHTML = '';
        }
    }
    return errorcount;
}

function BlankOrNotValidContactNo(tempStr, lblValue, blankErrorMsg, invalidEntryMsg)
{
    var errorcount = 0;
    
    if (tempStr == "")
    {
        document.getElementById(lblValue).innerHTML = blankErrorMsg;
        errorcount++;
    }
    else
    {
        if (CheckIfValidContactNoChar(tempStr) == false)
        {
            document.getElementById(lblValue).innerHTML = invalidEntryMsg;
            errorcount++;
        }
        else
        {
            document.getElementById(lblValue).innerHTML = '';
        }
    }
    return errorcount;
}

function CheckIfValidMobileNo(tempStr, lblValue, blankErrorMsg, invalidEntryMsg)
{
    var errorcount = 0;
    
    if ((tempStr == "") || (tempStr == "na"))
    {
        document.getElementById(lblValue).innerHTML = '';
    }
    else
    {
        if (CheckIfValidContactNoChar(tempStr) == false)
        {
            document.getElementById(lblValue).innerHTML = invalidEntryMsg;
            errorcount++;
        }
        else
        {
            document.getElementById(lblValue).innerHTML = '';
        }
    }
    return errorcount;
}

function IsStrongPassword(sText)
{
    
    var Specialchar = "|:;?!\/#@*%()+=-$^'~`\"";
    var ValidNumeric = "0123456789";
    var ValidAlphaNumeric = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
    
    var countSpecialChar = 0;
    var countValidNumeric = 0;
    var countValidAlphaNumeric = 0;
    
    var Char;
    
    for (i = 0; i < sText.length; i++)
    {
        Char = sText.charAt(i); 
        if (Specialchar.indexOf(Char) != -1) 
        {
            countSpecialChar++;
        }
    }
    
    for (j = 0; j < sText.length; j++)
    {
        Char = sText.charAt(j); 
        if (ValidNumeric.indexOf(Char) != -1) 
        {
            countValidNumeric++;
        }
    }

    for (k = 0; k < sText.length; k++)
    {
        Char = sText.charAt(k); 
        if (ValidAlphaNumeric.indexOf(Char) != -1) 
        {
            countValidAlphaNumeric++;
        }
    }    
    
      
    if (countSpecialChar > 0 && countValidNumeric > 0 && countValidAlphaNumeric > 0)
    {
        return (true);
    }
    else
    {
        return (false);
    }
    
    
}

function CheckEmailAddChars(sText)
{
    pattern = /^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/; //checking e mail format.
    if (pattern.test(sText) == false)
    {
        return (false);
    }
    else
    {
        return (true);
    }
}

function CheckIfValidDateFormat(sText)
{
    pattern = /^([0][1-9]|[1][0-2])([/])([0][1-9]|1[0-9]|2[0-9]|3[0-1])[/]([1-2][0-9][0-9][0-9])$/; //checking date format.
    if (pattern.test(sText) == false)
    {
        return (false);
    }
    else
    {
        return (true);
    } 
}


