// GLOBAL REQUEST HEADER PAGE

function req_header () {
	
http_request = false;
		
        if (window.XMLHttpRequest) { // Mozilla, Safari,...
            http_request = new XMLHttpRequest();
            if (http_request.overrideMimeType) {
                //http_request.overrideMimeType('text/xml');
				;
                // See note below about this line
            }
        } else if (window.ActiveXObject) { // IE
            try {
                http_request = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    http_request = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {}
            }
        }
        if (!http_request) {
            alert('Giving up :( Cannot create an XMLHTTP instance )');
            return false;
        }else {
		
		return http_request;
		}


}

function chkLogin() {
	email_header = false;	
	email_header = req_header();
	var email = document.getElementById('telno').value;
	
	document.getElementById('m').innerHTML= 'Verifying.....';
	email_header.onreadystatechange = email_return;	
	email_header.open('GET','chklogin_ajx.php?email=' + email + '',true);
	email_header.send(null);
}
function email_return() {
	if (email_header.readyState==4){
		if (email_header.status==200){
//			var EmailCheck = document.getElementById('EmailCheck');
			var email_return_text = email_header.responseText;	
//			alert(email_return_text);
//			EmailCheck.innerHTML = email_return_text;
			if (email_return_text >= 1) {				
				//alert ('The Username you selected is already registerd , Please Select Another');
				bkColor = '#990000';
				fntColor = '#FFFF00';
//				alert(bkColor);
				document.getElementById('telno').style.background = bkColor;
				document.getElementById('telno').style.color=fntColor;			
				document.getElementById('m').innerHTML='The request of the phone number entered is already in process';
				document.getElementById('m').style.color=bkColor;			
				document.getElementById('telno').focus();
			}
			else {
				Reset();
				document.getElementById('m').innerHTML= '';				
				
				}
		}	
	}	
}


function Reset() {
		bkColor1 = '#49394E';
		fntColor1 = '#FFFFFF';	
		document.getElementById('telno').style.background = fntColor1;
		document.getElementById('telno').style.color = bkColor1;
		document.getElementById('m').innerHTML= '';
		document.getElementById('m').style.background = fntColor1;		

}





function validate_required(field,alerttxt)
	{
		with (field)
			{
				if (value==null||value=="")
					  {alert(alerttxt);return false}
				else {return true}
			}
}

function fieldlength(field,maximum) {
//	alert(field.length);
	if (field.length > maximum) {
		return false;
		} else {
			return true;			
			}

}

function ChkOption (field) {
//	alert(field.name);
	field_name = field.name;
	v = field.value;
	var j =v.charAt(0);
	
	if (isNumber(j) == true) {		
//		alert('First Number is numeric');
		field_name = field_name+'m';
		fmsg = document.getElementById(field_name);
//		alert(field_name);
		fmsg.innerHTML='First character must not be numeric.';
	} else {
		field_name = field_name+'m';
		fmsg = document.getElementById(field_name);		
		fmsg.innerHTML='';
		}
}

//Check in character is number or string
function isNumber (InString)  { 
    if(InString.length==0) return (false); 
    var RefString="1234567890"; 
    for (Count=0; Count < InString.length; Count++)  { 
        TempChar= InString.substring (Count, Count+1); 
        if (RefString.indexOf (TempChar, 0)==-1)   
            return (false); 
    } 
    return (true); 
} 

function FirstChar (field) {
	var ch = field.value;
		ch = ch.charAt(0);
		if (isNumber(ch)) { 
			ShowError(field,'First character must not be numeric');
			return(false) 
		} else {
			ResetError(field);
			return (true);
		}
	}
	
function ShowError (field,Error) {
	var	bkColor = '#990000';
	var	fntColor = '#FFFF00';	
	var FieldName = field.name;
	var MsgFieldName = field.name+'m';
	var Field = document.getElementById(FieldName);
	var MsgField = document.getElementById(MsgFieldName);
	
	Field.style.background = bkColor;
	Field.style.color = fntColor;
	MsgField.innerHTML   = '';
	MsgField.innerHTML   =  Error;
	MsgField.style.color   = bkColor;
	
	}
	
function ResetError (field) {
	var	bkColor = '#FFFFFF';
	var	fntColor = '#000000';	
	var FieldName = field.name;
	var MsgFieldName = field.name+'m';
	var Field = document.getElementById(FieldName);
	var MsgField = document.getElementById(MsgFieldName);
	
	Field.style.background = bkColor;
	Field.style.color = fntColor;
	MsgField.innerHTML   = '';
	MsgField.style.color   = fntColor;
	
	
	
	
	
	}
	
	
	
function validate_dob (field) {
	if(field.value.length == 4) {
//		alert(field.value);
		field.value = field.value + "-";
	}
	if(field.value.length == 7) {
//		alert(field.value);
		field.value = field.value + "-";
	}

}

function checkIt(evt) {
    evt = (evt) ? evt : window.event
    var charCode = (evt.which) ? evt.which : evt.keyCode
    if (charCode > 31 && (charCode < 48 || charCode > 57)) {
        status = "This field accepts numbers only."
        return false
    }
    status = ""
    return true
}

function checkItChar(evt) {
    evt = (evt) ? evt : window.event
    var charCode = (evt.which) ? evt.which : evt.keyCode
	alert(charCode);
    if ((charCode < 65 || charCode > 90) || (charCode < 97 || charCode > 122)) {
        status = "This field accepts characters only."
        return false
    }
    status = ""
    return true
}


function AllowOnlyNumeric()
{
    // Get the ASCII value of the key that the user entered
    var key = window.event.keyCode;

    // Verify if the key entered was a numeric character (0-9) or a decimal (.)
//    if ( (key > 47 && key < 58) || key == 46 || key == 95 || key == 45 || (key > 96 && key < 123))
    if ( (key > 47 && key < 58) || key == 46 || key == 95 || key == 45 || key == 13 )
        // If it was, then allow the entry to continue
        return;
    else
        // If it was not, then dispose the key and continue with entry
        window.event.returnValue = null; 
}

function AllowOnlyChar()
{
    // Get the ASCII value of the key that the user entered
    var key = window.event.keyCode;

    // Verify if the key entered was a numeric character (0-9) or a decimal (.)
//    if ( (key > 47 && key < 58) || key == 46 || key == 95 || key == 45 || (key > 96 && key < 123))
    if ( (key > 64 && key < 91) || (key > 96 && key < 123) || key == 13 )
        // If it was, then allow the entry to continue
        return;
    else
        // If it was not, then dispose the key and continue with entry
        window.event.returnValue = null; 
}

function InsertCode (city) {
//	alert(city);
	var codeField = document.getElementById('brdph1');
//		alert(codeField.value);

	var code = city.split(":");
		code = code[1];
		codeField.value="";
		codeField.value =code;


}

function InsertCodeEdu (city) {
//	alert(city);
	var codeField = document.getElementById('uninumber1');
//		alert(codeField.value);

	var code = city.split(":");
		code = code[1];
		codeField.value="";
		codeField.value =code;


}

function OpenWindow(pic) {
	window.open(pic,'idcard');

}

function OpenWindow1(pic) {
	window.open('pkg.htm','packages',"menubar=0,resizable=0,width=600,height=250");

}