
var newwin = null;

function openW(x,y){

	var prm ='toolbar=no,titlebar=no,directories=no,menubar=no,resizable=yes,scrollbars=yes,width=700,height=400,top=30,left=30';
	if ((y==null)||(y=='')) {
	  newwin = window.open('/PAX/'+x,y,prm); 
	}
	else {
		if((newwin==null) ||(newwin.closed)) { 
			newwin = window.open('/PAX/'+x,y,prm); 
		} else {
			newwin.document.write("Page loading.Please waiting...");
			newwin.location = '/PAX/'+x;
		}
	}  
	newwin.focus();
}

function uk(obj) {
	if (window.event.keyCode==8 || window.event.keyCode==46) 
	return;
        if (obj.value.length==2)
	        obj.value+="/";
        else if (obj.value.length==5)
		    obj.value+="/";
}

function ukAyGun(obj) {
	if (window.event.keyCode==8 || window.event.keyCode==46) 
		return;
    if (obj.value.length==2)
	    obj.value+="/";
    else if (obj.value.length==5)
	   return;
}

function dk(obj) {
	if ((window.event.keyCode < 48 || window.event.keyCode > 57) && (window.event.keyCode != 8 && window.event.keyCode !=46)){
		return false;
	}
	
}

function checkFormat(obj){
	var val=obj.value.split("/");
	if(obj.value.length==0)
		return true;
	else{
		if(val.length<3)
		{
			alert("Date format invalid!")
			obj.focus();
			return false;
		}
		if(val[0]>"31" || val[1]>"12")
		{
			alert("Date format invalid!")
			obj.focus();
			return false;
		}
	}
}
	

function checkAll() {
		for (var i = 0; i < document.form1.elements.length; i++) {
			if(document.form1.elements[i].style.type== "r")			{
				if(document.form1.elements[i].value == "")				{
					alert(document.form1.elements[i].name.substr(2)+' field is empty...Please check...');
					document.form1.elements[i].focus();
					return false;
				}
			} else if(document.form1.elements[i].style.type== "email") {
					var val = document.form1.elements[i].value;
					if ((val == "")||(val.indexOf('@')<1)||(val.indexOf('@')==val.length-1)||(val.indexOf('.')<1)||(val.indexOf('.')==val.length-1))  {
						alert('Email is invalid. Please check it..');
						document.form1.elements[i].focus();
						return false;
					}
				}
			
		}
		return true;
}




function Only_Numeric(e) {
  alert("In function");
	var whichCode = (window.Event) ? e.which : e.keyCode;
  alert(whichCode);
	if (whichCode == 13) return true;  // Enter
	if (whichCode == 47) return true;  // Slash
	if (whichCode > 57 ){
	return false;}
	if (whichCode < 48 && whichCode > 13){
	return false;}
}


function OnEnterSubmit(e) {	
	var whichCode = (window.Event) ? e.which : e.keyCode;
	if (whichCode == 13) // Enter
		document.forms["form1"].elements["Search"].click();
}

function findOpener(openerWindow) {
	var myOpener = openerWindow;
	var found = myOpener.universite;
	 if (found == null) {
		 myOpener = openerWindow.opener;
	 }
	 return myOpener;
} 





function onKeyDown() {
    if ( ((event.keyCode == 8) && 
    	 (event.srcElement.type != "text" &&
    	    event.srcElement.type != "textarea" &&
    	 	event.srcElement.type != "password")) || 
    	 ((event.ctrlKey) && ((event.keyCode == 78) || (event.keyCode == 82)) ) ||
    	 (event.keyCode == 116) ) {
				 event.keyCode = 0;
		         event.returnValue = false;
         }
}





function NoktaKoy(str)  {
	var tempstr,newstr;
		tempstr=str;
		newstr="";
		
		while (tempstr.length>3)
		{
			newstr="."+tempstr.substr(tempstr.length-3)+newstr; 
			tempstr=tempstr.substr(0,tempstr.length-3);
		}	
	return tempstr+newstr;
}
 
