var en_001 = "Please enter serial number";
var en_002 = "Please enter purchase date: Day";
var en_003 = "Please enter purchase date: Month";
var en_004 = "Please enter purchase date: Year";
var en_005 = "Please select at least 1 item";
var en_006 = "Please select at least 1 of the quantity items";
var en_007 = "Please select one of the models";
var en_008 = "Please select at least 1 which is under warranty";
var en_009 = "Please input your information before you proceed!";
var en_010 = "Please enter the approval name";
var en_011 = "Please select error type";
var en_011 = "Please enter the remark for your claimed part. Your warranty claimed will not be processed if the remark is empty and irrelevant.";

/***************************************************************/
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(en_009);
	return false;
  }

  if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	alert(en_009);
	return false;
  }

  if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
	alert(en_009);
	return false;
  }

  if (str.indexOf(at,(lat+1))!=-1){
	alert(en_009);
	return false;
  }

  if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
	alert(en_009);
	return false;
  }

  if (str.indexOf(dot,(lat+2))==-1){
	alert(en_009);
	return false;
  }
		
  if (str.indexOf(" ")!=-1){
	alert(en_009);
	return false;
  }

  return true;				
}

function checkEmail(){
var frm=document.warranty;

	if (echeck(frm.email.value)==false){
	    frm.email.value="";
	    frm.email.focus();
	    return false;
	}
	if (frm.distributor_email.value != "")
	{
		if (echeck(frm.distributor_email.value)==false){
			frm.distributor_email.value="";
			frm.distributor_email.focus();
			return false;
		}
	}
	
return true;
}
//warranty check for formSelect
function check()
{
  var frm = document.formSelect;
  
  if (frm.selModel.value=="")
  {
	alert(en_007);
	frm.selModel.focus();
	return false;
  }
  if (frm.serialNo.value=="")
  {
	alert(en_001);
	frm.serialNo.focus();
	return false;
  }
/*  if (frm.day.value=="")
  {
	alert(en_002);
	frm.day.focus();
	return false;
  }*/
  if (frm.month.value=="")
  {
	alert(en_003);
	frm.month.focus();
	return false;
  }
  if (frm.year.value=="")
  {
	alert(en_004);
	frm.year.focus();
	return false;
  }

  if (frm.remarks.value=="")
  {
	alert(en_011);
	frm.remarks.focus();
	return false;
  }

var counter;
var checkbox_choices = 0;

// Loop from zero to the one minus the number of checkbox button selections
for (counter = 0; counter < formSelect.checkbox.length; counter++){
// If a checkbox has been selected it will return true
// (If not it will return false)
	if (formSelect.checkbox[counter].checked){ 
		checkbox_choices = checkbox_choices + 1; 
	}
}
if (checkbox_choices==0){
	alert(en_005);
	return false;
}
  return true;
}

//warranty check for formEdit
function check2()
{
  var frm = document.formEdit;

  if (frm.selModel.value=="")
  {
	alert(en_007);
	frm.selModel.focus();
	return false;
  }
  if (frm.serialNo.value=="")
  {
	alert(en_001);
	frm.serialNo.focus();
	return false;
  }
/*  if (frm.day.value=="")
  {
	alert(en_002);
	frm.day.focus();
	return false;
  }*/
  if (frm.month.value=="")
  {
	alert(en_003);
	frm.month.focus();
	return false;
  }
  if (frm.year.value=="")
  {
	alert(en_004);
	frm.year.focus();
	return false;
  }

/*  if (frm.remarks.value=="")
  {
	alert(en_011);
	frm.remarks.focus();
	return false;
  }*/

var counter;
var checkbox_choices = 0;

// Loop from zero to the one minus the number of checkbox button selections
for (counter = 0; counter < formEdit.checkbox.length; counter++){
// If a checkbox has been selected it will return true
// (If not it will return false)
	if (formEdit.checkbox[counter].checked){ 
		checkbox_choices = checkbox_choices + 1; 
	}
}
if (checkbox_choices==0){
	alert(en_005);
	return false;
}
  return true;
}

function checkItemQ()
{
  var frm = document.formSelect;
  
  if (frm.selModel.value=="")
  {
	alert(en_007);
	frm.selModel.focus();
	return false;
  }

/*  if (frm.remarks.value=="")
  {
	alert(en_011);
	frm.remarks.focus();
	return false;
  }*/
var counter;
var select_choice = 0;

// Loop from zero to the one minus the number of checkbox button selections
for (counter = 0; counter < formSelect.selectItem.length; counter++){
// If a checkbox has been selected it will return true
// (If not it will return false)
	if (formSelect.selectItem[counter].value!=""){ 
		select_choice = select_choice + 1; 
	}
}
if (select_choice==0){
	alert(en_006);
	return false;
}
  return true;
}

function checkItemQ2()
{
  var frm = document.formEdit;
  
  if (frm.selModel.value=="")
  {
	alert(en_007);
	frm.selModel.focus();
	return false;
  }

/*  if (frm.remarks.value=="")
  {
	alert(en_011);
	frm.remarks.focus();
	return false;
  }*/
var counter;
var select_choice = 0;

// Loop from zero to the one minus the number of checkbox button selections
for (counter = 0; counter < formEdit.selectItem.length; counter++){
// If a checkbox has been selected it will return true
// (If not it will return false)
	if (formEdit.selectItem[counter].value!=""){ 
		select_choice = select_choice + 1; 
	}
}
if (select_choice==0){
	alert(en_006);
	return false;
}
  return true;
}

//backend user 
/*function checkApprove()
{
var counter;
var checkbox_choices = 0;

// Loop from zero to the one minus the number of checkbox button selections
for (counter = 0; counter < approve.checkbox.length; counter++){
// If a checkbox has been selected it will return true
// (If not it will return false)
	if (approve.checkbox[counter].checked){ 
		checkbox_choices = checkbox_choices + 1; 
	}
}
if (checkbox_choices==0){
	alert(en_008);
	return false;
}
  return true;
}*/

function checkName(){
  var frm = document.approve;
	
  if (frm.username.value=="")
  {
	alert(en_010);
	frm.username.focus();
	return false;
  }

  

  

  /*if (frm.username.value=="")
  {
	alert(en_010);
	frm.username.focus();
	return false;
  }*/
return true;
}

