
function checkTyped(x,type) {
        var character;
        var keypressed;

        if (window.event)
           keypressed = window.event.keyCode;
        else if (x)
           keypressed = x.which;
        else
           return true;

        //get character from keycode
        character = String.fromCharCode(keypressed);

        //testing
        //alert('you pressed' +keypressed);


        // check for 13(enter),9(tab),27(escape)
        if ((keypressed==13) || (keypressed==27) || (keypressed==27) || (keypressed==8) || (keypressed==0) ) {
                return true
        }
        switch (type){
                case 'integer': {
                        if ( (("0123456789").indexOf(character) > -1) ) {
                        return true;
                        }
                        break;
                }
        }

        // if we got here then return false
   	return false;
}

function checkLength(x,length, fieldname) {
        // x=event
        // length is amx length of field
        // fieldname = document.form.field

//      alert("length " +fieldname.value.length +" and x=" +length);

        if (fieldname.value.length > length-2) {
                return false;
        }
        else {
                return true;
        }

}
var isNN = (navigator.appName.indexOf("Netscape")!=-1);
// call this function like this   onKeyUp="return moveNext(this, 3, event);"
function moveNext(input,len, e) {
        var keyCode = (isNN) ? e.which : e.keyCode;
        var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
        if (input.value.length >= len && !containElement(filter,keyCode)) {
                input.value = input.value.slice(0, len);
                input.form[(getIndex(input)+1) % input.form.length].focus();
        }

        function containElement(arr, ele) {
                var found = false, index = 0;
                while(!found && index < arr.length)
                if(arr[index] == ele)
                        found = true;
                else
                        index++;
                return found;
        }

        function getIndex(input) {
                var index = -1, i = 0, found = false;
                while (i < input.form.length && index == -1)
                if (input.form[i] == input) index = i;
                else i++;
                return index;
        }

        return true;
}

function validate_data() 
{	
	if (document.FORM1.adstring2)
	{
		if (document.FORM1.adstring2.value.length < 1)
		{
		      	alertuser(document.FORM1.adstring2, "Please enter your password.");
		      	return false;
		}
	}
	
	if (document.FORM1.heard)
	{
		if (document.FORM1.heard.value.length < 2)
		{
		      	alertuser(document.FORM1.heard, "Please tell us where you saw the link for our game.");
		      	return false;
		}
		
		if (document.FORM1.heard.value == "other")
		{
			if (document.FORM1.other)
			{
				if (document.FORM1.other.value.length < 2)
				{
					alertuser(document.FORM1.other, "Please tell us where you saw the link for our game.");
		      		return false;
		      	}
		    }
		}
	}

	if (document.FORM1.prev_button)
	{
		if (!document.FORM1.prev_button[0].checked && !document.FORM1.prev_button[1].checked)
		{
			alertuser(document.FORM1.prev_button[0], "Please indicate whether you've played with us before");
			return false;
		}
	}

	if (document.FORM1.prev_button[1].checked)
	{
	    if (document.FORM1.customer_id.value.length < 1) 
	    {
	      	alertuser(document.FORM1.customer_id, "You must enter a value for User Id.");
	      	return false;
	    }

	    if (document.FORM1.password.value.length < 1)
	    {
	      	alertuser(document.FORM1.password, "You must enter a value for password.");
	      	return false;
	    }
	}
	return true;
}
function alertuser(field,msg) 
{
        alert(msg);
        field.focus();
}

function change_radio(passvar)
{
	if (document.FORM1.prev_button)
	{
		self.document.FORM1.prev_button[passvar].checked = 1
	}
}

function checkOther()
{
	if(self.document.layers)
	{
		if (self.document.FORM1.heard.value == "other")
		{	
			document.other.visibility="visible";
			self.document.FORM1.other.focus();
		}
		else 
		{	
			document.other.visibility="hidden";
		}
			
	}
		
	if(self.document.layers)
	{
		if (self.document.FORM1.heard.value == "other")
		{	
			document.all.other.style.visibility="visible";
			self.document.FORM1.other.focus();
		}
		else
		{
			document.all.other.style.visibility="hidden";
		}		
	}
	if(self.document.getElementById)
	{
		if (self.document.FORM1.heard.value == "other")
		{	
			document.getElementById("other").style.visibility="visible";
			self.document.FORM1.other.focus();			
		}
		else
		{
			document.getElementById("other").style.visibility="hidden";
		}
	}
}

function getmyPassword() 
{
	popupWin = ""
window.open('http://www.cdmsports.com/forgot_password.php','forgotpasswd','status=yes,scrollbars=yes,resizable=yes,width=500,height=400')
}
function popRefund() 
{
        popupWin = window.open('/adpopups/refund.html','forgotpasswd','status=yes,scrollbars=yes,resizable=yes,width=500,height=400')
}
function popHRRefund() 
{
        popupWin = window.open('/adpopups/hr_refund.html','forgotpasswd','status=yes,scrollbars=yes,resizable=yes,width=500,height=400')
}
