var origen_unidad="";
var vdes="";
var model="";
var variables=Array();
var reservado=Array("hsbToRgb","rgbToHsb","rgbToHex","test","each","getLast","getRandom","include","merge","extend","associate","contains","remove","copy","hexToRgb","indexOf","some","every","map","filter","forEach"); 
function muestraSucursal(s){
	
		
		for(x=1;x<=10;x++){
			
			
				window.document.getElementById("Sucursal"+x).style.display="none";
			}
			
		window.document.getElementById("Sucursal"+s).style.display="block";
		
	
	}

function volverST(){
		window.document.getElementById("IMAGENNN").style.display="none";
		window.document.getElementById("DATOOOOS").style.display="block";
		
	}

function muestraVer(){
		window.document.getElementById("IMAGENNN").style.display="block";
		window.document.getElementById("DATOOOOS").style.display="none";
	}


function CargaComponente(contenedor,onComplete){	
ajax = new sack();
	window.document.getElementById(contenedor).innerHTML="<img src='./loading.gif'><br>Cargando...";	
	ajax.resetData();
	for(key in this.variables ){
			if(!reservado[key]){
				//alert(variables[key]);
				ajax.setVar(key,variables[key]); 
				
				
			}
			
		}

	ajax.setVar("print","1"); 
	if(onComplete){
		
			funcion="ajax.onCompletion = "+onComplete+";";
			
			eval(funcion);
		
		}
	
	ajax.requestFile = "./";
	ajax.method = 'GET';
	ajax.element = contenedor;
	
	ajax.runAJAX();	
		
}

function popUpDodge(){	
	url='./?page=home/popup_dodge&print=1';
	Modalbox.show(url, {title: ' ', width: 430});	
}
function popServTec(x){
	if(x == 1){
		url='http://www.guillermomorales.cl/web/pop-up/ssangyong.html';
	}else if(x == 2){
		url='http://www.guillermomorales.cl/web/pop-up/gm-info.html';
	}else{
		url='http://www.guillermomorales.cl/web/pop-up/mitsubishi.html';
	}
	Modalbox.show(url, {title: ' ', width: 430});	
}

function popGM(){
	url='http://www.guillermomorales.cl/web/pop-GM.html';
	Modalbox.show(url, {title: ' ', width: 430});	
}

function popChery(){
	url='http://www.guillermomorales.cl/pop-chery-abril.html';
	Modalbox.show(url, {title: ' ', width: 430});	
}


function CargaFormulario2(i){
			
		resetVariable();
		setVariable("page","ajax/ShowroomForm");
		setVariable("id_formulario",i);
		CargaComponente("ShowroomForm","whenCompleted4");
		
		
	
}


/*function formularioModalFut(){
	url='http://www.guillermomorales.cl/web/?page=ajax/ShowroomForm&id_formulario=41&print=1';
	Modalbox.show(url, {title: '', width: 430});
}*/

function whenCompleted4(){
	var contenedor="ShowroomForm";
	window.document.getElementById(contenedor).style.position = "absolute";
	window.document.getElementById(contenedor).style.zindex = "5000";
	window.document.getElementById(contenedor).style.height = "550px";
	window.document.getElementById(contenedor).style.width = "458px";
	window.document.getElementById(contenedor).style.top = "80px";
	window.document.getElementById(contenedor).style.left = (document.body.clientWidth/2-300)+'px';
	window.document.getElementById(contenedor).style.display = "block";

}

function cerrarModal(){
	Modalbox.hide();
}



function CargaComponente2(contenedor,onComplete){	
ajax2 = new sack();
	window.document.getElementById(contenedor).innerHTML="<img src='./loading.gif'><br>Cargando...";	
	ajax2.resetData();
	for(key in this.variables ){
			if(!reservado[key]){
				//alert(variables[key]);
				ajax2.setVar(key,variables[key]); 
				
				
			}
			
		}

	ajax2.setVar("print","1"); 
	if(onComplete){
		
			funcion="ajax2.onCompletion = "+onComplete+";";
			
			eval(funcion);
		
		}
	
	ajax2.requestFile = "./";
	ajax.method = 'GET';
	ajax2.element = contenedor;
	
	ajax2.runAJAX();	
		
}



