﻿// JScript File
/*
CheckTelNo method takes in current element of the form as input. This method should be 
fired as the user attempts to leave the current element in the form (by using onBlur method). 
It checks to see if the format of the phone is "(123) 456-7890".
Eg. <netui:textBox size="13" maxlength="13" onBlur="JavaScript:checkTelNo (this);" onKeyUp="JavaScript:formatTelNo (this);" onKeyDown="JavaScript:formatTelNo (this);"/>  
*/      
function checkTelNo (telNo)
{
    if (telNo.value == "") return;
    if (telNo.value.match (".[0-9]{3}.[0-9]{3}-[0-9]{4}") == null)
    {
        if (telNo.value.match ("[0-9]{10}") != null)
            formatTelNo (telNo)              
    }
}
/*
FormatTelNo method takes in the current element of the form and formats the phone number 
in "(123 456-7890" format. This method should be fired on every key entry 
(using onKeyUp method) in the current element of the form. If any key other than 0 to 9 
is entered, it erases that entry rightaway. Maxlength and size of the current
element of the form should be 13.
Eg. <netui:textBox size="13" maxlength="13" onKeyUp="JavaScript:formatTelNo (this);" onBlur="JavaScript:checkTelNo (this);" onKeyDown="JavaScript:formatTelNo (this);"/>    
*/
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 setFocus() {
	if(strFocusControlId != "") {
		var objControl	= document.getElementById(strFocusControlId);
		objControl.focus();
	}
}

function ConfirmDelete(title){
	if(confirm("You are about to delete the Selected "+ title +".\nYou will not be able to get back the details once deleted.\nDo you wish to continue?"))
	{
		return true;			
	}
	else
	{
		return false;
	}
	return false;
}
	
function ConfirmRemove(title){
	if(confirm("You are about to remove the Selected "+ title +".\nYou will not be able to get back the details once removed.\nDo you wish to continue?"))
	{
		return true;			
	}
	else
	{
		return false;
	}
	return false;
}
	
function CheckKeyCode(controlName,strValue)
    {		
        controlName.value = (strValue);

	    if (( event.keyCode < 48 || event.keyCode > 57 ) && (event.keyCode < 46  ||  event.keyCode  > 46) && (event.keyCode < 45  ||  event.keyCode  > 45 || event.keyCode  == 45) )
	    {
		    event.keyCode=0;
		    return false;
	    }
    }
    
function checkEmail(email)
{
	var str = email;
	var invalidCharactersRegExp = /[^a-z\d\@\_\.-]/i; 
	
	var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.^\!^\#)/; // not valid
	var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/; // valid
	
	if (!reg1.test(str) && reg2.test(str))
	{
		return true;
	}else
	{
		return false;
	}

if(!invalidCharactersRegExp.test(str)) 
	{
		return true;
	}
	else
	{
		return false;	
	}
}
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") )) 
		{
		//alert("please enter integer value");
		return false;
		}
    }
    return true;
}

function navigatePage(pageIndex) 
	{	
	    var frm	= document.aspnetForm;
	    document.getElementById("ctl00_AdminHeaderContentPlaceHolder_PageIndexHidden").value	= pageIndex;
	    document.getElementById("ctl00_AdminHeaderContentPlaceHolder_ActionHidden").value = "PAGINATION";
	    frm.submit();
    }

function navigateUserPage(pageIndex) 
	{	
	    var frm	= document.aspnetForm;
	    document.getElementById("ctl00$MainContent$PageIndexHidden").value	= pageIndex;
	    document.getElementById("ctl00$MainContent$ActionHidden").value = "PAGINATION";
	    frm.submit();
    }
     
function navigateAdminPage(pageIndex) 
	{
	    var frm	= document.aspnetForm;	
	    document.getElementById("PageIndexHidden").value	= pageIndex;
	    document.getElementById("ActionHidden").value = "PAGINATION";
	    frm.submit();
    }
    
    
function ShowHideTr(trId,trId1)
{
   var tr; 
   var tr1;
    tr  = document.getElementById(trId);
    tr1 = document.getElementById(trId1);
    
//   if(document.getElementById("MainTr").style.display=="none")
//        document.getElementById("MainTr").style.display = "";
//   else 
//        document.getElementById("MainTr").style.display = "none";
        
   if(tr.style.display=="none")
   {
     tr.style.display   = "";  
     tr1.style.display  = "none"; 
     return false;   
   } 
   else
   {
     tr.style.display   = "none";  
     tr1.style.display  = "none";    
     return false;
   }
     
}
