// JavaScript Document

var vector1=Array()
var vector2=Array()
var i=0;
var j=0;


function alo(){
	alert("alo");
}


function analytics(){

	var desti = document.location.href;
	var str = desti.split('/');
	//alert(str[2]);

	if (str[2]=="http://www.dinsic.cat/"){
		var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
		document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
		var pageTracker = _gat._getTracker("UA-5800634-1");
		pageTracker._trackPageview();
		return;
	}
	if (str[2]=="http://www.dinsic.es/"){
		var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
		document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
		var pageTracker = _gat._getTracker("UA-5800884-1");
		pageTracker._trackPageview();
		return;
	}
	if (str[2]=="http://www.dinsic.com/"){
		var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
		document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
		var pageTracker = _gat._getTracker("UA-5800908-1");
		pageTracker._trackPageview();
		return;
	}
}


function redireccion(){
	if (document.location.href=="http://www.dinsic.cat/"){
		document.location.href='http://www.dinsic.com/';
		return false;
	}
	if (document.location.href=="http://www.dinsic.es/"){
		document.location.href='http://www.dinsic.com/';
//		document.location.href='http://www.dinsic.es/es';
		return false;
	}
}

function calc() {

//	alert(document.location.href);

//	var vent=window.open('../../pagos/index.html','tpv','width=725,height=600,scrollbars=no,resizable=yes,status=yes,menubar=no,location=no');

	//envio temporal mientras no se compruebe la validez del pago
	document.forms['compra_tpv'].submit();

}

function popup_paypal(){
	width=700;
	height=600;
	var url='/paypal/prev_notify_url';
	var puntero=window.open(url,'',"width="+width+",height="+height+",menubar=no");
}

function area(opc){
	alert(opc);
	switch(opc){
		case 1: document.forms['area'].boton.name='datos'; break;
		case 2: document.forms['area'].boton.name='lista'; break;
		case 3:	document.forms['area'].boton.name='boletin'; break;

	}
	alert(document.forms['area'].boton.name);
	document.forms['area'].submit();
}


function envia(opc){
	switch(opc){
		case 1: document.forms['compra'].boton.name='RemoveProductItemButton'; break;
		case 2: document.forms['compra'].boton.name='CheckoutButton'; break;
		case 3:	document.forms['compra'].boton.name='StoreChangesButton'; break;
		case 4:	document.forms['compra'].boton.name='ContinueShoppingButton'; break;
	}
	document.forms['compra'].submit();
}

function almacen(opc){
	switch(opc){
		case 1: document.forms['pedido'].boton.name='StoreChangesButton'; break;
		case 2: document.forms['pedido'].boton.name='RemoveProductItemButton'; break;
		case 3: document.forms['pedido'].boton.name='MoveToBasket'; break;
		case 4:	document.forms['pedido'].boton.name='ContinueShoppingButton'; break;
	}
	document.forms['pedido'].submit();
}

function getRadioButtonSelectedValue(ctrl)
{
    for(i=0;i<ctrl.length;i++)
        if(ctrl[i].checked) return ctrl[i].value;
}

function copiar1(txt){
	vector1[i]=txt;
	i++;
}

function copiar2(txt){
	vector2[j]=txt;
	j++;
}

function borrar_info(){
	with (document.forms['Register']){
		for(var k=0;k<=7;k++){
			document.forms['Register'][vector2[k]].value='';
		}
	}
}

function registrar(){

	volcar_info();

	with (document.forms['Register']){
//		alert("zona: "+zona.value)
		if (zona.value==-1){
			alert("Ha de seleccinar una Zona obligatoriament");
		}else{
			document.forms['Register'].submit();
		}
	}

}

function volcar_info(){
	with (document.forms['Register']){
		if (getRadioButtonSelectedValue(radiobutton)=='si'){
			var valor1=0;
			var valor2=0;
			for(var k=0;k<=8;k++){
				document.forms['Register'][vector2[k]].value=document.forms['Register'][vector1[k]].value;
			}
		}
	}
}

