// 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 combo2 = document.getElementById('grau'+selec.selectedIndex);

	//alert('grau'+selecIndex);

	combo.options.length = null;
	combo.disabled = false;

	for(var i=0;i<combo2.options.length;i++){
		combo[i] = new Option(combo2.options[i].text,combo2.options[i].value,"","");
	}

}
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 direccionar(){

	//alert("direccionar");

	var desti='';
	var selectopcion = document.getElementById('opcion');
	var selectcategoria = document.getElementById('categoria');
	var destiurl = document.getElementById('DestinationURL');

	//alert(selectopcion);

	if (selectopcion.selectedIndex==-1){
		//no hay opcion seleccionada
	}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/new_ca/'+resp.responseText;
				},
				onFailure : function(resp) {
					//alert("Oops, there's been an error.");
				},
				parameters : "node="+desti
			});

			return false;

		}else{
			//ha escogido ninguna copiamos la del select opcion
			var desti = selectopcion.options[selectopcion.selectedIndex].value
			//alert("opcion de select: "+desti);
		}
	}

	if (desti!=''){
		//alert("copia: "+desti);
		destiurl.value=desti+'/(tema)/78'; //filtro por partituras
		//alert("seteado: "+destiurl.value);
		document.location.href='http://www.dinsic.com/new_ca/'+desti+'/(tema)/78';
		return false;
	}


	return false;

	var destiopcion = selectopcion.options[selectopcion.selectedIndex].value
	if (destiopcion==undefined) alert('no definido');
	//alert(destiopcion);

	var selectcategoria = document.getElementById('categoria');
	var desticategoria = selectcategoria.options[selectcategoria.selectedIndex].value
	//alert(desticategoria);

	var selectnivel = document.getElementById('nivel');
	var destinivel = selectnivel.options[selectnivel.selectedIndex].value
	//alert(destinivel);

//si esta marcada una opcion =>>>

//si esta marcada una categoria =>>>

//a partituras segun nivel

	//categoria
	//opcion

	return false;
}

