function showMail(name) {

   var reg = window.document.getElementById("divReg");
   var regcont = window.document.getElementById("edtReg");

   reg.style.left = ((parseFloat(document.body.clientWidth) / 2) - (parseFloat(reg.style.width) / 2)) + "px";
   reg.style.top = ((parseFloat(document.body.clientHeight) / 2) - ((parseFloat(reg.style.height) / 2) + 140)) + "px";
  // reg.style.height = "450px"; 
   regcont.src = "http://www.miit.co.nz/staffmail.php?Seqn=" + name;
   reg.style.visibility = "visible";

}//end function

function showComp() {

   var reg = window.document.getElementById("divReg");
   var regcont = window.document.getElementById("edtReg");

   reg.style.left = ((parseFloat(document.body.clientWidth) / 2) - (parseFloat(reg.style.width) / 2)) + "px";
   reg.style.top = ((parseFloat(document.body.clientHeight) / 2) - ((parseFloat(reg.style.height) / 2) + 140)) + "px";
   regcont.src = "http://www.miit.co.nz/compmail.php";
   reg.style.visibility = "visible";

}//end function

function showLogin() {

   var reg = window.document.getElementById("divReg");
   var regcont = window.document.getElementById("edtReg");

   reg.style.left = ((parseFloat(document.body.clientWidth) / 2) - (parseFloat(reg.style.width) / 2)) + "px";
   reg.style.top = ((parseFloat(document.body.clientHeight) / 2) - (parseFloat(reg.style.height) / 2)) + "px";
   reg.style.height = "200px";
   regcont.src = "http://www.miit.co.nz/login-intranet.php";
   reg.style.visibility = "visible";

}//end function

function showLogout() {

   var reg = window.document.getElementById("divReg");
   var regcont = window.document.getElementById("edtReg");

   reg.style.left = ((parseFloat(document.body.clientWidth) / 2) - (parseFloat(reg.style.width) / 2)) + "px";
   reg.style.top = ((parseFloat(document.body.clientHeight) / 2) - (parseFloat(reg.style.height) / 2)) + "px";
   reg.style.height = "150px";
   regcont.src = "http://www.miit.co.nz/logout-intranet.php";
   reg.style.visibility = "visible";

}//end function

function showReg(reg_type) {
   var reg = window.document.getElementById("divReg");
   var regcont = window.document.getElementById("edtReg");

   reg.style.left = ((parseFloat(document.body.clientWidth) / 2) - (parseFloat(reg.style.width) / 2)) + "px";
   reg.style.top = ((parseFloat(document.body.clientHeight) / 2) - (parseFloat(reg.style.height) / 2)) + "px";
   
   if (reg_type == "IPM") {
      reg.style.height = "270px";

   } else {
      reg.style.height = "150px";
   }
   
   regcont.src = "http://www.miit.co.nz/registration.php?reg_type=" + reg_type;
   reg.style.visibility = "visible";

}//end function

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 Browser() {
   // IE innerHeight-HACK by Roman Dissertori (Prototype - but it works)
   var AdaptedHeight = document.getElementById('IEhackInnerHeight').offsetTop-30;
   document.getElementById('IEhackInnerHeight').style.top = AdaptedHeight + 'px';
}

function minDiv() {
   document.getElementById("staffDiv").style.height = (parseFloat(window.document.body.clientHeight) - 40) + "px";
   document.getElementById("staffDiv").style.top = (parseFloat(window.document.body.clientHeight) - 40) + "px";
}//end function

function resize() {

   var staff = document.getElementById("staffDiv");
   var Y_min = parseFloat(window.document.body.clientHeight) - 180;   
   var Y_max = parseFloat(window.document.body.clientHeight) - 40;  
   Drag.init(staff,2,0,Y_min,0,Y_max);

}//end function
function trim(s) {
  return s.replace(/^\s+|\s+$/, '');
}//end function

function validateUsername(fld) {
    var error = "";

    if (fld == null) {
        error = "Please enter a valid username.\n";
    } else {
       fld.value=fld.value.replace(/\W_/g,'');// allow only letters, and numbers
       fld.value=fld.value.replace(/\d/g,'');// allow only letters

       if (fld.value == "") {
           error = "Please enter a valid username.\n";
       }//end if
    }
    return error;
}//end function

function validateCompany(fld) {
    var error = "";

    if (fld == null) {
        error = "Please enter a valid Company name.\n";
    } else {
       fld.value=fld.value.replace(/\W_/g,'');// allow only letters, and numbers
       fld.value=fld.value.replace(/\d/g,'');// allow only letters

       if (fld.value == "") {
           error = "Please enter a valid Company name.\n";
       }//end if
    }
    return error;
}//end function

function validateEmail(fld) {
    var error="";
    if (fld == null) {
        error = "Please enter a valid email address1.\n";
    } else {
       fld.value = trim(fld.value);                        // value of field with whitespace trimmed off
       fld.value=fld.value.replace(/[;<>|~`]/g,'');      // remove unwanted characters
       var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
      
       if (fld.value == "") {
           error = "Please enter an email address.\n";
       } else if (!emailFilter.test(fld.value)) {              //test email for correct format
           error = "Please enter a valid email address2.\n";
       }//end if
    }//end if
    return error;
}//end function

function validatePhone(fld) {
    var error = "";
    if (fld == null) {
        error = "Please enter a valid telephone number.\n";
    } else {
       fld.value=fld.value.replace(/\D/g,'');// allow only numbers

       if (fld.value == "") {
           error = "Please enter a valid telephone number.\n";
       } else if ((fld.value.length < 8) || (fld.value.length > 11)) {
           error = "Please enter a valid telephone number.\n";
       }//end if
    }
    return error;
}//end function

function validateFormOnSubmit(theForm) {
   var reason = "";
   var reg_form = document.getElementById(theForm)
   
   reason += validateUsername(reg_form.name);
   reason += validatePhone(reg_form.tel);
   reason += validateEmail(reg_form.mail);
     
   if (reg_form.message != null) {
      reg_form.message.value=reg_form.message.value.replace(/[;<>|~`]/g,'');      // remove unwanted characters
   }//end if
      
   if (reason != "") {
      alert(reason);
      return false;
   } else {
      alert("Thank You.");
      return true;
   }//end if

}//end function

function showSpot() {
   var reg = window.document.getElementById("divReg");
   var regcont = window.document.getElementById("edtReg");

   reg.style.left = ((parseFloat(document.body.clientWidth) / 2) - (parseFloat(reg.style.width) / 2)) + "px";
   reg.style.top = ((parseFloat(document.body.clientHeight) / 2) - (parseFloat(reg.style.height) / 2)) + "px";
   reg.style.height = "150px";
   regcont.src = "http://www.miit.co.nz/spot.php";
   reg.style.visibility = "visible";

}//end function
