// JavaScript Document

function popup(url) {
	window.open(url,'_blank','directories=no, location=no, menubar=no, scrollbars=yes, toolbar=no');
}

function popupsize(url,uwidth,uheight) {
	window.open(url,'_blank', 'scrollbars=yes , width=' + uwidth + ', height=' + uheight );
}

function admin_modify_validator() {
	var obj = document.form1;
	var msg = "";
	if (obj.model.value == "") {
	  msg += "Model\n";
	}
	if(msg != "") {
	  alert("Please fill or correct the following fields! \n"+msg);
	  return false;
	}
	return true;
}

function dosort ( sorttype ) {
  document.forms['form66'].sort.value = sorttype ;
  document.form66.submit() ;
}

function isPhone ( number ) {
	number = number.replace(/[\(\)\.\-\ ]/g, '');
	if (number.length != 10 || number != parseInt(number)) return false;
	return true;
}

function contact_validator(){
	var obj = document.contact;
	var msg = "";
		if (obj.first_name.value == "") {
				msg += "First Name\n";
		}
		if (obj.last_name.value == "") {
				msg += "Last Name\n";
		}
		var eml = obj.email.value ;
		var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i ;
		if (!filter.test(eml) ) {
				msg += "Email\n";
		}

		var home_phone = obj.home_phone1.value + obj.home_phone2.value + obj.home_phone3.value;
		var work_phone = obj.work_phone1.value + obj.work_phone2.value + obj.work_phone3.value;
		if(!isPhone(home_phone) && !isPhone(work_phone) ) msg += "At least One Valid Phone #\n";

		if (obj.city.value == "") {
				msg += "City\n";
		}		

		
	if(msg != "") {
		alert("Please fill or correct the following fields! \n"+msg);
		return false;
	}
	return true;
}

function rma_validator(){
	var obj = document.contact;
	var msg = "";
		if (obj.first_name.value == "") {
				msg += "First Name\n";
		}
		if (obj.last_name.value == "") {
				msg += "Last Name\n";
		}
		var eml = obj.email.value ;
		var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i ;
		if (!filter.test(eml) ) {
				msg += "Email\n";
		}

		var home_phone = obj.home_phone1.value + obj.home_phone2.value + obj.home_phone3.value;
		var work_phone = obj.work_phone1.value + obj.work_phone2.value + obj.work_phone3.value;
		if(!isPhone(home_phone) && !isPhone(work_phone) ) msg += "At least One Valid Phone #\n";

		if (obj.city.value == "") {
				msg += "City\n";
		}		

		
	if(msg != "") {
		alert("Please fill or correct the following fields! \n"+msg);
		return false;
	}
	return true;
}

function techs_validator(){
	var obj = document.contact;
	var msg = "";
		if (obj.first_name.value == "") {
				msg += "First Name\n";
		}
		if (obj.last_name.value == "") {
				msg += "Last Name\n";
		}
		var eml = obj.email.value ;
		var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i ;
		if (!filter.test(eml) ) {
				msg += "Email\n";
		}

		var home_phone = obj.home_phone1.value + obj.home_phone2.value + obj.home_phone3.value;
		var work_phone = obj.work_phone1.value + obj.work_phone2.value + obj.work_phone3.value;
		if(!isPhone(home_phone) && !isPhone(work_phone) ) msg += "At least One Valid Phone #\n";

		if (obj.city.value == "") {
				msg += "City\n";
		}		

		
	if(msg != "") {
		alert("Please fill or correct the following fields! \n"+msg);
		return false;
	}
	return true;
}

function quote_validator(){
	var obj = document.quote;
	var msg = "";
		if (obj.first_name.value == "") {
				msg += "Name\n";
		}

		var home_phone = obj.home_phone1.value + obj.home_phone2.value + obj.home_phone3.value;
		var work_phone = obj.work_phone1.value + obj.work_phone2.value + obj.work_phone3.value;
		if(!isPhone(home_phone) && !isPhone(work_phone) ) msg += "At least One Valid Phone #\n";

		var eml = obj.email.value ;
		var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i ;
		if (!filter.test(eml) ) {
				msg += "Email\n";
		}
		if (obj.model.value == "") {
				msg += "Model\n";
		}
		if (obj.city.value == "") {
				msg += "City\n";
		}
		
	if(msg != "") {
		alert("Please fill or correct the following fields! \n"+msg);
		return false;
	}
	return true;
}

