/*------------------ global js (Front End) ----------------------------*/

/*--------------- Change style css ----------------------*/
function celOver(obj) {
  var s = obj.className;
  s = s.replace(/-over/g, "");
  obj.className = s+"-over";
}

function celOut(obj) {
  var s = obj.className;
  s = s.replace(/-over/g, "");
  obj.className = s;
}


/*------------- Search field ----------------*/
function searchinfo() {
  var errors = '';
  var form = document.SearchFrm
  if (form.searchfield.value == "Search" || form.searchfield.value == "") {
    errors = "True";
  }
  if (errors) {
    //alert('The following error(s) occurred:\n'+errors);
  }
  document.MM_returnValue = (errors == '');
}

function searchfocus(val) {
  if (val.value == "Search") {
    val.value = "";
  }
}

function searchblur(val) {
  if (val.value == "") {
    val.value = "Search";
  }
}

/*------------- Search field ----------------*/
function MM_validateApplyOnline() {
  var form = document.form1;
  var errors = "";
  
  if (form.Name.value.length == 0) {
	errors += "- Name is required\n";
  }
  
  if (form.Address.value.length == 0) {
	errors += "- Address is required\n";
  }
  
  if (form.Email.value.length == 0) {
	errors += "- Email is required\n";
  }
  
  if (form.Phone.value.length == 0) {
	errors += "- Phone is required\n";
  }
  
  if (form.Mobile.value.length == 0) {
	errors += "- Mobile is required\n";
  }
  
  if (!numberok(form.Phone.value)) {
	errors += "- Phone must be a number\n";
  }
  
  if (!numberok(form.Mobile.value)) {
	errors += "- Mobile must be a number\n";
  }
  
  if (form.CompanyName.value.length == 0) {
	errors += "- CompanyName is required\n";
  }
  
  if (form.Comments.value.length == 0) {
	errors += "- Comments is required\n";
  }
  
  if (form.Position.value.length == 0) {
	errors += "- Position is required\n";
  }
  
  errors += verifyEmail();
  
  if (errors) {
    alert('The following error(s) occurred:\n'+errors);
  }
  document.MM_returnValue = (errors == '');
}

/*-------gallery system (item)----------*/
function popup(idimg,width,height) { 
  xp = (screen.width-width)/2;
  if (xp <= 0) {
    xp = 0;
  }
  yp = 0;

  fen = window.open(idimg,'','toolbar=0,location=0,directories=0,status=0,scrollbars=0,resizable=0,copyhistory=0,menuBar=0,top='+yp+',left='+xp+',width=' + width + ',height=' + height);
  fen.focus(); 
}

/*-------gallery system (itempopup)----------*/
function checksize() {
 if (document.images[0].complete) {
  window.resizeTo(document.images[0].width+12,document.images[0].height+30);
  window.focus();
 }
}

/*------------------end global js----------------------------*/
function numberok(valeur) {
	if (isNaN(valeur)) {
		return false;
	} else {
		return true;
	}
}

function verifyEmail() {
  var form = document.form1;
  var msg = "";
  
  if (form.Email.value.length == 0) {
    returnString += "- Email is required\n";
  } else {
	regex = new RegExp("^[a-z0-9_]([.-]?[a-z0-9_]+)+@[a-z0-9_]([.-]?[a-z0-9_]+)+\.([a-z]{2,4}|[a-z]{6})$", "gi");
	if (!regex.exec(form.Email.value)) {
       msg += "- Email is invalid\n";
	}				
  }
  return msg;
}
