// JavaScript Document#

/////////////////////// Check login form //////////////////////////

function openScript(url,name, width, height){
	var Win = window.open(url,name,'width=' + width + ',height=' + height + ',resizable=1,scrollbars=yes,menubar=no,status=yes' );
}

function checkform1() {


	if (document.form1.email.value==""){
		alert("Please enter username!");
		document.form1.email.focus();
		return false;
	}
	if (document.form1.password.value==""){
		alert("Please enter password!");
		document.form1.password.focus();
		return false;
	}

	return true;
}





////////////////////////////  all pages top ///////////////////////////////


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];}
}


//////////////////////////////// Go Back Button ///////////////////////////////////////


function goback(){
history.back();
}


/////////////////////////////// Click Open Meun(Mailing page)  /////////////////////////////


NS4 = (document.layers) ? 1 : 0;
IE4 = (document.all) ? 1 : 0;
ver4 = (NS4 || IE4) ? 1 : 0;

if (ver4) {
    with (document) {
        write("<STYLE TYPE='text/css'>");
        if (NS4) {
            write(".parent {position:absolute; visibility:visible}");
            write(".child {position:absolute; visibility:visible}");
            write(".regular {position:absolute; visibility:visible}")
        }
        else {
            write(".child {display:none}")
        }
        write("</STYLE>");
    }
}

function getIndex(el) {
    ind = null;
    for (i=0; i<document.layers.length; i++) {
        whichEl = document.layers[i];
        if (whichEl.id == el) {
            ind = i;
            break;
        }
    }
    return ind;
}

function arrange() {
    nextY = document.layers[firstInd].pageY +document.layers[firstInd].document.height;
    for (i=firstInd+1; i<document.layers.length; i++) {
        whichEl = document.layers[i];
        if (whichEl.visibility != "hide") {
            whichEl.pageY = nextY;
            nextY += whichEl.document.height;
        }
    }
}

function initIt(){
    if (!ver4) return;
    if (NS4) {
        for (i=0; i<document.layers.length; i++) {
            whichEl = document.layers[i];
            if (whichEl.id.indexOf("Child") != -1) whichEl.visibility = "hide";
       }
        arrange();
    }
    else {
        divColl = document.all.tags("DIV");
        for (i=0; i<divColl.length; i++) {
            whichEl = divColl(i);
            if (whichEl.className == "child") whichEl.style.display = "none";
        }
    }
}

function expandIt(el) {
    if (!ver4) return;
    if (IE4) {
        whichEl = eval(el + "Child");
        if (whichEl.style.display == "none") {
            whichEl.style.display = "block";
        }
        else {
            whichEl.style.display = "none";
        }
    }
    else {
        whichEl = eval("document." + el + "Child");
        if (whichEl.visibility == "hide") {
            whichEl.visibility = "show";
        }
        else {
            whichEl.visibility = "hide";
        }
        arrange();
    }
}
onload = initIt;




////////////////////////// Go URL (1) Link to Login page  /////////////////////////////////////

function gourl(){
window.location = "http://www.soonerthanlater.com/account.php";
}

///////////////////////// Go URL (2)  Link to Index page  //////////////////////////////////////


function gourl2(){
window.location = "http://www.soonerthanlater.com/index.php";
}



//////////////////////////  Input Check Update Form  ///////////////////////////////


function openScript(url,name, width, height){
	var Win = window.open(url,name,'width=' + width + ',height=' + height + ',resizable=1,scrollbars=yes,menubar=no,status=yes' );
}


function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail !")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail !")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail !")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail !")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail !")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail !")
		    return false
		 }

		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail !")
		    return false
		 }

 		 return true
	}


var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 10;

function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function checkInternationalPhone(strPhone){
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}

function checkform2() {

    if (document.form2.email.value==""){
		alert("Please enter email!");
		document.form2.email.focus();
		return false;
	}
if (echeck(document.form2.email.value)==false){
		document.form2.email.value=""
		document.form2.email.focus()
		return false
	}

	if (document.form2.password.value==""){
		alert("Please enter password!");
		document.form2.password.focus();
		return false;
	}
	if (document.form2.password_2.value!=document.form2.password.value){
		alert("Please confirm your password!");
		document.form2.password_2.focus();
		return false;
	}
	if (document.form2.first_name.value==""){
		alert("Please enter your first name!");
		document.form2.first_name.focus();
		return false;
	}
	if (document.form2.last_name.value==""){
		alert("Please enter your last name!");
		document.form2.last_name.focus();
		return false;
	}

	if (document.form2.company_name.value=="" ){
		alert("Please enter your company name!");
		document.form2.company_name.focus();
		return false;
	}
	if (document.form2.address_1.value=="" ){
		alert("Please enter address!");
		document.form2.address_1.focus();
		return false;
	}
	if (document.form2.country.value=="" ){
		alert("Please enter country!");
		document.form2.country.focus();
		return false;
	}

	if (document.form2.telephone_no.value==""){
		alert("Please give your telephone number which we can contact you!");
		document.form2.telephone_no.focus();
		return false;
	}
	if (checkInternationalPhone(document.form2.telephone_no.value)==false){
		alert("Please Enter a Valid Phone Number")
		document.form2.telephone_no.value=""
		document.form2.telephone_no.focus()
		return false
	}
	if (document.form2.fax_no.value==""){
		alert("Please give your fax number!");
		document.form2.fax_no.focus();
		return false;
	}
	if (document.form2.mobile.value==""){
		alert("Please give your Mobile number!");
		document.form2.mobile.focus();
		return false;
	}



return true;
}





///////////////////////////////  Register Roles Links ///////////////////////////////////

function links(){
if (document.registerform.register_type == guest){ 
 alert("Guest!");
 return false;
}
  return true;
  
 }