function textCounter(maxlimit) {
	field = event.srcElement;
	if (field.value.length > maxlimit) { // if too long...trim it!
		field.value = field.value.substring(0, maxlimit);
		alert('Maximum '+maxlimit + ' characters are allowed.')
	}
}

function getRadioButtonIndex(rb) {
	// single button group check
	if (rb.checked) return 0;

	// multiple button group check
	len = rb.length;
	for (var i=0; i<len; i++) {
		if (rb[i].checked) return i;
	}

	// if here no button is checked
	return  -1;
}

function getRadioButtonValue(rb) {
	// single button group check
	if (rb.checked) return rb.value;

	// multiple button group check
	len = rb.length;
	for (var i=0; i<len; i++) {
		if (rb[i].checked) return rb[i].value;
	}

	// if here no button is checked
	return  '';
}


function isNumeric(str) {
	len = str.length;
	for (var i=0; i<len; i++) {
		if ((str.charAt(i) < '0') || (str.charAt(i) > '9'))
			return false;
	}
	return true;
}


function blockEnglish(e)
{
	var key;
	var keychar;
	if(window.event) {
		key = e.keyCode; 
	}
	else if(e.which) {
		key = e.which; 
	}
	else {
		return true;
	}
	keychar = String.fromCharCode(key);
  if ((keychar>='A' && keychar<='Z')||(keychar>='a' && keychar<='z') ){
   return false;
  }
}
function onlyEnglish(e)
{
	var key;
	if(window.event) {
		key = e.keyCode; 
	}
	else if(e.which) {
		key = e.which; 
	}
	else {
		return true;
	}
  
  if (key>397 ){
   return false;
  }
}

function isPOBoxMandatory(country)
{
	if (country=="QA")return true;
	if (country=="AE")return true;
	return false;
}

function isZipCodeMandatory(country)
{
	if (country=="DE")return true;// Germany
	if (country=="CH")return true;// Switzerland
	if (country=="FR")return true;// France
	if (country=="IT")return true;// Italy
	if (country=="NL")return true;// Netherlands
	if (country=="PT")return true;// Portugal
	if (country=="DK")return true;// Denmark
	if (country=="US")return true;// United States
	if (country=="NO")return true;// Norway
	if (country=="SE")return true;// Sweden
	if (country=="GR")return true;// Greece
	if (country=="ZA")return true;// South Africa
	if (country=="AT")return true;// Austria
	if (country=="CA")return true;// Canada
	if (country=="HU")return true;// Hungary
	if (country=="GB")return true;// United Kingdom
  
	return false;
  
}

function isGCCCountry(country)
{
	if (country=="SA")return true;//Saudi Arabia
	if (country=="QA")return true;//Qatar
	if (country=="KW")return true;//Kuwait
	if (country=="OM")return true;//Oman
	if (country=="BH")return true;//Bahrain
	if (country=="AE")return true;//United Arab Emirates
	return false;
}

function isAreaCodeMandatory(country) 
{ 
  if ((country=="DZ") || (country=="213"))return false;//Algeria
  if ((country=="BH") || (country=="973"))return false;//Bahrain
  if ((country=="CR") || (country=="506"))return false;//Costa Rica
  if ((country=="CU") || (country=="53"))return false;//Cuba
  if ((country=="DJ") || (country=="253"))return false;//Djibouti
  if ((country=="KW") || (country=="965"))return false;//Kuwait
  if ((country=="LU") || (country=="352"))return false;//Luxemburg
  if ((country=="MT") || (country=="356"))return false;//Malta
  if ((country=="OM") || (country=="968"))return false;//Oman
  if ((country=="PY") || (country=="595"))return false;//Paraguay
  if ((country=="QA") || (country=="974"))return false;//Qatar
  if ((country=="SN") || (country=="221"))return false;//Senegal
  if ((country=="SG") || (country=="65"))return false;//Singapore
  return true;
}
  
function isStateMandatory(country) 
{ 
  if (country=="US")return true;//USA
  if (country=="CA")return true;//Canada
  if (country=="AU")return true;//Australia
  return false;
}

