﻿var xDoc_1 = new XML();

var activeMobile = "";

function saveMobile( mobilePh )
{
	activeMobile = mobilePh;
}

function check( idZip4_ , idZip3_ , responseTextInput , ajaxServer )
{
	var zip4_ = getE( idZip4_ ).value
	var zip3_ = getE( idZip3_ ).value

	if( zip4_.length == 4 && zip3_.length == 3 )
	{
		getE('wtpreloader').style.display = "block" ;
		var url = ajaxServer +"/AjaxZipResponse.aspx?zip4_="+ zip4_ + "&zip3_=" + zip3_ +"&destId="+responseTextInput+"";

		xDoc_1.fromAsyncRequest( url , fillAdressName ,"Content-type=text/xml;charset=UTF-8");
	}
 
	
}

function fillAdressName(oResp)
{
	var resp = oResp.responseText;

	var attrib = resp.split(",")

	if( attrib.length >= 2 )
	{
		getE('wtpreloader').style.display = "none" ;
		var cb_street = getE( attrib[0] );

		for(var i = cb_street.options.length-1;i>0;i--)
		{
			if( cb_street.options[i].value != '' && cb_street.options[i].value != '0')
			{
				cb_street.remove(i);
			}
		}

		for(var i = 1; i < attrib.length; i++)
		{
			if( attrib[i] != "" )
			{
				var oOption = document.createElement("OPTION");
				oOption.text = attrib[i];
				oOption.value = "__ossli_"+attrib[i];

				cb_street.options[cb_street.options.length] = oOption;
			}
		}
		if( attrib.length = 1 )
		{
			cb_street.selectedIndex = 1;
		}
		
	}
}

function addItem( destId , text_ )
{
	if( text_ != "0" && text_ != "" )
	{
		var cb_street = getE( destId );

		var oOption = document.createElement("OPTION");
		oOption.text = text_;
		oOption.value = "__ossli_"+text_;

		cb_street.options[cb_street.options.length] = oOption;
	
		cb_street.selectedIndex = cb_street.options.length-1;
	}
}


function swapFocusTo( nrCarac , currId_ , swapToId_ )
{
	if( !currId_ || currId_ == "" )
		return;

	if( !swapToId_ || swapToId_ == "" )
		return;

	if( getE( currId_ ).value.length >= nrCarac )
		getE( swapToId_ ).focus();
}

function mobileCheck( input_ )
{
	//if( input_.value.lenght > 8 )
	//	alert("hello");
	
	if( input_.value != activeMobile )
		alert("O seu telemóvel foi alterado, tenha em conta que ao fazer isto terá de\r\n certificar este novo número, sendo que o outro ser tornará obsoleto.");
}


