// JavaScript Document
browser_version= parseInt(navigator.appVersion);
browser_type = navigator.appName;
if (browser_type == "Microsoft Internet Explorer" && (browser_version >= 4)) {
document.write("<link REL='stylesheet' HREF='css/styles_ie.css' TYPE='text/css'>");
}
else {
document.write("<link REL='stylesheet' HREF='css/styles.css' TYPE='text/css'>");
}




function validate_required(field,alerttxt)
{
with (field)
  {
  if (value==null||value=="")
    {
    alert(alerttxt);return false;
    }	
  else
    {
    return true;
    }
  }
}

function validate_man(field,alerttxt)
{
with (field)
  {
	var str = value.toLowerCase();
	
  if (str.search("apple")!=-1 || str.search("iphone")!=-1 || str.search("i-phone")!=-1  || str.search("i phone")!=-1 || str.search("phone")!=-1 || str.search("pihone")!=-1 || str.search("ihone")!=-1 || str.search("ihpone")!=-1 || str.search("ipone")!=-1  || str.search("ipohne")!=-1  || str.search("ipone")!=-1 || str.search("iphne")!=-1  || str.search("iphone")!=-1  || str.search("iphoe")!=-1  || str.search("iphoen")!=-1  || str.search("iphon")!=-1  || str.search("phone")!=-1 || str.search("hone")!=-1 || str.search("hpone")!=-1 || str.search("pone")!=-1 || str.search("pohne")!=-1 || str.search("phne")!=-1 || str.search("phnoe")!=-1 || str.search("phoe")!=-1 || str.search("phoen")!=-1 || str.search("phon")!=-1 || str.search("pple")!=-1 || str.search("paple")!=-1 || str.search("aple")!=-1 || str.search("aplpe")!=-1 || str.search("appel")!=-1 || str.search("appe")!=-1 || str.search("appl")!=-1
																																																																																																																				   )

    {
    window.alert("You are submitting for Apple iPhone Unlocking... You will be redirect to Apple iPhone Unlocking Solutions after you click 'OK' ") 
	window.location="?type=Apple"
	return false;
    }	
  else
    {
    return true;
    }
  }
}



function limitText(limitField, limitCount, limitNum) {
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	} else {
		limitCount.value = limitNum - limitField.value.length;
	}
}

function validate(form_id,email) {


   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   //var reg = /^([A-Za-z0-9_\-\.])+\@([gmail\yahoo\hotmail])+\.([A-Za-z]{2,4})$/;
   var address = document.forms[form_id].elements[email].value;
   var lowercaseAddress = address.toLowerCase();
   if(lowercaseAddress.search("aol")!=-1 ){
   	  alert('Please enter a valid e-mail address!');
      return false;
   }
   var email = document.getElementById("email");
   if(reg.test(address) == false) {
      alert('Please enter a valid e-mail address!');
      return false;
   }
}


function validate_email(field,alerttxt)
{
with (field)
  {
apos=value.indexOf("@");
dotpos=value.lastIndexOf(".");
aol=value.search(/aol.com/i);
aolfr=value.search(/aol.fr/i);
if (apos<1||dotpos-apos<2)
    {
	alert(alerttxt);return false;
	}
else if(aol>1||aolfr>1)
	{
	alert("This email address (@ aol) is not accepted in this transaction. Please choose another e-mail!");
	return false;
	}
  else {return true;}
  }
}

function trim(str)
   {
    s = str.replace(/^(\s)*/, '');
     s = s.replace(/(\s)*$/, '');
    return s;
   }







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




function validate_imei(field,alerttxt)
{
with (field)
  {
  imeistring=trim(value.toString());
  imeilength=(imeistring.length);
    if (value==null||isNaN(value)==true||imeilength<15 ||imeistring[1]=="x"||imeistring[1]=="X")
    {
    alert(alerttxt);return false;
    }	
  else
    {
    return true;
    }
  }
}



function validate_form(thisform)
  {
with (thisform)
  {
  if (agree.checked==false)
    {
	alert ('Please accept the terms and conditions');
	agree.focus();
	return false;
	}
  }	
  
with (thisform)
  {
  if (validate_required(manufacturer,"ERROR: Please enter your manufacturer")==false)
  {manufacturer.focus();return false;}
  }

with (thisform)
  {
  if (validate_man(manufacturer,"Go to Apple iPhone Unlocking")==false)
  {manufacturer.focus();return false;}
  }
    
 with (thisform)
  {
  if (validate_required(model,"ERROR: Please enter your model")==false)
  {model.focus();return false;}
  }
  
 with (thisform)
  {
  if (validate_required(imei,"ERROR: Please enter your 15 digit IMEI number")==false)
  {imei.focus();return false;}
  }
  with (thisform)
  {
  if (validate_imei(imei,"ERROR: Invalid IMEI! Please follow the format of your IMEI number")==false)
  {imei.focus();return false;}
  }

   with (thisform)
  {
  if (validate_required(network,"ERROR: Please enter your network provider")==false)
  {network.focus();return false;}
  }
  
with (thisform)
  {
  if (validate_required(firstName,"ERROR: Please Enter your First Name")==false)
  {firstName.focus();return false;}
  }  
with (thisform)
  {
  if (validate_required(lastName,"ERROR: Please Enter your Last Name")==false)
  {lastName.focus();return false;}
  }

with (thisform)
  {
  if (validate_required(email,"ERROR: Please enter your email")==false)
  {email.focus();return false;}
  }
with (thisform)
  {
  if (validate_email(email,"Please enter a VALID email")==false)
    {email.focus();return false;}
  }

}