function calibration_validator(){
	var obj = document.quote;
	var msg = "";
		if (obj.first_name.value == "") {
				msg += "Name\n";
		}

		var home_phone = obj.home_phone1.value + obj.home_phone2.value + obj.home_phone3.value;
		var work_phone = obj.work_phone1.value + obj.work_phone2.value + obj.work_phone3.value;
		if(!isPhone(home_phone) && !isPhone(work_phone) ) msg += "At least One Valid Phone #\n";

		var eml = obj.email.value ;
		var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i ;
		if (!filter.test(eml) ) {
				msg += "Email\n";
		}
		if (obj.city.value == "") {
				msg += "City\n";
		}
		
	if(msg != "") {
		alert("Please fill or correct the following fields! \n"+msg);
		return false;
	}
	return true;
}

function prod_verify() {
	var obj = document.form1;
	if (!obj.HPT[0].checked) {
 	  var answer = confirm("Are you sure you want to overlay the product directory?\n")
     	  if (answer){ return true;}
	    else{ return false; }
	}
}

function togvis(item) {
      if (document.getElementById(item).style.display == "block") {
        document.getElementById(item).style.display = "none";
        document.getElementById(item + "tog").innerHTML = "[+]";
        document.getElementById(item + "tog").title = "Expand section";
      } else {
        document.getElementById(item).style.display = "block";
        document.getElementById(item + "tog").innerHTML = "[-]";
        document.getElementById(item + "tog").title = "Collapse section";
      }
}

function togvis1(item) {
        document.getElementById(item).style.display = "none";
        document.getElementById(item + "tog").innerHTML = "[+]";
        document.getElementById(item + "tog").title = "Expand section";
}

function orderModule(down, col) 
{
  sl = document.fm[col].selectedIndex;
  if (sl != -1 && document.fm[col].options[sl].value > "") {
    oText = document.fm[col].options[sl].text;
    oValue = document.fm[col].options[sl].value;
    if (document.fm[col].options[sl].value > "" && sl > 0 && down == 0) {
      document.fm[col].options[sl].text = document.fm[col].options[sl-1].text;
      document.fm[col].options[sl].value = document.fm[col].options[sl-1].value;
      document.fm[col].options[sl-1].text = oText;
      document.fm[col].options[sl-1].value = oValue;
      document.fm[col].selectedIndex--;
    } else if (sl < document.fm[col].length-1 && document.fm[col].options[sl+1].value > "" && down == 1) {
      document.fm[col].options[sl].text = document.fm[col].options[sl+1].text;
      document.fm[col].options[sl].value = document.fm[col].options[sl+1].value;
      document.fm[col].options[sl+1].text = oText;
      document.fm[col].options[sl+1].value = oValue;
      document.fm[col].selectedIndex++;
    }
    document.fm['.modified'].value = "1";
  } else {
    alert("Please select a module first.");
  }

  return false;
}

function xMod(col) 
{
  req = "";
  sl = document.fm[col].selectedIndex;
  if (sl != -1 && document.fm[col].options[sl].value > "") {
      if (confirm("Delete - " + document.fm[col].options[sl].text + "?")) {
        if (document.fm[col].options[sl].value!=".none") {
	    window.location= 'featured.php?action=DELETE&id=' + document.fm[col].options[sl].value;
          if (document.fm[col].length==1) {
            document.fm[col].options[0].text="";
            document.fm[col].options[0].value=".none";
          } else {
            document.fm[col].options[sl]=null; 
          } 
          document.fm['.modified'].value = "1";
        } else {
          alert("Please select a module first.");
        }
      }
  }

  return false;
}

function doSub() 
{
  if (document.fm['EDIT'].value != 'EDIT') {
    if (document.fm['action'].value != 'DELETE') {
      col = 'c0[]';
      for (i=0; i< document.fm[col].length; i++) {
        document.fm[col].options[i].selected = true;
      }
    }
  } 

  num = 3;
  for (i = 0; i < num; i++) {
    document.fm["c" + i + "_lst"].value = makeList("c" + i);
  }
  return true;
}

function makeList(col) 
{
  val = "";
  for (j=0; j<document.fm[col].length; j++) {
    if (val > "") { val += ","; }
    if (document.fm[col].options[j].value > "") val += document.fm[col].options[j].value;
  } 
  return val;
}

function sub_layout(indexes) {
  document.fm['.finished'][0].value="";
  document.fm['.indexes'].value=indexes;
  doSub();
  document.fm.submit();
}
