
//Used for the displaying the strenght of the password field 
function testPassword(ctlPassword, ctlStrength)
{        
        var passwd = ctlPassword.value;
		var intScore   = 0;
		var strVerdict = "weak";
		var strLog     = "";
		var fontColor  = "black";
		
		if (passwd.length == 0)
		{   
		    //hide the strength box if there is no value in the new primary password textbox
		    ctlStrength.innerHTML = ""; 
		    return;
		}		
		else
		{
		    // PASSWORD LENGTH
		    if (passwd.length<5)                         // length 4 or less
		    {
			    intScore = (intScore+3)
			    strLog   = strLog + "3 points for length (" + passwd.length + ")\n"
		    }
		    else if (passwd.length>4 && passwd.length<8) // length between 5 and 7
		    {
			    intScore = (intScore+6)
			    strLog   = strLog + "6 points for length (" + passwd.length + ")\n"
		    }
		    else if (passwd.length>7 && passwd.length<16)// length between 8 and 15
		    {
			    intScore = (intScore+12)
			    strLog   = strLog + "12 points for length (" + passwd.length + ")\n"
		    }
		    else if (passwd.length>15)                    // length 16 or more
		    {
			    intScore = (intScore+18)
			    strLog   = strLog + "18 point for length (" + passwd.length + ")\n"
		    }
    		
    		
		    // 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)
			    strLog   = strLog + "1 point for at least one lower case char\n"
		    }
    		
		    if (passwd.match(/[A-Z]/))                              // [verified] at least one upper case letter
		    {
			    intScore = (intScore+5)
			    strLog   = strLog + "5 points for at least one upper case char\n"
		    }
    		
		    // NUMBERS
		    if (passwd.match(/\d+/))                                 // [verified] at least one number
		    {
			    intScore = (intScore+5)
			    strLog   = strLog + "5 points for at least one number\n"
		    }
    		
		    if (passwd.match(/(.*[0-9].*[0-9].*[0-9])/))             // [verified] at least three numbers
		    {
			    intScore = (intScore+5)
			    strLog   = strLog + "5 points for at least three numbers\n"
		    }
    		
    		
		    // SPECIAL CHAR
		    if (passwd.match(/.[!,@,#,$,%,^,&,*,?,_,~]/))            // [verified] at least one special character
		    {
			    intScore = (intScore+5)
			    strLog   = strLog + "5 points for at least one special char\n"
		    }
    		
									     // [verified] at least two special characters
		    if (passwd.match(/(.*[!,@,#,$,%,^,&,*,?,_,~].*[!,@,#,$,%,^,&,*,?,_,~])/))
		    {
			    intScore = (intScore+5)
			    strLog   = strLog + "5 points for at least two special chars\n"
		    }
    	
    		
		    // COMBOS
		    if (passwd.match(/([a-z].*[A-Z])|([A-Z].*[a-z])/))        // [verified] both upper and lower case
		    {
			    intScore = (intScore+2)
			    strLog   = strLog + "2 combo points for upper and lower letters\n"
		    }

		    if (passwd.match(/([a-zA-Z])/) && passwd.match(/([0-9])/)) // [verified] both letters and numbers
		    {
			    intScore = (intScore+2)
			    strLog   = strLog + "2 combo points for letters and numbers\n"
		    }
     
									    // [verified] letters, numbers, and special characters
		    if (passwd.match(/([a-zA-Z0-9].*[!,@,#,$,%,^,&,*,?,_,~])|([!,@,#,$,%,^,&,*,?,_,~].*[a-zA-Z0-9])/))
		    {
			    intScore = (intScore+2)
			    strLog   = strLog + "2 combo points for letters, numbers and special chars\n"
		    }
    	
	        var level = 0;
    	
		    if(intScore < 16)
		    {
		       level = 1;
		       fontColor = "red";
		       strVerdict = "Weak"
		    }
		    else if (intScore > 16 && intScore < 35)
		    {
		       level = 2;
		       fontColor = "orange";
		       strVerdict = "OK";
		    }
		    else 
		    {
		       level = 3;
		       fontColor = "green";
		       strVerdict = "Strong";
		    }
    		
            ctlStrength.style.color = fontColor;
            
            html = makeBoxes(level, fontColor, strVerdict)
            
            ctlStrength.innerHTML = html;
        }
}

function makeBoxes(level, color, descriptor) {
    var maxWidth = 250
    var html = "<div style='margin-top:2px; margin-bottom:2px;font-size:11px'>Password strength: " + descriptor;
    html += "<div style='padding:1px;border: inset 1px black;height:10px;width:" + maxWidth + "px'>"
       
    html += "<div style='height:8px; width:" + (level * maxWidth/3) + "px; background-color:" + color + "; color:black'>&nbsp;</div>"
    
    html += "</div></div>"
    
    return html
}

//Used for PleaseWaitButton
function GetDiv(sDiv)
{
	var div;
	if (document.getElementById)
		div = document.getElementById(sDiv);
	else if (document.all)
		div = eval("window." + sDiv);
	else if (document.layers)
		div = document.layers[sDiv];
	else
		div = null;

	return div;
}

function HideDiv(sDiv)
{
	d = GetDiv(sDiv);
	if (d)
	{
		if (document.layers) d.visibility = "hide";
		else d.style.visibility = "hidden";
	}
}

function PleaseWait(sDivButton, sDivMessage, sInnerHtml)
{
	HideDiv(sDivButton);
	var d = GetDiv(sDivMessage);
	if (d) d.innerHTML = sInnerHtml;
}

//To view and hide sections of a page
function View_Hide(DivName,lblName,ViewText,HideText)
{
    var divID = document.all(DivName);
    var lblId  = document.all(lblName);
    if (divID.style.display == "none") 
		{
			divID.style.display = "";
			lblId.innerHTML  = HideText;    
        }
    else
		{
			divID.style.display = "none";
			lblId.innerHTML  = ViewText;
		}
}

//Shows the comfirmation box
function ShowConfirm(Msg)
{
	window.event.returnValue = window.confirm(Msg,"yes");	
}

//Opens a window
function OpenAWindow(URL,WName)
{
	var Wleft = screen.width/2 - 350;
	var Wtop = screen.height/2-320;
	window.open(URL,WName,'scrollbars=yes,height=600,width=680,left='+Wleft+',top='+Wtop+'');
	
}

// Browser Detection Javascript
// copyright 1 February 2003, by Stephen Chapman, Felgall Pty Ltd

// You have permission to copy and use this javascript provided that
// the content of the script is not changed in any way.

function whichBrs() {
var agt=navigator.userAgent.toLowerCase();
if (agt.indexOf("opera") != -1) return 'Opera';
if (agt.indexOf("staroffice") != -1) return 'Star Office';
if (agt.indexOf("webtv") != -1) return 'WebTV';
if (agt.indexOf("beonex") != -1) return 'Beonex';
if (agt.indexOf("chimera") != -1) return 'Chimera';
if (agt.indexOf("netpositive") != -1) return 'NetPositive';
if (agt.indexOf("phoenix") != -1) return 'Phoenix';
if (agt.indexOf("firefox") != -1) return 'Firefox';
if (agt.indexOf("safari") != -1) return 'Safari';
if (agt.indexOf("skipstone") != -1) return 'SkipStone';
if (agt.indexOf("msie") != -1) return 'Internet Explorer';
if (agt.indexOf("netscape") != -1) return 'Netscape';
if (agt.indexOf("mozilla/5.0") != -1) return 'Mozilla';
if (agt.indexOf('\/') != -1) {
if (agt.substr(0,agt.indexOf('\/')) != 'mozilla') {
return navigator.userAgent.substr(0,agt.indexOf('\/'));}
else return 'Netscape';} else if (agt.indexOf(' ') != -1)
return navigator.userAgent.substr(0,agt.indexOf(' '));
else return navigator.userAgent;
}

function onlyNumerics(e, val)
        {
                    if (val == null) return 0;
                     var keynum;
                     var keychar;
                     var numcheck;
                     if(window.event) // IE
                     {
                      keynum = e.keyCode;
                     }
                     else if(e.which) // Netscape/Firefox/Opera
                     {
                      keynum = e.which;
                     }
                     if (keynum == null || keynum == 8 || keynum == 9 || keynum == 11)
                     {
                    	return true;
                     }
                     if (keynum==45)
                     {
                    	return false;
                     }
                     if (keynum==46 )
                     {
                    	return false; // only 1 period 
                     }
                     var maxLength = 0; 
                     if (val.indexOf('.')>-1)
                    	maxLength = 10;
                     else
                    	maxLength = 7;
                     if (val.length > maxLength) 
                     {	return false; }
                     numcheck = /^[\d.-]$/;
                     keychar = String.fromCharCode(keynum);
                     return numcheck.test(keychar);
                    }


function validateCreditCardNumber(sender,args) 
{

	var i, n, c, r, t,creditcardnumber;
	creditcardnumber=args.Value;
	

	if (creditcardnumber == "420000000000000") { // For Testing
	    args.valid=true;
	    return;
	}
	
	// First, reverse the string and remove any non-numeric characters.
	r = "";
	for (i = 0; i < creditcardnumber.length; i++)
	{
		c = parseInt(creditcardnumber.charAt(i), 10);
		if (c >= 0 && c <= 9)
		r = c + r;
	}
	// Check for a bad string.
    if (r.length <= 1)
	    args.valid=false;

    // Now run through each single digit to create a new string. Even digits
    // are multiplied by two, odd digits are left alone.

    t = "";
    for (i = 0; i < r.length; i++) 
    {
	    c = parseInt(r.charAt(i), 10);
	    if (i % 2 != 0)
	    c *= 2;
	    t = t + c;
    }

    // Finally, add up all the single digits in this string.

    n = 0;
    for (i = 0; i < t.length; i++)
     {
	    c = parseInt(t.charAt(i), 10);
	    n = n + c;
     }

    // If the resulting sum is an even multiple of ten (but not zero), the
    // card number is good.

    if (n != 0 && n % 10 == 0)
	    args.IsValid = true;
    else
	    args.IsValid = false;
}





