
function submitonce1(valor){
	if (valor==1) {
		document.getElementById('SubmitButton').style.display="none"
		document.getElementById('ProcessMsg').style.display="block"
		document.getElementById('SubmitButtonT').style.display="none"
		document.getElementById('ProcessMsgT').style.display="block"
	} else {
		document.getElementById('SubmitButton').style.display="block"
		document.getElementById('ProcessMsg').style.display="none"
	}
}
function submitonce(valor){
	if (valor==1) {
		document.getElementById('SubmitButton').style.display="none"
		document.getElementById('ProcessMsg').style.display="block"
	} else {
		document.getElementById('SubmitButton').style.display="block"
		document.getElementById('ProcessMsg').style.display="none"
	}
}
function FocusField(formInst,elementInst){
	if(document.forms.length>0){document.forms[formInst].elements[elementInst].focus();}
}

/*========================================================
Validación de formulario basica
onSubmit="MM_validateForm('nombre','','R','ciudad','','R','email','','RisEmail','usuario','','R','password1','','R','password2','','R');return document.MM_returnValue"
=========================================================*/

function MM_findObj(n,d){
	var p,i,x;if(!d)d=document;if((p=n.indexOf("?"))>0&&parent.frames.length){
	d=parent.frames[n.substring(p+1)].document;n=n.substring(0,p);}
	if(!(x=d[n])&&d.all)x=d.all[n];for(i=0;!x&&i<d.forms.length;i++)x=d.forms[i][n];
	for(i=0;!x&&d.layers&&i<d.layers.length;i++)x=MM_findObj(n,d.layers[i].document);
	if(!x&&d.getElementById)x=d.getElementById(n);return x;
}
function MM_validateForm(){
	var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
	for(i=0;i<(args.length-2);i+=3){
		test=args[i+2];val=MM_findObj(args[i]);
		if(val){
			nm=val.name;
			if((val=val.value)!=""){
				if(test.indexOf('isEmail')!=-1){
					p=val.indexOf('@');
					if(p<1||p==(val.length-1))errors+='- '+nm+' must contain an e-mail address.\n';
				}else if(test.indexOf('checklegal')!=-1){
					
				}else if(test!='R'){
					num=parseFloat(val);
					if(isNaN(val))errors+='- '+nm+' must contain a number.\n';
					if(test.indexOf('inRange')!=-1){
						p=test.indexOf(':');
						min=test.substring(8,p);max=test.substring(p+1);
						if(num<min||max<num)errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
					}
				}
				if(test.indexOf('isDataActual')!=-1){
					var v_DateErrors=isValidDate();
					if (v_DateErrors) {errors=v_DateErrors;}
				}
				if(test.indexOf('checklegal')!=-1){
					if (document.formPost.condiciones.checked == false){errors+='Para continuar debe aceptar las condiciones legales.';}i
				}
			}else if(test.charAt(0)=='R'){
				errors+=' \n';
			}
		}
	}
	if(errors){alert('ATENCIÓ: Heu d\'omplir tots els camps marcats amb *\n'+errors);
	document.MM_returnValue=(errors=='');} else { document.MM_returnValue=(submitonce(1)); }
}

function getZonesList(sel){
	var countryCode = sel.options[sel.selectedIndex].value;
	document.getElementById('id_zone').options.length = 0;
	if(countryCode.length>0){
		contentObj = document.getElementById('id_zone');
		ajax.requestFile = webroot+'js/GetZones.php?id_country='+countryCode;
		//ajax.onLoading = contentObj.innerHTML = 'Loading list, please wait...';
		ajax.onLoading = ShowLoadingSel;
		ajax.onCompletion = createZones;
		ajax.runAJAX();
	}
}

function createZones()
{
	var obj = document.getElementById('id_zone');
	document.getElementById('id_zone').options.length = 0;
	eval(ajax.response);
}




function getZonesList_S(sel)
{
	var countryCode = sel.options[sel.selectedIndex].value;
	document.getElementById('id_zone_Sf').options.length = 0;
	if(countryCode.length>0){
		contentObj = document.getElementById('id_zone_Sf');
		ajax.requestFile = common_js+'GetZones.php?id_country='+countryCode;
		ajax.onLoading = eval("contentObj.options[contentObj.options.length] = new Option('Loading...','0');");
		ajax.onCompletion = createZones_S;
		ajax.runAJAX();
	}
}

function createZones_S()
{
	var obj = document.getElementById('id_zone_Sf');
	document.getElementById('id_zone_Sf').options.length = 0;
	eval("obj.options[obj.options.length] = new Option('...Todas','Todas');"+ajax.response);
}

function getProvincesList(sel, path){
	var provinceCode = sel.options[sel.selectedIndex].value;
	document.getElementById('id_loc_province').options.length = 0;
	document.getElementById('id_loc_city').options.length = 0;
	if(provinceCode.length>0){
		contentObj = document.getElementById('id_loc_province');
		ajax.requestFile = path+'js/GetProvinces.php?id_zone='+provinceCode;
		ajax.onLoading = eval("contentObj.options[contentObj.options.length] = new Option('Actualizando...','0');");
		ajax.onCompletion = createProvinces;
		ajax.runAJAX();
	}
}
function createProvinces(){
	var obj = document.getElementById('id_loc_province');
	document.getElementById('id_loc_province').options.length = 0;
	eval(ajax.response);
}

function getCitiesList(sel, path){
	var cityCode = sel.options[sel.selectedIndex].value;
	document.getElementById('id_loc_city').options.length = 0;
	if(cityCode.length>0){
		contentObj = document.getElementById('id_loc_city');
		ajax.requestFile = path+'js/GetCities.php?id_loc_province='+cityCode;
		ajax.onLoading = eval("contentObj.options[contentObj.options.length] = new Option('Actualizando...','0');");
		ajax.onCompletion = createCities;
		ajax.runAJAX();
	}
}
function createCities(){
	var obj = document.getElementById('id_loc_city');
	document.getElementById('id_loc_city').options.length = 0;
	eval(ajax.response);
}

function getZonesList_S(sel)
{
	var countryCode = sel.options[sel.selectedIndex].value;
	document.getElementById('id_zone_Sf').options.length = 0;
	if(countryCode.length>0){
		contentObj = document.getElementById('id_zone_Sf');
		ajax.requestFile = common_js+'GetZones.php?id_country='+countryCode;
		ajax.onLoading = eval("contentObj.options[contentObj.options.length] = new Option('Loading...','0');");
		ajax.onCompletion = createZones_S;
		ajax.runAJAX();
	}
}

function createZones_S()
{
	var obj = document.getElementById('id_zone_Sf');
	document.getElementById('id_zone_Sf').options.length = 0;
	eval("obj.options[obj.options.length] = new Option('...Todas','Todas');"+ajax.response);
}

function OnlyNum(myfield,e){
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;
if (keycode == 13) {
		var i;
		for (i = 0; i < myfield.form.elements.length; i++)
			if (myfield == myfield.form.elements[i])
				break;
		i = (i + 1) % myfield.form.elements.length;
		myfield.form.elements[i].focus();
		return false;
	} 
else
if (((keycode>47) && (keycode<58) )  || (keycode==46) || (keycode==44) || (keycode==45) || (keycode==8) || (keycode == 13)) {EnableSave(); return true;}
else return false;
}

function NoKeyReturn(myfield,e){
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;
	if (keycode == 13) {
			var i;
			for (i = 0; i < myfield.form.elements.length; i++)
				if (myfield == myfield.form.elements[i])
					break;
			i = (i + 1) % myfield.form.elements.length;
			myfield.form.elements[i].focus();
			return false;
	} 
	
}
