var win;
var i     = 0;
var title = "";

function DJS_openImage(img, titulo) {
	if(i == 1) {
		win.close();
		win = null;
	}
	
	if(titulo == null) {
		titulo = title;
	}
	
	win = window.open('','ventana','resizable=yes,scrollbars=no');
	win.document.write('<html><head><title>' + titulo + '</title></head><body style="overflow:hidden" marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" scroll="no" onUnload="opener.i=0"><img alt="' + titulo + '" src="' + img + '" onLoad="opener.DJS_resize(this.width, this.height)" 	onClick="window.close()">');
	win.document.close();
	i++;
}

function DJS_resize(ancho, alto) {
	win.resizeTo(ancho + 12, alto + 28);
	win.moveTo((screen.width - ancho)/2, (screen.height - alto)/2); 
}

function DJS_openWindow(pagina, titulo, ancho, alto, scroll, tool) {
	var izquierda = ((screen.width  - ancho)/2);
	var arriba    = ((screen.height - alto)/2);
	window.open(pagina, titulo, 'width=' + ancho + ', height=' + alto + ', left=' + izquierda + ', top=' + arriba + ', scrollbars=' + scroll + ', toolbar=' + tool);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function DJS_creditos(e) {
	var win;
	
	var title = "Dikode";
	
	win = window.open('', 'Creditos', 'resizable=yes, scrollbars=no, width=300, height=137');
	win.document.write('<html><head><title>' + title + '</title></head><body style="overflow:hidden" marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" scroll="no">');
	
	win.document.write('<style type="text/css">');
	win.document.write('.creditos {');
	win.document.write('	font-size   : 10px;');
	win.document.write('	font-family : verdana;');
	win.document.write('}');
	win.document.write('</style>');
	win.document.write('<table cellpadding="0" cellspacing="0" border="0" width="100%" background="http://www.dikode.com/creditos/fondo.gif">');
	win.document.write('	<tr>');
	win.document.write('		<td class="creditos" style="padding: 3px" bgcolor="#b8baba"><b>Dikode Web Solutions-ek zuzendutako webgunea</b></td>');
	win.document.write('	</tr>');
	win.document.write('	<tr>');
	win.document.write('		<td class="creditos" style="padding: 10px">Copyright © Dikode Web Solutions<br>Pablo Azkue Eizagirre<br><br>Urdaneta  kalea 6, behea<br>20800 Zarautz - Gipuzkoa<br>Tlf.: 943 13 00 96<br>E-mail: dikode@dikode.com<br>Web: <b>www.dikode.com</b></td>');
	win.document.write('	</tr>');
	win.document.write('</table>');
	
	win.document.write('</body></html>');
	win.document.close();
}
	
function checkSuscriptionRows() {
	var mal = false;
	//alert(entragar_en);
		
	document.getElementById('a_nombre_div').className       = 'normal';
	document.getElementById('a_nombre_error').className     = 'normal';
	document.getElementById('a_nombre_error').innerHTML     = '';
	document.getElementById('a_apellidos_div').className    = 'normal';
	document.getElementById('a_apellidos_error').className  = 'normal';
	document.getElementById('a_apellidos_error').innerHTML  = '';
	document.getElementById('a_email_div').className       = 'normal';
	document.getElementById('a_email_error').className     = 'normal';
	document.getElementById('a_email_error').innerHTML     = '';	
	document.getElementById('a_telefono_div').className    = 'normal';
	document.getElementById('a_telefono_error').className  = 'normal';
	document.getElementById('a_telefono_error').innerHTML  = '';
	document.getElementById('a_direccion_div').className   = 'normal';
	document.getElementById('a_direccion_error').className = 'normal';
	document.getElementById('a_direccion_error').innerHTML = '';
	document.getElementById('a_ciudad_div').className      = 'normal';
	document.getElementById('a_ciudad_error').className    = 'normal';
	document.getElementById('a_ciudad_error').innerHTML    = '';
	document.getElementById('a_provincia_div').className   = 'normal';
	document.getElementById('a_provincia_error').className = 'normal';
	document.getElementById('a_provincia_error').innerHTML = '';
	document.getElementById('a_cp_div').className          = 'normal';
	document.getElementById('a_cp_error').className        = 'normal';
	document.getElementById('a_cp_error').innerHTML        = '';
   
	var nombre    = document.suscripcion.a_nombre.value;
	var apellidos = document.suscripcion.a_apellidos.value;
	var telefono  = document.suscripcion.a_telefono.value;
	var email     = document.suscripcion.a_email.value;
	var direccion = document.suscripcion.a_direccion.value;
	var ciudad    = document.suscripcion.a_ciudad.value;
	var provincia = document.suscripcion.a_provincia.options[document.suscripcion.a_provincia.selectedIndex].value;
	var cp        = document.suscripcion.a_cp.value;
		
	var warning = 0;
	if(nombre == "") {
		document.getElementById('a_nombre_div').className       = 'error';
		document.getElementById('a_nombre_error').className     = 'error';
		document.getElementById('a_nombre_error').innerHTML     = '<div id="error"><span>El nombre es un campo requerido</span></div>';
		warning++; 
	}
	if(apellidos == "") {
		document.getElementById('a_apellidos_div').className    = 'error';
		document.getElementById('a_apellidos_error').className  = 'error';
		document.getElementById('a_apellidos_error').innerHTML  = '<div id="error"><span>Los apellidos son campo requerido</span></div>';
		warning++;
	}
	if(email.indexOf('@') == -1) {
		document.getElementById('a_email_div').className        = 'error';
		document.getElementById('a_email_error').className      = 'error';
		document.getElementById('a_email_error').innerHTML      = '<div id="error"><span>El correo electrónico no es correcto</span></div>';
		warning++;
	}
	if(telefono == "") {
		document.getElementById('a_telefono_div').className    = 'error';
		document.getElementById('a_telefono_error').className  = 'error';
		document.getElementById('a_telefono_error').innerHTML  = '<div id="error"><span>El teléfono es un campo requerido</span></div>';
		warning++;
	}
	if(direccion == "") {		
		document.getElementById('a_direccion_div').className    = 'error';
		document.getElementById('a_direccion_error').className  = 'error';
		document.getElementById('a_direccion_error').innerHTML  = '<div id="error"><span>El campo dirección es un campo requerido</span></div>';
		warning++;
	}
	if(ciudad == "") {
		document.getElementById('a_ciudad_div').className       = 'error';
		document.getElementById('a_ciudad_error').className     = 'error';
		document.getElementById('a_ciudad_error').innerHTML     = '<div id="error"><span>El campo ciudad es un campo requerido</span></div>';
		warning++;
	}
	if(provincia == "Seleccione una provincia" || provincia == "") {
		document.getElementById('a_provincia_div').className    = 'error';
		document.getElementById('a_provincia_error').className  = 'error';
		document.getElementById('a_provincia_error').innerHTML  = '<div id="error"><span>El campo provincia es una campo requerido</span></div>';
		warning++;
	}
	if(cp.length < 5 || cp.length > 5 || isNaN(cp) == true) {
		document.getElementById('a_cp_div').className           = 'error';
		document.getElementById('a_cp_error').className         = 'error';
		document.getElementById('a_cp_error').innerHTML         = '<div id="error"><span>El código postal es un campo requerido</span></div>';
		warning++;
	}
	if(warning > 0) {
	} else {
		//alert('OK');
		document.suscripcion.submit();
	}
}