/// <reference path="GMC_common.js" />
/* Set a cookie to be sure that one exists.
Note that this is outside the function */
var today = new Date();
//expire in 1 day time
today.setTime(today.getTime() + 1*60*60*1000*24);

var gCookie='killme=' + escape('nothing') + '; expires=' + today.toUTCString() + ';'
document.cookie=gCookie;

function cc(){
      
	/* check for a cookie */
	if (document.cookie == "") {
		/* if a cookie is not found - alert user - change cookieexists field value to false */
		alert('\tYour browser is blocking cookies.\n\nIn order to log into our site cookies needs to be enabled.\nPlease contact your network Administrator then try again.');
		/* If the user has Cookies disabled an alert will let him know that cookies need to be enabled to log on.*/ 
		document.getElementById("cookieexists").value ='false';
		document.getElementById(btnSubmitID).disabled=true;
	}else{
		/* this sets the value to true and nothing else will happen,the user will be able to log on*/
		document.getElementById("cookieexists").value = 'true';
		document.getElementById(btnSubmitID).disabled=false;
	}
}

//browser detection
var strUserAgent = navigator.userAgent.toLowerCase(); 
var isIE = strUserAgent.indexOf("msie") > -1; 
var isNS6 = strUserAgent.indexOf("netscape6") > -1; 
var isNS4 = !isIE && !isNS6  && parseFloat(navigator.appVersion) < 5; 

//regular expressions
var reValidChars =/[0-9a-zA-Z]/;
var reKeyboardChars = /[\x00\x03\x08\x0D\x16\x18\x1A]/;
var reClipboardChars = /[cvxz]/i;

//mask functions
function maskKeyPress(objEvent) {
	var iKeyCode, strKey, objInput;  
	
	if (isIE) {
		iKeyCode = objEvent.keyCode;
		objInput = objEvent.srcElement;
	} else {
		iKeyCode = objEvent.which;
		objInput = objEvent.target;
	}
	
	strKey = String.fromCharCode(iKeyCode);
	
	if (isValid(objInput.value)) {
		objInput.validValue = objInput.value;
		if (!reValidChars.test(strKey) && !reKeyboardChars.test(strKey) && !checkClipboardCode(objEvent, strKey)) {
			return false;
		}
	} else {
		objInput.value = objInput.validValue;
		return false;
	}
}

function checkClipboardCode(objEvent, strKey) {
	if (isNS6)
		return objEvent.ctrlKey && reClipboardChars.test(strKey);
	else
		return false;
}

function isValid(strValue) {
	return reValidChars.test(strValue) || strValue.length == 0;			
}

function maskChange(objEvent) {
	var objInput;

	if (isIE) {
		objInput = objEvent.srcElement; 
	} else {
		objInput = objEvent.target;
	}
	
	if (!isValid(objInput.value)) {
		alert("The password must be alphanumeric.");
		objInput.value = objInput.validValue || "";
		objInput.focus();
		objInput.select(); 
	} else {
		objInput.validValue = objInput.value;
	}
}

function maskPaste(objEvent) {
	var strPasteData = window.clipboardData.getData("Text");
	var objInput = objEvent.srcElement;
	
	if (!isValid(strPasteData)) {
		alert("The password must be alphanumeric.");
		objInput.focus();
		return false;
	}
}	
