function IsNull(obj) //Null Validation
{
   var myString = obj
   var inThere = myString.match(/\S/g)
   if (inThere) 
	  return false //Invalid number
   return true //Valid Number
}
function IsNotNumber(iobj){ //Integer Validation
   var myString = iobj
   var inThere = myString.match(/\D/g)
   if (inThere) 
	  return true //Invalid number
   return false //Valid Number
}
function IsDate(dateStr) {
    var datePat = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/;
    var matchArray = dateStr.match(datePat); // is the format ok?
    var monthname=""
    if (matchArray == null) {
        alert("Please enter date as either mm/dd/yyyy.");
        return false;
    }

    month = matchArray[1]; // parse date into variables
    day = matchArray[3];
    year = matchArray[5];
	

    if (month < 1 || month > 12) { // check month range
        alert("Month must be between 1 and 12.");
        return false;
    }

    if (day < 1 || day > 31) {
        alert("Day must be between 1 and 31.");
        return false;
    }
	if (month == 2)monthname="February";
	else if (month == 4)monthname="April";
	else if (month == 6)monthname="June";
	else if (month == 9)monthname="September";
	else if (month == 11)monthname="November";

    if ((month==4 || month==6 || month==9 || month==11) && day==31) {
        alert(monthname+" doesn't have 31 days!")
        return false;
    }

    if (month == 2) { // check for february 29th
        var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
        if (day > 29 || (day==29 && !isleap)) {
            alert(monthname + " " + year + " doesn't have " + day + " days!");
            return false;
        }
    }
    return true; // date is valid
}

function IsPhone(eobj){//Phone Validation
   var str = eobj;
   str1=strreplace(str," ","")
   var res = str1.match(/^\([0-9]{1,3}\)[0-9]{3}-[0-9]{4}$/g)
   if (res)
	  return true //Valid Phone
   return false  //Invalid Phone
}
function IsEmail(ieobj){//Email Validation
   var estr = ieobj          
   var eres = estr.match(/^(\s)*[_a-z0-9A-Z-]+(\.[_a-z0-9A-Z-]+)*@[a-z0-9A-Z-]+(\.[a-z0-9A-Z-]+)+$/g)
   if (eres)
	  return true  //Valid Email
   return false  //Invalid Email
}

function opennewwindow(mypage,h,w,n,winname){
  if ((IsNull(h)) || (IsNull(w)) || (IsNull(n)) || (IsNotNumber(h)) || (IsNotNumber(w)) || ((n!="no")&&(n!="yes")))
     prpty=""
  else {
     locx = (screen.width - w)/2; 
     locy = (screen.height - h)/2; 
     prpty="status=yes,resizable=no,height="+h+",width="+w+",left="+locx+",top="+locy+",menubar=no,toolbar=no,scrollbars=" + n
  }
  if (IsNull(winname))
     wn = null
  else
     wn = winname
  if (!IsNull(mypage)){	 
	 mywin =  window.open(mypage,wn,prpty)
	 mywin.focus()
  }
}
function strreplace(string,text,by) {
// Replaces text with by in string
    var strLength = string.length, txtLength = text.length;
    if ((strLength == 0) || (txtLength == 0)) return string;

    var i = string.indexOf(text);
    if ((!i) && (text != string.substring(0,txtLength))) return string;
    if (i == -1) return string;

    var newstr = string.substring(0,i) + by;

    if (i+txtLength < strLength)
        newstr += strreplace(string.substring(i+txtLength,strLength),text,by);

    return newstr;
}

function PopupPic(sPicURL) {
      window.open( "popup.html?"+sPicURL, "Popup", 
      "resizable=1,HEIGHT=200,WIDTH=200");
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function validcout(tf){
	if (IsNull(tf.First_Name.value)){
		alert('"First Name" is required.');
		tf.First_Name.focus()
	    return false;	
	}
	if (IsNull(tf.Last_Name.value)){
		alert('"Last Name" is required.');
		tf.Last_Name.focus()
	    return false;	
	}
	if (IsNull(tf.Company.value)){
		alert('"Company" is required.');
		tf.Company.focus()
	    return false;	
	}
 	if (IsNull(tf.Position.value)){
		alert('"Position" is required.');
		tf.Position.focus()
	    return false;	
	}
 	if (IsNull(tf.City.value)){
		alert('"City" is required.');
		tf.City.focus()
	    return false;	
	}
 	if (IsNull(tf.Country[tf.Country.selectedIndex].value)){
		alert('"Country" is required.');
		tf.Country.focus()
	    return false;	
	} 
 	if (IsNull(tf.Phone.value)){
		alert('"Telephone No." is required.');
		tf.Phone.focus()
	    return false;	
	}
	if (IsNull(tf.Website.value)){
		alert('"URL" is required.');
		tf.Website.focus()
	    return false;	
	}
	if (IsNull(tf.Email_Address.value)){
		alert('"Email Address" is required.');
		tf.Email_Address.focus()
	    return false;	
	}
 	if (!IsEmail(tf.Email_Address.value)){
		alert('Invalid Email Address!');
		tf.Email_Address.focus()
	    return false;	
	}
	if (IsNull(tf.Request.value)){
		alert('"Request" is required.');
		tf.Request.focus()
	    return false;	
	} 
  tf.submit();
}

function wpop(cid){ 
	var y = 530;
	var x = 660;
	var locx = (screen.width - x)/2; 
	var locy = (screen.height - y)/2; 
	
	a= window.open ("apply.asp?cid="+cid,"job",'width='+x+',height='+y+',menubar=no,toolbars=no,status=yes,resizable=no,scrollbars=yes,left='+locx+',top='+locy);
	a.focus();
}
function PopupPic(sPicURL) {
      window.open( "popup.html?"+sPicURL, "Popup", 
      "resizable=1,HEIGHT=200,WIDTH=200");
}