// JavaScript Document

function isEmailAddress (string) {
  var addressPattern = 
    /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
  return addressPattern.test(string);
}

function isPostcode (obj) {
  string = obj.value;
  var addressPattern = /^\d{4}\s[A-Za-z]{2}$/;
  if(addressPattern.test(string)){
	return true;
  }
  addressPattern = /^\d{4}[A-Za-z]{2}$/;
  if(addressPattern.test(string)){
	obj.value = string.substr(0,4) + ' ' + string.substr(4,2);
	return true;
  }
  return false;
}

function isTelOrMobile(string){
   var pattern = /^([0]\d{2}(-|\s)[1-9]\d{6})|([0]\d{3}(-|\s)[1-9]\d{5})|([0]\d{9})|(06(-|\s)?[1-9][0-9]{7})$/;
	return pattern.test(string);
}

function chooseCountry()
{
	if ($('select#formcountry').val() == -2)
	{
		$('input#country2')
			.css({ 'visibility': 'visible'})
			.attr('disabled', null)
			.focus();
	}
	else
	{
		$('input#country2')
			.css({ 'visibility': 'hidden'})
			.attr('disabled', 'disabled');			
	}
}

/* searchHighResImgForm */
function submitSearchHighResImgForm() {
var submitdata = true
var errorstr = ""
  
errorstr = "The following fields are missing or incomplete:\n";

	if ( (document.searchHighResImgForm.searchHighResImg.value.length==0) )
	{
	   errorstr = errorstr + "\n" + "  - Name of company";
	   submitdata = false;
	 }

	if (submitdata==true)
	 {
	   document.searchHighResImgForm.action="press-categorie.php";
	   document.searchHighResImgForm.submit();
	 }
	 
 else
 {
   alert(errorstr);
   return false;
 }
}	
















/* orderAdapterForm */
function submitOrderAdapterForm() {
var submitdata = true
var errorstr = ""
  
errorstr = "The following fields are missing or incomplete:\n";

	if ( (document.orderAdapterForm.name.value.length==0) )
	{
	   errorstr = errorstr + "\n" + "  - Name";
	   submitdata = false;
	 }

	if ( (document.orderAdapterForm.address1.value.length==0) )
	{
	   errorstr = errorstr + "\n" + "  - Address";
	   submitdata = false;
	 }
	 
	if ( (document.orderAdapterForm.city.value.length==0) )
	{
	   errorstr = errorstr + "\n" + "  - City";
	   submitdata = false;
	 }

	if ( document.orderAdapterForm.country.selectedIndex==0 ) 
	 {
	   errorstr = errorstr + "\n" + "  - Country";
	   submitdata = false;
	 }
	 
	if ( (document.orderAdapterForm.telephone.value.length==0) )
	{
	   errorstr = errorstr + "\n" + "  - Telephone";
	   submitdata = false;
	 }
	 
	if ( ( document.orderAdapterForm.selectProduct[0].checked!=1 ) &&
		( document.orderAdapterForm.selectProduct[1].checked!=1 ) &&
		( document.orderAdapterForm.selectProduct[2].checked!=1 ))
	{
	   errorstr = errorstr + "\n" + "  - Select your Smart Living product";
	   submitdata = false;
	 }
	 
	if ( (document.orderAdapterForm.serialNumber.value.length==0) )
	{
	   errorstr = errorstr + "\n" + "  - Serial number";
	   submitdata = false;
	 }

	if (submitdata==true)
	 {
	   document.orderAdapterForm.action="adapter-form_thanks.php";
	   document.orderAdapterForm.submit();
	 }
	 
 else
 {
   alert(errorstr);
   return false;
 }
}	





