function validate_number(field)
{
	var tipo = 0;
	var valid = "0123456789";
	var ok = "yes";
	var temp;
	
	for (var i=0; i<field.value.length; i++) 
	{
		temp = "" + field.value.substring(i, i+1);
		if (valid.indexOf(temp) == "-1") 
		{ 
			ok = "no"; tipo = 1; 
		}
	}
	if (ok == "no") 
	{
		if (tipo == 1) 
		{
			alert("You must enter a valid number.");
			field.focus();
			field.select();
		}
	}
	if (ok == "no") 
	{ 
		return false;
	}
	else 
	{
		return true;
	}
}

function initiateTab(dest, e) {
	if (e.keyCode==9) { //TAB
		dest.focus();
	}
}

function initiateTabPhone(dest, e, i) {
	if (e.value.length==i) { //TAB
		dest.focus();
	}
}

function activateInput(){

	if(document.form.havedomain[0].checked){
		document.form.clientdomain.disabled = false;
		document.form.desireddomain.disabled = true;
		document.form.desireddomain.value = "";
	}else{
		document.form.clientdomain.disabled = true;
		document.form.desireddomain.disabled = false;
		document.form.clientdomain.value = "";
	}

}


function EsEmail(w_email) {
    if(w_email == '')
        return true;
	//si le pones comillas a test se caga
    var test = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	var emailReg = new RegExp(test);

	return emailReg.test(w_email);
}

var isNN = (navigator.appName.indexOf("Netscape")!=-1);
function autoTab(input,len, e) {
	var keyCode = (isNN) ? e.which : e.keyCode;
	var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
	if(input.value.length >= len && !containsElement(filter,keyCode)) {
		input.value = input.value.slice(0, len);
		input.form[(getIndex(input)+1) % input.form.length].focus();
	}
} //agregado
function containsElement(arr, ele) {
var found = false, index = 0;
while(!found && index < arr.length)
if(arr[index] == ele)
	found = true;
else
	index++;
return found;
}
function getIndex(input) {
var index = -1, i = 0, found = false;
while (i < input.form.length && index == -1)
if (input.form[i] == input) index = i;
else i++;
return index;
}

// Define a list of Microsoft XML HTTP ProgIDs.
var XMLHTTPREQUEST_MS_PROGIDS = new Array(
	"Msxml2.XMLHTTP.7.0",
	"Msxml2.XMLHTTP.6.0",
	"Msxml2.XMLHTTP.5.0",
	"Msxml2.XMLHTTP.4.0",
	"MSXML2.XMLHTTP.3.0",
	"MSXML2.XMLHTTP",
	"Microsoft.XMLHTTP"
);

// Define ready state constants.
var XMLHTTPREQUEST_READY_STATE_UNINITIALIZED = 0;
var XMLHTTPREQUEST_READY_STATE_LOADING       = 1;
var XMLHTTPREQUEST_READY_STATE_LOADED        = 2;
var XMLHTTPREQUEST_READY_STATE_INTERACTIVE   = 3;
var XMLHTTPREQUEST_READY_STATE_COMPLETED     = 4;

//-----------------------------------------------------------------------------
// Returns an XMLHttpRequest object.
//-----------------------------------------------------------------------------

function getXMLHttpRequest()
{
	var httpRequest = null;

	// Create the appropriate HttpRequest object for the browser.
	if (window.XMLHttpRequest != null)
		httpRequest = new window.XMLHttpRequest();
	else if (window.ActiveXObject != null)
	{
		// Must be IE, find the right ActiveXObject.
		var success = false;
		for (var i = 0; i < XMLHTTPREQUEST_MS_PROGIDS.length && !success; i++)
		{
			try
			{
				httpRequest = new ActiveXObject(XMLHTTPREQUEST_MS_PROGIDS[i]);
				success = true;
			}
			catch (ex)
			{}
		}
	}

	// Display an error if we couldn't create one.
	if (httpRequest == null)
		alert("Error in HttpRequest():\n\nCannot create an XMLHttpRequest object.");

	// Return it.
	return httpRequest;
}

var zipLookup = getXMLHttpRequest();

function initiateZipLookup()
{

  // Abort any currently active request.
  zipLookup.abort();

 var zipcode = document.form.zip.value;

  // Perform an asynchronous request to get a list of zip codes for
  // that city and state.
  if(zipcode!=""){

  	var url = "zip_data.php?zip=" + encodeURI(zipcode);
  	zipLookup.onreadystatechange = zipCodeReadyStateChange;
  	zipLookup.open("GET", url, true);
  	zipLookup.send(null);
  }
}


function zipCodeReadyStateChange()
{
	var statusText;

	// Check the ready state.
	switch (zipLookup.readyState)
	{

		case XMLHTTPREQUEST_READY_STATE_COMPLETED:


			// Get the XML document returned from the request and fill in the
			// form fields.
			try
			{
				var xmlDoc = zipLookup.responseXML;

				// Copy the city and state attributes from the root XML node to the appropriate form fields.

				// Get all the zip code tags returned from the request.
				var city_name = xmlDoc.getElementsByTagName("city");

				var state = xmlDoc.getElementsByTagName("state");

				document.form.city.value=city_name[0].firstChild.nodeValue;
				document.form.state.value=state[0].firstChild.nodeValue;

			}
			catch (ex)
			{
				document.form.city.value="";
				document.form.state.value="";
			}
			break;

		default:
			statusText = "Unknown error.";
			break;
	}

}

function letIncorporate(estado){

	if(estado == 0)	{
		if (document.form.havelogo[1].checked==true){
			document.form.incorporatelogo[1].checked=true;
		}
		
		changeLogo();
	}else if (estado == 1){
		if (document.form.havelogo[1].checked==true){
			document.form.incorporatelogo[1].checked=true;
		}
	}

}

function changeLogo() {

	if (document.form.havelogo[0].checked==true) {
		document.form.sdwebproslogo[1].checked=true;
	}
	else
	{
		document.form.sdwebproslogo[0].checked=true;
	}
}


var domainLookup = getXMLHttpRequest();

function getDomain(){

  // Abort any currently active request.
  	domainLookup.abort();

  	var domain = document.form.desireddomain.value;
  	var tld = document.form.tld.value;

  // Perform an asynchronous request to check the domain's avaliability

  if(domain!=""){
  	var url = "whois.php?domain=" + encodeURI(domain) + '&tld='+tld;

  	domainLookup.onreadystatechange = domainReadyStateChange;
  	domainLookup.open("GET", url, true);
  	domainLookup.send(null);
  }

}

function domainReadyStateChange()
{
	var statusText="";

	// Check the ready state.
	switch (domainLookup.readyState)
	{
		case XMLHTTPREQUEST_READY_STATE_UNINITIALIZED:
			statusText = "";
			break;

		case XMLHTTPREQUEST_READY_STATE_LOADING:
			statusText = "Initialzing domain lookup...";
			break;

		case XMLHTTPREQUEST_READY_STATE_LOADED:
			statusText = "Sending data...";
			break;

		case XMLHTTPREQUEST_READY_STATE_INTERACTIVE:
			statusText = "Downloading data...";
			break;
		case XMLHTTPREQUEST_READY_STATE_COMPLETED:


			// Get the XML document returned from the request and fill in the
			// form fields.
			try
			{
				var xmlDoc = domainLookup.responseXML;
				var messagge = xmlDoc.getElementsByTagName("messagge");

				statusText = messagge[0].firstChild.nodeValue;


			}
			catch (ex)
			{

			}
			break;

		default:
			statusText = "Unknown error.";
			break;
	}

	document.form.statustext.value = statusText;


}