function CargaFormulario(i,contenedor,unidad_tmp){

	resetVariable()
	setVariable("page","ajax/ShowroomForm"); // recomended method of setting data to be parsed.
	setVariable("id_formulario",i); // recomended method of setting data to be parsed.	
	if(unidad_tmp)
		setVariable("unidad_marca",unidad_tmp); // recomended method of setting data to be parsed.
	CargaComponente("ShowroomForm");
	window.document.getElementById('ShowroomForm').style.position = "absolute";
	window.document.getElementById('ShowroomForm').style.zindex = "5000";
	window.document.getElementById('ShowroomForm').style.height = "550px";
	window.document.getElementById('ShowroomForm').style.width = "458px";
	window.document.getElementById('ShowroomForm').style.top = "10px";
	window.document.getElementById('ShowroomForm').style.left = (document.body.clientWidth/2-200)+'px';
	window.document.getElementById('ShowroomForm').style.display = "block";
	

}

function CerrarFormulario(){

	window.document.getElementById('ShowroomForm').style.display = "none";
	

}

function CargaPromos(promo){

	resetVariable()
	setVariable("page","home/Promocion"); // recomended method of setting data to be parsed	
	//setVariable("promoc","ajax/ShowroomForm"); // recomended method of setting data to be parsed	
	
	CargaComponente("PROMO_FEBRERO");
	window.document.getElementById('PROMO_FEBRERO').style.position = "absolute";
	window.document.getElementById('PROMO_FEBRERO').style.zindex = "5000";
	window.document.getElementById('PROMO_FEBRERO').style.height = "550px";
	window.document.getElementById('PROMO_FEBRERO').style.width = "458px";
	window.document.getElementById('PROMO_FEBRERO').style.top = "150px";
	window.document.getElementById('PROMO_FEBRERO').style.left = (document.body.clientWidth/2-200)+'px';
	window.document.getElementById('PROMO_FEBRERO').style.display = "block";
	

}

function cerrarPomoFebe(){
	window.document.getElementById('PROMO_FEBRERO').style.display = "none";
}

function setVariable(nom,val){
			this.variables[nom]=val;
		} 
function resetVariable(){
			this.variables=Array();			
		} 



function muestraShowroom(mod,unidad){
	//alert(unidad);
		resetVariable();
		if(unidad==1){
			setVariable("page","home/ShowroomDisplay10");
		}else if(unidad==13){
			setVariable("page","home/ShowroomDisplayfuso");
		}else if(unidad==9){
			setVariable("page","home/ShowroomDisplay13");
		}else{
			setVariable("page","home/ShowroomDisplay12");
		}

		setVariable("modelo_id",mod);
		setVariable("unidad",unidad);
		CargaComponente("MAIN");
	
	}


	
function descripcion(nuevo,m,unidad_tmp){
		//alert(m);
		resetVariable();
		setVariable("page","home/desc");
		setVariable("nuevo_id",nuevo);
		this.vdes=nuevo;
		this.model=m;
		this.origen_unidad=unidad_tmp;
		CargaComponente("EQUIP","getNombre");
		
	}	
function getNombre(){
		
		resetVariable();
		setVariable("page","home/nombre");
		setVariable("nuevo_id",vdes);
		
		CargaComponente2("NOMBREREEEE","cambiaUrl");
	}

function cambiaUrl(){
	
			resetVariable();
			setVariable("modelo",model); // recomended method of setting data to be parsed.
			setVariable("version_id",vdes);
			setVariable("unidad_origen",origen_unidad);
			setVariable("page","home/botones"); // recomended method of setting data to be parsed.
		
			CargaComponente("BOTONES");
	
	
	
	}	


function cambiaVersion(v_modelo,f,unidad_tmp){
		var v_version = document.getElementById('c_version').value;
		Modalbox.show('./?page=ajax/ShowroomForm&id_formulario=11&print=1&obj_id='+v_modelo+'&version_id='+v_version+'&origen='+unidad_tmp, {title: '', width: 430});
		//alert(f);
/*		
		resetVariable();
		setVariable("obj_id",v_modelo); // recomended method of setting data to be parsed.
		setVariable("version_id",v_version); // recomended method of setting data to be parsed.
		setVariable("last_page","ajax/ShowroomForm"); // recomended method of setting data to be parsed.
		setVariable("page","ajax/ShowroomForm"); // recomended method of setting data to be parsed.
		if(unidad_tmp)
			setVariable("unidad_marca",unidad_tmp); // recomended method of setting data to be parsed.
		//alert('hola');
		setVariable("id_formulario",f); // recomended method of setting data to be parsed.
		CargaComponente("ShowroomForm");
		//window.location.href="./?seccion_id=FORMULARIO&unidad=0&id_formulario=9&print=1&obj_id="+v_modelo+"&version_id="+v_version;
		*/
}