///////////////////////////////  Input Check Register Guest Form /////////////////////////

function checkguest_form() {

    if (document.guest_form.email.value==""){
		alert("Please enter email!");
		document.guest_form.email.focus();
		return false;
	}
   if (echeck(document.guest_form.email.value)==false){
		document.guest_form.email.value=""
		document.guest_form.email.focus()
		return false
	}
	if (document.guest_form.email_2.value!=document.guest_form.email.value){
		alert("Please confirm your Email!");
		document.guest_form.email_2.focus();
		return false;
	}

	if (document.guest_form.password.value==""){
		alert("Please enter password!");
		document.guest_form.password.focus();
		return false;
	}
	if (document.guest_form.password_2.value!=document.guest_form.password.value){
		alert("Please confirm your Password!");
		document.guest_form.password_2.focus();
		return false;
	}
	if (document.guest_form.first_name.value==""){
		alert("Please enter your first name!");
		document.guest_form.first_name.focus();
		return false;
	}
	if (document.guest_form.last_name.value==""){
		alert("Please enter your last name!");
		document.guest_form.last_name.focus();
		return false;
	}

return true;
}



///////////////////////////////  Input Check Register Client Form ////////////////////////

function checkclient_form() {

    if (document.client_form.email.value==""){
		alert("Please enter email!");
		document.client_form.email.focus();
		return false;
	}
   if (echeck(document.client_form.email.value)==false){
		document.client_form.email.value=""
		document.client_form.email.focus()
		return false
	}
	if (document.client_form.email_2.value!=document.client_form.email.value){
		alert("Please confirm your Email!");
		document.client_form.email_2.focus();
		return false;
	}

	if (document.client_form.password.value==""){
		alert("Please enter password!");
		document.client_form.password.focus();
		return false;
	}
	if (document.client_form.password_2.value!=document.client_form.password.value){
		alert("Please confirm your Password!");
		document.client_form.password_2.focus();
		return false;
	}
	if (document.client_form.first_name.value==""){
		alert("Please enter your first name!");
		document.client_form.first_name.focus();
		return false;
	}
	if (document.client_form.last_name.value==""){
		alert("Please enter your last name!");
		document.client_form.last_name.focus();
		return false;
	}

	if (document.client_form.telephone_no.value==""){
		alert("Please give your telephone number which we can contact you!");
		document.client_form.telephone_no.focus();
		return false;
	}
	if (checkInternationalPhone(document.client_form.telephone_no.value)==false){
		alert("Please Enter a Valid Phone Number")
		document.client_form.telephone_no.value=""
		document.client_form.telephone_no.focus()
		return false
	}
	if (document.client_form.company_name.value==""){
		alert("Please enter the company name!");
		document.client_form.company_name.focus();
		return false;
	}
	if (document.client_form.address_1.value==""){
		alert("Please give your company address!");
		document.client_form.address_1.focus();
		return false;
	}
	if (document.client_form.city.value==""){
		alert("Please enter the city!");
		document.client_form.city.focus();
		return false;
	}
		if (document.client_form.country.value==""){
		alert("Please enter the country!");
		document.client_form.country.focus();
		return false;
	}
		if (document.client_form.company_telephone.value==""){
		alert("Please give company telephone number which we can use to contact!");
		document.client_form.company_telephone.focus();
		return false;
	}
	if (checkInternationalPhone(document.client_form.company_telephone.value)==false){
		alert("Please Enter a Valid Phone Number")
		document.client_form.company_telephone.value=""
		document.client_form.company_telephone.focus()
		return false
	}
 

return true;
}




///////////////////////// Input Check Register Staff Form //////////////////////////

function checkstaff_form() {

    if (document.staff_form.email.value==""){
		alert("Please enter email!");
		document.staff_form.email.focus();
		return false;
	}
   if (echeck(document.staff_form.email.value)==false){
		document.staff_form.email.value=""
		document.staff_form.email.focus()
		return false
	}
	if (document.staff_form.email_2.value!=document.staff_form.email.value){
		alert("Please confirm your Email!");
		document.staff_form.email_2.focus();
		return false;
	}

	if (document.staff_form.password.value==""){
		alert("Please enter password!");
		document.staff_form.password.focus();
		return false;
	}
	if (document.staff_form.password_2.value!=document.staff_form.password.value){
		alert("Please confirm your Password!");
		document.staff_form.password_2.focus();
		return false;
	}
	if (document.staff_form.first_name.value==""){
		alert("Please enter your first name!");
		document.staff_form.first_name.focus();
		return false;
	}
	if (document.staff_form.last_name.value==""){
		alert("Please enter your last name!");
		document.staff_form.last_name.focus();
		return false;
	}
	if (document.staff_form.telephone_no.value==""){
		alert("Please give your telephone number which we can contact you!");
		document.staff_form.telephone_no.focus();
		return false;
	}
	if (checkInternationalPhone(document.staff_form.telephone_no.value)==false){
		alert("Please Enter a Valid Phone Number")
		document.staff_form.telephone_no.value=""
		document.staff_form.telephone_no.focus()
		return false
	}
	if (document.staff_form.employee_no.value==""){
		alert("Please enter your emplpyee number!");
		document.staff_form.employee_no.focus();
		return false;
	}
		if (document.staff_form.department.value==""){
		alert("Please enter the department name!");
		document.staff_form.department.focus();
		return false;
	}

return true;
}






//////////////////////////////  Check Email in Forget Password page  ///////////////////////////



function checkemail() {

    if (document.form2.email2.value==""){
		alert("Please enter your email which used when register!");
		document.form2.email2.focus();
		return false;
	}
if (echeck(document.form2.email2.value)==false){
		document.form2.email2.value=""
		document.form2.email2.focus()
		return false
	}


return true;
}