function popup(imagen){
	var algo=imagen+'&pop=si';
	alert(algo);
	width=440;
	height=500;
	window.open(imagen,'',"width="+width+",height="+height+",menubar=no")
}

function imprimir2(page){
	width=700;
	height=700;
	page+='&pop=si';
	window.open(page,'',"width="+width+",height="+height+",menubar=no,scrollbars=yes")
//	window.open(page,'',"width="+width+",height="+height+",menubar=no,scrollbars=no")
}

function imprimir(page){
	width=700;
	height=700;
	window.open(page,'',"width="+width+",height="+height+",menubar=no,scrollbars=yes")
}

function imprimir_ficha(page){
	width=800;
	height=600;
	page+='/(pop)/si';
//	alert(page);
	window.open(page,'',"width="+width+",height="+height+",menubar=no")
}


function imprimir_factura(page){
	width=800;
	height=600;
	var ventana=window.open(page,'',"width="+width+",height="+height+",menubar=no");
	ventana.print();
}

function pdf(pdf){
	width=700;
	height=700;
//	alert(pdf);
	window.open(pdf,'',"width="+width+",height="+height+",menubar=no")
}

function actualitza(form){

	var selec = form.temes;
	var selecIndex = selec.selectedIndex;
	var combo = form.grau;
	var index = selec.options[selec.selectedIndex].value;
	//alert();
	//return;

	//var combo2 = document.getElementById('grau'+selec.selectedIndex);
	var combo2 = document.getElementById('grau'+index);

	if (selecIndex==0){
		combo.options.length = null;
		combo.disabled = true;
		return;
	}

	combo.options.length = null;
	combo.disabled = false;

	//alert(combo2.options.length);

	for(var i=0;i<combo2.options.length;i++){
		combo[i] = new Option(combo2.options[i].text,combo2.options[i].value,"","");
	}

	if (combo2.options.length==0) combo.disabled = true;

}
function validar_envio(pdf,alldigital){
	var cierto_pagos=false;
	var cierto_envio=false;
	with (document.forms['pagos']){
		if ((pdf!='SI')||(alldigital=='')){
			switch(getRadioButtonSelectedValue(sendment)){
				case 'C_Urgente':		cierto_pagos=true;
									break;
				case 'C_Normal': 		cierto_pagos=true;
									break;
				case 'C_Transporte':	cierto_pagos=true;
									break;
				default: 			//alert('no marcado envio');
									break;
			}
		}else{
			cierto_pagos=true;
		}
		switch(getRadioButtonSelectedValue(payment)){
			case 'Bankeinzug':	cierto_envio=true;		// ON LINE
								break;
			case 'Nachnahme': 	cierto_envio=true;		//CONTRARREMBOLSO
								break;
			default: 			//alert('no marcado pago');
								break;
		}
	}
	if (cierto_pagos && cierto_envio){
		//validado
		document.forms['pagos'].submit();
	}else{
		alert('Faltan campos de envios o pagos');
	}
	return
}

function validarZona(){
	with (document.forms['Register']){
		alert(zona.value);
	}
	return true;
}

function instrument(){

	var selectinput = document.getElementById('DestinationURL');

	if (selectinput.options[selectinput.selectedIndex].value==0){
		var selectinput = document.getElementById('PREVDestinationURL');
		if (selectinput==null) return;
	}

	var desti = selectinput.options[selectinput.selectedIndex].value

	var str = desti.split('/');
	var newstr = '';
	for(var i=1;i<str.length;i++){
		newstr+=str[i]+'/';
	}

	document.location.href=newstr;

}

function comboInstrument(combo,prevurl){

	var url = prevurl+'/layout/set/ajax/consultasexternas/consultasexternas';
	val='instrument='+combo.options[combo.selectedIndex].value;

	//alert(url);

	$('img_loading').show();
	$('instrument_carga').remove();

	var myAjax = new Ajax.Updater(
		'busca_instrument',
		url,
		{
			method: 'get',
			parameters: val
		});
}