function cargaPromocionDisplay(foto,tipo){

	Modalbox.show('./?page=ajax/promos&print=1&foto='+foto+'&tipo='+tipo, {title: ' f', width: 430});
}
	
function getVersion(mod,unidad_tmp){
	//alert(mod);
		Modalbox.show('./?page=ajax/ShowroomForm&id_formulario=40&print=1&modelo_gaso='+mod+'&origen='+unidad_tmp, {title: '', width: 430});
}



function simular2(m,v,unidad_tmp){
	/*
			resetVariable();
			setVariable("obj_id",m); // recomended method of setting data to be parsed.
			setVariable("version_id",v)
			setVariable("page","ajax/ShowroomForm"); // recomended method of setting data to be parsed.
			setVariable("id_formulario","11"); // recomended method of setting data to be parsed.
			CargaComponente("ShowroomForm");
			document.getElementById('ShowroomForm').style.position = "absolute";
			document.getElementById('ShowroomForm').style.zindex = "5000";
			document.getElementById('ShowroomForm').style.height = "550px";
			document.getElementById('ShowroomForm').style.width = "458px";
			document.getElementById('ShowroomForm').style.top = "10px";
			document.getElementById('ShowroomForm').style.left = (document.body.clientWidth/2-200)+'px';
			document.getElementById('ShowroomForm').style.display = "block";
		
	*/
		Modalbox.show('./?page=ajax/ShowroomForm&id_formulario=11&print=1&obj_id='+m+'&version_id='+v+'&origen='+unidad_tmp, {title: '', width: 430});	
		
}

function trabajaNosotros(unidad_tmp){
	Modalbox.show('./?page=ajax/ShowroomForm&id_formulario=59&print=1&origen='+unidad_tmp, {title: '', width: 430});
}

	

function cotizar2(m,v,unidad_tmp){
	/*		resetVariable();
			setVariable("obj_id",m); // recomended method of setting data to be parsed.
			setVariable("version_id",v)
			setVariable("page","ajax/ShowroomForm"); // recomended method of setting data to be parsed.
			setVariable("id_formulario","9"); // recomended method of setting data to be parsed.
			CargaComponente("ShowroomForm");*/
			
			Modalbox.show('./?page=ajax/ShowroomForm&id_formulario=9&print=1&obj_id='+m+'&version_id='+v+'&origen='+unidad_tmp, {title: '', width: 430});	
			
	}
function cotizarGolOro(m,v,unidad_tmp,jugada){
			
			Modalbox.show('./?page=ajax/ShowroomForm&id_formulario=51&print=1&obj_id='+m+'&version_id='+v+'&origen='+unidad_tmp+'&jugada='+jugada, {title: '', width: 430});	
			
	}
function cotizarFinalista(m,v,unidad_tmp,jugada){
			
			Modalbox.show('./?page=ajax/ShowroomForm&id_formulario=54&print=1&obj_id='+m+'&version_id='+v+'&origen='+unidad_tmp+'&jugada='+jugada, {title: '', width: 430});	
			
	}
	
	
function simularGolOro(m,v,unidad_tmp,jugada){
		
		Modalbox.show('./?page=ajax/ShowroomForm&id_formulario=52&print=1&obj_id='+m+'&version_id='+v+'&origen='+unidad_tmp+'&jugada='+jugada, {title: '', width: 430});	
		
	}
function simularFinalista(m,v,unidad_tmp,jugada){
		
		Modalbox.show('./?page=ajax/ShowroomForm&id_formulario=55&print=1&obj_id='+m+'&version_id='+v+'&origen='+unidad_tmp+'&jugada='+jugada, {title: '', width: 430});	
		
	}
	
