// USO EXCLUSIVO SOFTBAL S.L.
var DGBI=function(obj){return document.getElementById(obj);};
function SB_goToUrl(url,win){location.href=url;}
var ie=window.ActiveXObject?true:false;
//muestra las imágenes
var zoom;
function SB_verPant(pant,z,n){zoom=z;DGBI("imgs").src="img/"+pant;DGBI("tF").firstChild.nodeValue=n;}
//expandir opciones
function SB_expand(){
	DGBI(SB_expand.arguments[0]).style.display='block';
	for(var i=1;i<SB_expand.arguments.length;i++){
		DGBI(SB_expand.arguments[i]).style.display='none';
	}
	
}
//abre nueva ventana
function SB_newWindow(pag,name,w,h,scroll,status){
	if(zoom!==''){
		var winl=(screen.availWidth-w)/2;var wint=(screen.availHeight-h)/2;
		winprops='height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',status='+status;
		win=window.open(pag,name,winprops);
		if(parseInt(navigator.appVersion)>=4){win.window.focus()}
	}
}
function SB_munic(){if(DGBI("provincia").value==0){alert("Seleccione una provincia por favor");DGBI("provincia").focus()}}
//validar formulario
var vMail=/^[\w][\w\-\.]*@[\w\-\.]+\.[a-z]{2,4}/i; //chequeo de la dirección de correo
var vNum=/^(\d+)$/; //chequeo de números
function SB_valForm(pag,f){
	if(DGBI("dpto")){if(DGBI("dpto").value==""){alert("Por favor seleccione el dpartamento con el que desea contactar.");DGBI("dpto").focus();return;}}
	if(DGBI("rSocial")){if(DGBI("rSocial").value==""){alert("Por favor indique la razón social.");DGBI("rSocial").focus();return;}}
	if(DGBI("cliSi")){if(DGBI("cliSi").checked==false&&DGBI("cliNo").checked==false){alert("Por favor indique si es cliente o no.");return;}}
	if(DGBI("pContacto").value==""){alert("Por favor escriba el nombre de la persona de contacto.");DGBI("pContacto").focus(); return;}
	else if(DGBI("tfno").value==""&&DGBI("email").value==""){alert("Debe indicar un teléfono o e-mail de contacto.");DGBI("tfno").focus();return;}
	//else if(DGBI("tfno").value!=""&&!vNum.test(DGBI("tfno").value)){alert("El campo de teléfono sólo puede contener números.");DGBI("tfno").value;return;}
	else if(DGBI("email").value!=""&&!vMail.test(DGBI("email").value)){alert("Introduzca una dirección e-mail válida.");DGBI("email").value="";DGBI("email").value;return;}
	else if(DGBI("fsDP")){
		var dp=new Array("direcc","cp","munic","prov");
		for(var i=0;i<dp.length;i++){
			if(DGBI(dp[i])&&DGBI(dp[i]).value==''){
			alert("Por favor debe rellenar los datos postales para poder remitirle las invitaciones.");DGBI(dp[i]).focus();
			return}
		}
		if(DGBI("invit")&&DGBI("invit").value==0){alert("Por favor indique el número de invitaciones que desea recibir."); return}
	}
	if(!DGBI("lAceptLegal").checked){alert("Debe aceptar los términos legales.");return;}
	try{
		if(DGBI("provincia").value!=0){DGBI("nom_prov").value=DGBI("provincia").options[DGBI("provincia").options.selectedIndex].text}else{DGBI("nom_prov").value="Sin especificar"}
	} catch(e){}
	DGBI("send").disabled=true;f.action=pag;f.submit();
}
function SB_medio(val){
	if(val=="otros"){DGBI("lMedio2").style.display='block';DGBI("medio2").style.display='block'}
	else{DGBI("lMedio2").style.display='none';DGBI("medio2").style.display='none'}
}
//carga el combo de provincias y municipios
var SB_cargaCombo={
	obOpen:function(cmp,val){
		if(cmp=="prv"){pag=roFile+'provincias.asp?nInmo=0'; SB_XML.openObject(pag,'GET','','SB_cargaCombo.process("provincia")')}
		else{if(val!=0){pag=roFile+'municipios.asp?nCodProv='+val+'&nCodInmob=0'; SB_XML.openObject(pag,'GET','','SB_cargaCombo.process("munic")')}}
	},
	process:function(cmp){
		if(!root){alert(connError);return;}
		var opt=DGBI(cmp);SB_delNodeWhite(root)
		while(opt.options.length>1){opt.options[opt.options.length-1]=null;}
		if(root.childNodes.length>0){
			for(i=0;i<root.childNodes.length;i++){
				valor=root.childNodes[i].getAttribute("codigo");
				texto=root.childNodes[i].firstChild.nodeValue;
				opt.options[i+1]=new Option(texto,valor);
			}
			opt.options[0].selected=true
		}
	}
}
var root="",roFile="ficheros/";
var BTAG=function(tag,att,n){if(att==''){return root.getElementsByTagName(tag)[n];}	else{return root.getElementsByTagName(tag)[n].getAttribute(att)}}
function SB_delNodeWhite(raiz){for(x=0;x<raiz.childNodes.length;x++){if(raiz.childNodes[x].nodeType==3){raiz.removeChild(raiz.childNodes[x]);}}}
var SB_XML={
	parser:function(){
		if(window.ActiveXObject){return new ActiveXObject('Microsoft.XMLHTTP')}
		else if(window.XMLHttpRequest){return new XMLHttpRequest()}
		else{return false}
	},
	openObject:function(pagData,method,params,process){
		xDoc=this.parser()
		xDoc.onreadystatechange=function(){
			if(xDoc.readyState==4){if(xDoc.status==200){root=xDoc.responseXML.documentElement;return eval(process)}else{alert("problema: "+xDoc.statusText)}}
		}
		try{xDoc.open(method,pagData,true)}catch(exception){alert(exception)}
		if(method=='POST'){
			xDoc.setRequestHeader('Connection','close')
			xDoc.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		}
		try{xDoc.send(method=='POST'?params:null)}catch(exception){alert(exception)}
	}
}