function partitures(){

	var selectinput = document.getElementById('categoria');

	if (selectinput.options[selectinput.selectedIndex].value==0){
		var selectinput = document.getElementById('PREVDestinationURL');
		if (selectinput==null) return;
	}

	var desti = selectinput.options[selectinput.selectedIndex].value

	var str = desti.split('/');
	var newstr = '';
	for(var i=1;i<str.length;i++){
		newstr+=str[i]+'/';
	}

	document.location.href=newstr;

}

function comboPartitures(combo,prevurl){

	var url = prevurl+'/layout/set/ajax/consultasexternas/consultapartituras';
	val='partituras='+combo.options[combo.selectedIndex].value;

	//alert(url);
	//return;

	$('img_loading').show();
	$('instrument_carga').remove();

	var myAjax = new Ajax.Updater(
		'busca_partitura',
		url,
		{
			method: 'get',
			parameters: val
		});
}

function actualiza_2nivel(){

	//alert("actualiza_2nivel");

	var combo = document.getElementById('opcion2');
	combo[0] = new Option('Tots','/',"","");
	combo[1] = new Option('Basic','/(nivel)/88',"","");
	combo[2] = new Option('Intermig','/(nivel)/89',"","");
	combo[3] = new Option('Avancat','/(nivel)/90',"","");
	combo.disabled = false;

}

function direccionar(){

	//alert("direccionar");

	var desti='';
	var selectopcion = document.getElementById('opcion');
	var selectcategoria = document.getElementById('categoria');
	var destiurl = document.getElementById('DestinationURL');
	var opcion2 = document.getElementById('opcion2');

	//alert(selectopcion);

	//alert(document.location.href);
	var s = document.location.href;
	s = s.split('/');
	var lang = s[3];
	
	if (selectopcion.selectedIndex==-1){
		//no hay opcion seleccionada
		//alert('no hay opcion seleccionada');
		

		
		//document.location.href='http://www.dinsic.com/ca/publicacions/publicacions-classificacio-general/partitures/';
		document.location.href='http://www.dinsic.com/'+lang+'/publicacions/publicacions-classificacio-general/partitures/';
		return false;
	}else{
		//hay opcion seleccionada la copiamos al input y lanzamos el form

		//no ha escogido ninguna copiamos la del select categorias
		if (selectopcion.selectedIndex==0){
			var desti = selectcategoria.options[selectcategoria.selectedIndex].value
			//alert(desti);//es un numero de nodo!!!!

			//llamada ajax para obtener la url de destino!!!

			var url = 'http://www.dinsic.com/layout/set/ajax/consultasexternas/consultanodo';
			//alert(url);
			new Ajax.Request(url, {
				onSuccess : function(resp) {
					//alert("The response from the server is: " + resp.responseText);
					destiurl.value=resp.responseText;
					document.location.href='http://www.dinsic.com/'+lang+'/'+resp.responseText;
				},
				onFailure : function(resp) {
					//alert("Oops, there's been an error.");
				},
				parameters : "node="+desti
			});

			return false;

		}else{

			if (opcion2.selectedIndex!=0){
				var desti = selectopcion.options[selectopcion.selectedIndex].value;
				desti += opcion2.options[opcion2.selectedIndex].value;
			}else{
				//ha escogido ninguna copiamos la del select opcion
				var desti = selectopcion.options[selectopcion.selectedIndex].value;
			}
			//alert("desti: "+desti);
			document.location.href='http://www.dinsic.com/'+lang+'/'+desti;
			return false;

		}
	}

	return false;

}

var vector1=Array()
var vector2=Array()
var i=0;
var j=0;

function volcar_info(){
	//alert('volcar_info');
	with (document.forms['Register']){
		if (getRadioButtonSelectedValue(radiobutton)=='si'){
			var valor1=0;
			var valor2=0;
			for(var k=0;k<=8;k++){
				document.forms['Register'][vector2[k]].value=document.forms['Register'][vector1[k]].value;
			}
		}
	}
}

function copiar1(txt){
	//alert('copiar1: '+txt);
	vector1[i]=txt;
	i++;
}

function copiar2(txt){
	//alert('copiar2: '+txt);
	vector2[j]=txt;
	j++;
}