function cotizarUsadoGolOro(tipo,id,jugada){
	//alert(jugada);
		Modalbox.show('./?page=ajax/ShowroomForm&id_formulario='+id+'&print=1&obj_id='+tipo+'&jugada='+jugada, {title: '', width: 430});
	
	}
function cotizarUsadoFinalista(tipo,id,jugada){
	//alert(jugada);
		Modalbox.show('./?page=ajax/ShowroomForm&id_formulario='+id+'&print=1&obj_id='+tipo+'&jugada='+jugada, {title: '', width: 430});
	
	}
	
function formularioCargaModal(unidad_marca,id){
	url='./?page=ajax/ShowroomForm&id_formulario='+id+'&print=1&origen='+unidad_marca;
	Modalbox.show(url, {title: '', width: 430});
}

function formularioCargaModalSt(id,tipo){
	url='./?page=ajax/ShowroomForm&id_formulario='+id+'&print=1&tipo_marca='+tipo;
	Modalbox.show(url, {title: '', width: 430});
}
	
function CargaShowroom(tipo,accion,unidad_marca){
	//alert(tipo);
//	resetVariable();
//	setVariable("obj_id",tipo); // recomended method of setting data to be parsed.
//	setVariable("unidad",unidad_marca);
//	setVariable("page","ajax/ShowroomForm"); // recomended method of setting data to be parsed.
	if(accion == 'COTIZAR'){
		
		Modalbox.show('./?page=ajax/ShowroomForm&id_formulario=9&print=1&obj_id='+tipo+'&origen='+unidad_marca, {title: '', width: 430});	
	
//		setVariable("id_formulario","9"); // recomended method of setting data to be parsed.
	}
	if(accion == 'SIMULAR'){
		
		Modalbox.show('./?page=ajax/ShowroomForm&id_formulario=11&print=1&obj_id='+tipo+'&origen='+unidad_marca, {title: '', width: 430});
//		setVariable("id_formulario","11"); // recomended method of setting data to be parsed.
	}
	if(accion == 'FICHA'){

Modalbox.show('./?page=ajax/ShowroomForm&id_formulario=7&print=1&obj_id='+tipo+'&origen='+unidad_marca, {title: '', width: 430});
//		setVariable("id_formulario","7"); // recomended method of setting data to be parsed.
//
	}

	
//		CargaComponente("ShowroomForm");
//	window.document.getElementById('ShowroomForm').style.position = "absolute";
//	window.document.getElementById('ShowroomForm').style.zindex = "5000";
//	window.document.getElementById('ShowroomForm').style.height = "550px";
//	window.document.getElementById('ShowroomForm').style.width = "458px";
//	window.document.getElementById('ShowroomForm').style.top = "10px";
//	window.document.getElementById('ShowroomForm').style.left = (document.body.clientWidth/2-200)+'px';
//	window.document.getElementById('ShowroomForm').style.display = "block";
	
		
	
	
}

function cargaEstadistica(id,tipo){
	
	window.document.getElementById('PROMOCIONES').src="http://www.guillermomorales.cl/web/?page=home/genera_estadisticas&id_estadistica="+id+"&tipo_estadistica="+tipo+"&print=1";
}

function CargaShowroomGasolina(unidad_marcas){
	Modalbox.show('./?page=ajax/ShowroomForm&id_formulario=40&print=1&origen='+unidad_marcas, {title: '', width: 430});
}
	
	function cerrarForm(contenedor){

	window.document.getElementById(contenedor).style.display = 'none';
}

