var preloadFlag = false;
var ns4 = (document.layers)? true:false;
var ie4 = (document.all)? true:false;

//****************************************************
//  Netscape Resize Fix
//****************************************************
if (ns4){
     origWidth = innerWidth;
     origHeight = innerHeight;
     }

function reDo(){
     if (innerWidth != origWidth || innerHeight != origHeight)
     location.reload();
          }

if (ns4) onresize = reDo;

function chcol(nama) {
nama.style.backgroundColor = '#cccccc';
return true;
}
function retcol(nama) {
nama.style.backgroundColor = '#ffffff';
return true;
}
function completetask(invar){
	reWin=window.open('print.php?completion_id='+invar,'MyWindow','toolbar=no, location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes, width=600,height=420');
}
function printtask(invar){
	reWin=window.open('print.php?completion_id='+invar+'&printonly=true','MyWindow','toolbar=no, location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes, width=600,height=420');
}

//****************************************************
//  Intialization
//****************************************************
function init(){
        preloadImages();
}

//****************************************************
//   Imaging
//****************************************************
function newImage(arg) {
     if (document.images)
     {        rslt = new Image();
          rslt.src = arg;
          return rslt;
     }
}

function changeImages(layerName,imgName,imgObj) {
     if (document.images && (preloadFlag == true))
     {
          if (document.layers && layerName!=null)
        eval('document.'+layerName+'.document.images["'+imgName+'"].src ="'+imgObj+'"');
          else document.images[imgName].src = imgObj;
     }
}

//****************************************************
//   Layer controls
//****************************************************
function show(id) {
     if (ns4) document.layers[id].visibility = "show"
     else if (ie4) document.all[id].style.visibility = "visible"
}

function hide(id) {
     if (ns4) document.layers[id].visibility = "hide"
     else if (ie4) document.all[id].style.visibility = "hidden"
}

//****************************************************
//   Status Bar
//****************************************************

function statusBar(msgStr) {
  status = msgStr;
}

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 submitUpload(){
  document.frmSelect.action = "send.php";
  document.frmSelect.submit();
}
function submitAddUser(){
  document.frmSelect.action = "send.php";
  document.frmSelect.submit();
}
function submitRemoveUser(){
  document.frmSelect.action = "send.php";
  document.frmSelect.submit();
}
function navigateMT(id){
  document.frmNavigation.resetmediatype.value = id;
  document.frmNavigation.submit();
}

function navigateSection(id){
  document.frmNavigation.resetsection.value = id;
  document.frmNavigation.submit();
}

ns4 = (document.layers)? true:false
ie4 = (document.all)? true:false

function layerWrite(id,nestref,text) {
        //alert(id+' '&nestref+' '+text);
        if (ns4) {
                if (nestref) var lyr = eval('document.'+nestref+'.document.'+id+'.document')
                else var lyr = document.layers[id].document
                lyr.open()
                lyr.write(text)
                lyr.close()
        }
        else if (ie4) document.all[id].innerHTML = text
}

function linkOver(num) {
        //alert ("Linkover :"+link[num]);
        //if (ns4) {
                for (var i=0;i<link.length;i++) {
                        if (link[i][3]==true) linkOut(i)
                }
        //}
        link[num][3] = true
        layerWrite(link[num][0],null,'<A CLASS="navigationOver" onclick="'+link[num][1]+'" onMouseOut="linkOut('+num+')">'+link[num][2]+'</A>')
}

function linkOut(num) {
        link[num][3] = true
        //alert ("Linkout :"+link[num]);
        layerWrite(link[num][0],null,'<A CLASS="navigation" onclick="'+link[num][1]+'" onMouseOver="linkOver('+num+')">'+link[num][2]+'</A>')
}

//*********************************************************************************

function checkrequired(which){
  var pass=true
  if (document.images){
  for (i=0;i<which.length;i++){
    var tempobj=which.elements[i]
      if (tempobj.name.substring(0,8)=="required"){
        if (((tempobj.type=="text"||tempobj.type=="textarea")&&tempobj.value=='')||(tempobj.type.toString().charAt(0)=="s"&&tempobj.selectedIndex==-1)){
          pass=false
          break
        }
      }
    }
  }
  if (!pass){
    alert("One or more of the required elements are not completed. Please complete them, then submit again!")
    return false
  }
  else
    //document.orderfrm.submit()
    return true
}

function validateform(){
  if (checkrequired(document.orderfrm)){
     alert("validated");
  }

}

function changeDropdown(theDropdown, selectedvalue) {
   for(i = 0; i < theDropdown.options.length; i++) {
      if (theDropdown.options[i].text==selectedvalue) {
         theDropdown.selectedIndex=i;
         break;
      }
   }
}
//*********************************************************************************
//*************************  JavaScript Valaidation *******************************
//*********************************************************************************

function checkApproval () {
var error="";
if (mainform.approved.checked){
   error = "";
}else{
   error = "You didn't indicate that you have approval.\n";
}
return error;
}
function checkEmail (strng) {
var error="";
if (strng == "") {
   error = "You didn't enter an email address.\n";
}
    var emailFilter=/^.+@.+\..{2,3}$/;
    if (!(emailFilter.test(strng))) {
       error = "Please enter a valid email address.\n";
    }
    else {
       var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
         if (strng.match(illegalChars)) {
          error = "The email address contains illegal characters.\n";
       }
    }
return error;
}