function disableCopy(event) {
     if ( (event.button == 2)) { // no right button
      alert("Please type the e-mail address instead of copying and pasting!");
      event.returnValue = false;
    }
}

var DAY_IN_MS = 1000 * 60 * 60 * 24;
function dayDifference(d1, d2) {
  var diff = d1.getTime() - d2.getTime();
  var dMod = Math.floor(diff / DAY_IN_MS); // somehow, the modulus (%) operator does not operate correctly... 
  return dMod;
}

function numOnly(e) {
	/*
	var key;
	var keychar;
	if(window.event) {
		key = e.keyCode; 
	}
	else if(e.which) {
		key = e.which; 
	}
	else {
		return true;
	}
	keychar = String.fromCharCode(key);
  if ( !(keychar>='0' && keychar<='9') ) {
   return false;
  }
  */

	// var charCode = (e.which) ? e.which : e.keyCode
	var charCode = (e.which != undefined) ? e.which : e.keyCode;
	if (charCode > 31 && (charCode < 48 || charCode > 57))
		return false;
	return true;

}

function isValidEmail(email) {
    if (email.length==0) {  
       return false;
    }
    if (! allValidChars(email)) {  // check to make sure all characters are valid
        return false;
    }
    if (email.indexOf("@") < 1) { //  must contain @, and it must not be the first character
        return false;
    } else if (email.lastIndexOf(".") <= email.indexOf("@")) {  // last dot must be after the @
        return false;
    } else if (email.lastIndexOf("@") == email.length-1) {  // @ must not be the last character
        return false;
    } else if (email.indexOf("..") >=0) { // two periods in a row is not valid
	return false;
    } else if (email.lastIndexOf(".") == email.length-1) {  // . must not be the last character
	return false;
    } else if (email.indexOf("@") != email.lastIndexOf("@")) { // there must be only one @
  return false;
    }
    return true;
}

// AA 13.04.2006
function isValidName(name) {
    if (name.length==0) {  
       return false;
    }
    if (invalidChars(name)) {  // check to make sure all characters are valid
        return false;
    }
    return true;
}

function allValidChars(email) {
  var parsed = true;
  var validchars = "abcdefghijklmnopqrstuvwxyz0123456789@.-_";
  for (var i=0; i < email.length; i++) {
    var letter = email.charAt(i).toLowerCase();
    if (validchars.indexOf(letter) != -1)
      continue;
    parsed = false;
    break;
  }
  return parsed;
}

function invalidChars(name) {
  // Returns true if an invalid character is found in a name.
  var parsed = false;
  var invalid = "!^+%&/()=?;#${}[]*@,";
  for (var i=0; i < name.length; i++) {
    var letter = name.charAt(i);
    if (invalid.indexOf(letter) >= 0){
      parsed = true;
      break;
    }  
  }
  return parsed;
}

function isEmpty(str) { 
    return (str.value == "");
}
function isChar(ev){
  if (!ev) var ev=window.event;
  if (ev.ctrlKey) {
   return false;
  }
  var kc;
  if (ev.keyCode) {kc=ev.keyCode;}
  if (ev.which) {kc=ev.which;}
  if (kc == 37 || kc == 39 || kc == 46 || kc == 8 || kc ==9){
   return true;
  }
  if (kc <63 || kc>128){
   return false;
  }
  return true;
}


var warningAlert = {
	init: function() {
		//$("#WarningAlert").css("display", "block"); //
		if ($("#WarningAlert").is(':visible')) {
			$("#WarningAlert").fadeOut("fast");
		}
		$("#WarningAlert").fadeIn("slow");
		// commented out to make error message visible
		// window.parent.scroll(0,500);
	}
}

function alert(msg){
	warningAlert.init();
	if($("#errorMessage")) {
		$("#errorMessage").hide();
	}
    $("#warningMessage").html(msg);
}

//Used in autoscrolling of the iframe on load
function getPosition(who){
    var T= 0,L= 0;
    while(who){
        L+= who.offsetLeft;
        T+= who.offsetTop;
        who= who.offsetParent;
    }
    return T;    
}