function getUnidades(id){
	switch(id){
		case 1:
			cargaEstadistica('http://www.guillermomorales.cl/web/mitsubishi/',1);
			window.location.href="http://www.guillermomorales.cl/web/mitsubishi/";
		break;
		case 2:
			cargaEstadistica('http://www.guillermomorales.cl/web/hyundai/',2);
			window.location.href='http://www.guillermomorales.cl/web/hyundai/';
		break;
		case 3:
			cargaEstadistica('http://www.guillermomorales.cl/web/?unidad=3',3);
			window.location.href='http://www.guillermomorales.cl/web/?unidad=3';
		break;
		case 4:
			cargaEstadistica('http://www.guillermomorales.cl/web/?unidad=4',4);
			window.location.href='http://www.guillermomorales.cl/web/?unidad=4';
		break;
		case 5:
			cargaEstadistica('http://www.guillermomorales.cl/web/?unidad=5',5);
			window.location.href='http://www.guillermomorales.cl/web/?unidad=5';
		break;
		case 8:
			cargaEstadistica('http://www.guillermomorales.cl/web/?unidad=8',8);
			window.location.href='http://www.guillermomorales.cl/web/?unidad=8';
		break;
		case 9:
			cargaEstadistica('http://www.guillermomorales.cl/web/?unidad=9',9);
			window.location.href='http://www.guillermomorales.cl/web/?unidad=9';
		break;
		case 10:
			cargaEstadistica('http://www.guillermomorales.cl/web/?unidad=10',10);
			window.location.href='http://www.guillermomorales.cl/web/?unidad=10';
		break;
		case 11:
			cargaEstadistica('http://www.guillermomorales.cl/web/?unidad=11',11);
			window.location.href='http://www.guillermomorales.cl/web/?unidad=11';
		break;
		case 13:
			cargaEstadistica('http://www.guillermomorales.cl/web/?unidad=13',13);
			window.location.href='http://www.guillermomorales.cl/web/?unidad=13';
		break;
		case 15:
			cargaEstadistica('http://www.guillermomorales.cl/web/?unidad=15',15);
			window.location.href='http://www.guillermomorales.cl/web/?unidad=15';
		break;
		case 100:
			cargaEstadistica('http://www.guillermomorales.cl/web/?seccion_id=PROMOS&unidad=0',100);
			window.location.href='http://www.guillermomorales.cl/web/?seccion_id=PROMOS&unidad=0';
		break;
		case 101:
			cargaEstadistica('http://multimedia.guillermomorales.cl/',101);
			window.location.href='http://multimedia.guillermomorales.cl/';
		break;
	}
}



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 MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  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_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


function CargaPresup(){
		//alert();
		var j=0;
		var unidades_pr= new Array();
		 var inputs = document.getElementsByTagName("input");
		 var hasItems = false;
		 var hastetx = false;
		 var bono = "";
		 for(var i = 0; i < inputs.length; i++){
			if(inputs[i].type == 'checkbox' && inputs[i].name!='all'){
				if(inputs[i].checked==true){
					hasItems = true;					
					unidades_pr[j]=inputs[i].value;
					j++;
				}
			}
			
			if(inputs[i].type == 'text'){
				if(inputs[i].value != ''){
					hastetx = true;
				}
				presupuesto = inputs[i].value;
			}
			
			if(inputs[i].type == 'hidden'){
				
				bono = inputs[i].value;
			}

		 }			 

		if(hasItems == false || hastetx == false){
			alert('Debe ingresar un presupuesto y seleccionar al menos una marca.');
		}else{
			resetVariable();
		
			if(bono!= ""){
				setVariable("bono",bono);
			}
			setVariable("unidades_pr",unidades_pr);
			setVariable("presupuesto",presupuesto);
	
			setVariable("page","home/presupuesto_result");
			CargaComponente("PRESU");
		}
	
}

function getModalBoxSession(){
	document.getElementById('session').src="./?page=home/consulta_sessiones&print=1";	
}
function getModalBoxPromo(){
	Modalbox.show('http://www.guillermomorales.cl/pop-up-hyundai/pop-up-hyundai.html', {title: '', width: 442});
}

function muestraDivPre(d,s,u){
	//alert(u);
	if(s==1){
		window.document.getElementById(d).style.display="block";
		window.document.getElementById(u).href="javascript:muestraDivPre("+d+",'-1','"+u+"');";
	
	}else{
		window.document.getElementById(d).style.display="none";
		window.document.getElementById(u).href="javascript:muestraDivPre("+d+",'1','"+u+"');";
		
	}
}

//Funciones para validar solo letras en campos numericos y formato separador//
function onKeyPressBlockLeters(e,obj){
	//onKeyPress='return onKeyPressBlockLeters(event,this);'	
	//alert(obj);
	var key = window.event ? e.keyCode : e.which;
	
	var keychar = String.fromCharCode(key);
	reg =/^[0-9]+/;
	return reg.test(keychar);
	
}

function formateaaqaaaajanocluiao(obj){
	var nf2 = new NumberFormat(obj.value);
		nf2.setPlaces(0);
		nf2.setSeparators(true);
		x= nf2.toFormatted();
		
		obj.value=x;
	
}