function checkPhone (strng) {
  var error = "";
  if (strng == "") {
    error = "You didn't enter a phone number.\n";
  }
  var stripped = strng.replace(/[\(\)\.\-\ ]/g, '');
  var expr = /^[a-z_A-Z_0-9]+$/
  //if (expr.test(stripped)) {
  if (isNaN(parseInt(stripped))) {
    error = "The phone number contains illegal characters.";
    }
    if (!(stripped.length == 10)) {
        error = "The phone number is the wrong length. Make sure you included an area code.\n";
    }
  return error;
}

function checkCostCenter (strng) {
  var error = "";
  if (strng == "") {
    error = "You didn't enter a Cost Center.\n";
  }
  var stripped = strng.replace(/[\(\)\.\-\ ]/g, '');
  var expr = /^[a-z_A-Z_0-9]+$/
  //if (expr.test(stripped)) {
  if (isNaN(parseInt(stripped))) {
    error = "The Cost Center contains illegal characters.";
    }
    if (!(stripped.length == 10)) {
        error = "The Cost Center is the wrong length.\n";
    }
  return error;
}

function checkFax (strng) {
  var error = "";
  if (strng == "") {
    error = "You didn't enter a facsimile number.\n";
  }

  var stripped = strng.replace(/[\(\)\.\-\ ]/g, '');
  if (isNaN(parseInt(stripped))) {
    error = "The phone number contains illegal characters.";
    }
    if (!(stripped.length == 10)) {
        error = "The facsimile number is the wrong length. Make sure you included an area code.\n";
    }
  return error;
}

function checkPassword (strng) {
  var error = "";
  if (strng == "") {
    error = "You didn't enter a password.\n";
  }
  var illegalChars = /[\W_]/;
  if ((strng.length < 6) || (strng.length > 8)) {
    error = "The password is the wrong length.\n";
  }
  else if (illegalChars.test(strng)) {
    error = "The password contains illegal characters.\n";
  }
  else if (!((strng.search(/(a-z)+/)) && (strng.search(/(A-Z)+/)) && (strng.search(/(0-9)+/)))) {
    error = "The password must contain at least one uppercase letter, one lowercase letter, and one numeral.\n";
  }
  return error;
}

function checkUsername (strng) {
  var error = "";
  if (strng == "") {
    error = "You didn't enter a username.\n";
  }
  var illegalChars = /\W/;
  if ((strng.length < 2) || (strng.length > 25)) {
    error = "The username is the wrong length.\n";
  }
//  else if (illegalChars.test(strng)) {
//    error = "The username contains illegal characters.\n";
//  }
  return error;
}

function checkString (strng, type) {
  var error = "";
  if (strng == "") {
    error = "You didn't enter a " + type + ".\n";
  }
  return error;
}

function checkRadio(checkvalue) {
  var error = "";
  if (!(checkvalue)) {
    error = "Please check a radio button.\n";
  }
  return error;
}

function checkDropdown(choice) {
  var error = "";
  if (choice == 0) {
    error = "You didn't choose an option from the drop-down list.\n";
  }
  return error;
}

function checkDropdownLabel(choice, type) {
  var error = "";
  if (choice == 0) {
    error = "You didn't choose a " + type + ".\n";
  }
  return error;
}

function checkState(strng) {
var error="";
  var illegalChars= /-/
  if (strng.match(illegalChars)) {
   error = "You must select a valid state.\n";
  }
  if (strng=="") {
   error = "You must select a valid state.\n";
  }

return error;
}

//*********************************************************************************
/**********************************************************************************
Insert this script in page header and modify

function checkWholeForm(theForm) {
    var why = "";
    why += checkEmail(theForm.email.value);
    why += checkPhone(theForm.phone.value);
    why += checkPassword(theForm.password.value);
    why += checkUsername(theForm.username.value);
    for (i=0, n=theForm.radios.length; i<n; i++) {
        if (theForm.radios[i].checked) {
            var checkvalue = theForm.radios[i].value;
            break;
        }
    }
    why += checkRadio(checkvalue);
    why += checkDropdown(theForm.choose.selectedIndex);
    if (why != "") {
       alert(why);
       return false;
    }
return true;
}

Also, your submit should look something like this:
<input type="button" value="Next" name="SUBMIT" onclick="javascript:checkWholeForm(document.orderfrm);">

************************************************************************************/

function submitNavigation(inNav){
  document.frm_navigation.navigate.value = inNav;
  //  document.frm_navigation.action = "send.php";
  document.frm_navigation.submit();
}

function submitSubNavigation(inNav){
  document.frm_navigation.subnavigate.value = inNav;
  document.frm_navigation.submit();
}

function confirmDelete(inMessage, inAction){
   if (confirm(inMessage)){
      eval(inAction);
   }
}

function confirmAction(inMessage, inAction){
   if (confirm(inMessage)){
      eval(inAction);
   }
}

function submitMain(inAction, inRecordID){
    var verifyDelete=/delete/;
    if ((verifyDelete.test(inAction))) {
		if (!(confirm("Are you sure you want to delete?"))) return;
	}
	document.frm_main.action.value = inAction;
//	alert(document.frm_main.action.value);
	if (document.frm_main.recordID.value) document.frm_main.recordID.value = inRecordID;
//	alert(document.frm_main.recordID.value);
//   document.forms["frm_main"].submit();
	document.frm_main.submit();
}



