function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function checkCategory(){
	if(document.getElementById('manufacturer').checked==true){
		document.getElementById('list_manufacturer').style.display='block';
		document.getElementById('list_carrier').style.display='none';
		document.getElementById('logo_manufacturer').style.display='block';
		document.getElementById('logo_carrier').style.display='none';
	}
	else{
		document.getElementById('list_manufacturer').style.display='none';
		document.getElementById('list_carrier').style.display='block';
		document.getElementById('logo_manufacturer').style.display='none';
		document.getElementById('logo_carrier').style.display='block';
	}
}

function blackBerry(){
	document.getElementById('blackberry').focus();
}

function windows(){
	document.getElementById('windows').focus();
}

function motorola(){
	document.getElementById('motorola').focus();
}

function checkOperator(object){
	switch(object.value){
		case 'Fido': document.getElementById('operator').src='images/fido.png';
					break;
		case 'Red': document.getElementById('operator').src='images/red.png';
					break;
		case 'Rogers': document.getElementById('operator').src='images/rogers.png';
					break;
		case 'AT&T': document.getElementById('operator').src='images/at&t.png';
					break;
		case 'Cingular': document.getElementById('operator').src='images/cingular.png';
					break;
		case 'Suncom USA': document.getElementById('operator').src='images/suncom.png';
					break;
		case 'T-Mobile USA': document.getElementById('operator').src='images/tmobile.png';
					break;
		case 'Google G1': document.getElementById('operator').src='images/google-g1.png';
					break;
		case 'Bouygues Telecom': document.getElementById('operator').src='images/bouygues.png';
					break;
		case 'Orange France': document.getElementById('operator').src='images/orange.png';
					break;
		case 'SFR': document.getElementById('operator').src='images/sfr.png';
					break;
		case 'Vodafone UK': document.getElementById('operator').src='images/vodafone.png';
					break;
		case 'Movistar Spain': document.getElementById('operator').src='images/movistar.png';
					break;
		case 'Verizon BlackBerry': document.getElementById('operator').src='images/verizon.png';
					break;
		default: document.getElementById('operator').src='images/img-no-op.png';
	}
}

function checkProvider(form){
	with(form){
		if(!operator.value){
			alert("Please Select Provider");
			operator.focus();
			return false;
		}
	}
}

function checkManufacturer(form){
	with(form){
		if(!model.value){
			alert("Invalid Model");
			model.focus();
			return false;
		}
	}
}

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_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 here. 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_required(field,alerttxt)
{
with (field)
  {
  if (trim(value)==null||trim(value)=="")
    {
    alert(alerttxt);return false;
    }	
  else
    {
    return true;
    }
  }
}

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

function checkIndex(thisform,type)
  {
with (thisform)
  {
  if (agree.checked==false)
    {
	alert ('Please accept the terms and conditions!');
	agree.focus();
	return false;
	}
  }	
  with (thisform)
  {
  if (validate_required(imei,"Please fill in the box ` IMEI ` ")==false)
  {imei.focus();return false;}
  }
  with (thisform)
  {
  if (validate_imei(imei,"Please check the format of your IMEI number")==false)
  {imei.focus();return false;}
  }
  if(type==1){
	with (thisform)
	  {
	  if (validate_required(brand,"Please fill in the box ` Brand ` ")==false)
	  {brand.focus();return false;}
	  }  
  }
  else if(type==2){
	  with (thisform)
	  {
	  if (validate_required(provider,"Please fill in the box ` Provider ` ")==false)
	  {provider.focus();return false;}
	  }  
  }
  with (thisform)
	  {
	  if (validate_required(model,"Please fill in the box ` Model ` ")==false)
	  {model.focus();return false;}
	  }
	  
  with (thisform)
  {
	  if(brand.value=='Alcatel')
	  if (validate_required(providerID,"Please fill in the box ` Provider ID ` ")==false)
	  {providerID.focus();return false;}
  }
  
  with (thisform)
  {
  if (validate_required(f_name,"Please fill in the box ` First Name `")==false)
  {f_name.focus();return false;}
  }
with (thisform)
  {
  if (validate_required(l_name,"Please fill in the box ` Last Name `")==false)
  {l_name.focus();return false;}
  }
with (thisform)
  {
  if (validate_required(email,"Please fill in the box ` Email `")==false)
  {email.focus();return false;}
  }
with (thisform)
  {
  if (validate_email(email,"Please enter a valid email address!")==false)
    {email.focus();return false;}
  }

}

function checkApple(thisform)
  {
with (thisform)
  {
  if (agree.checked==false)
    {
	alert ('Please accept the terms and conditions!');
	agree.focus();
	return false;
	}
  }	
  with (thisform)
  {
  if (validate_required(f_name,"Please fill in the box ` First Name `")==false)
  {f_name.focus();return false;}
  }
with (thisform)
  {
  if (validate_required(l_name,"Please fill in the box ` Last Name `")==false)
  {l_name.focus();return false;}
  }
with (thisform)
  {
  if (validate_required(email,"Please fill in the box ` Email `")==false)
  {email.focus();return false;}
  }
with (thisform)
  {
  if (validate_email(email,"Please enter a valid email address!")==false)
    {email.focus();return false;}
  }

}
