function NewWindow(mypage,myname,w,h,scroll,resize){
	var win=null;
	LeftPosition=(screen.width)?(screen.width-w)/2:100;
	TopPosition=(screen.height)?(screen.height-h)/2:100;
	settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=yes,menubar=no,toolbar=no,resizable='+resize+'';
	win=window.open(mypage,myname,settings);
}
function trim(s){
	var l=0; var r=s.length -1;
	while(l < s.length && s[l] == ' ')
	{	l++; }
	while(r > l && s[r] == ' ')
	{	r-=1;	}
	return s.substring(l, r+1);
}
function mostrar(nombreCapa){
	popId = document.getElementById(nombreCapa);
	if(document.getElementById("recomendar")) ocultar("recomendar");
	if(document.getElementById("contacto")) ocultar("contacto");

	winsize = getWinSize();
	scrollsize = getScrollXY();
	popleft = parseInt(winsize[0]/2) - parseInt(220);
	poptop  = parseInt(winsize[1]/2) - parseInt(150) + scrollsize[1];
	popId.style.left = popleft+'px';
	popId.style.top  = poptop+'px';
	popId.style.visibility="visible";
}
function ocultar(nombreCapa){
	document.getElementById(nombreCapa).style.visibility="hidden";
}
function showID(id){
	if (document.getElementById){ // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'block';
	}else{
		if (document.layers){ // Netscape 4
			document.id.display = 'block';
		}else{ // IE 4
			document.all.id.style.display = 'block';
		}
	}
}
function hideID(id){
	if (document.getElementById){ // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'none';
	}else{
		if (document.layers){ // Netscape 4
			document.id.display = 'none';
		}else{ // IE 4
			document.all.id.style.display = 'none';
		}
	}
}
function setStyle(obj,stl,val){
	document.getElementById(obj).style[stl] = val;
}
function setClass(id,cName){
	document.getElementById(id).className=cName;
}

function checkCode (e,idtexto,mensaje) {
	var charCode;
	if(e && e.which){
		e=e;
		charCode=e.which;
	}else{
		charCode=e.keyCode;
	}
	if(charCode==13 && document.getElementById(idtexto).value.length < 2){
		alert(mensaje);
		return false;
	}else{
		return true;
	}
}
function doSearch(myform){
	var buscar = trim(myform.buscar.value);
	if(buscar.length < 3){
		alert('Por favor ingrese al menos 3 caracteres para buscar productos.');
		return false;
	}
	switch(myform.rubro.value){
		case 'electricidad':
		var surl = 'materiales_electricos/materiales_electricos_productos.php';
		break;
		case 'iluminacion':
		var surl = 'iluminacion/iluminacion_productos.php';
		break;
		case 'telefonia':
		var surl = 'telefonia/telefonia_productos.php';
		break;
		case 'informatica':
		var surl = 'informatica/informatica_productos.php';
		break;
		case 'seguridad':
		var surl = 'seguridadycontrol/seguridad_y_control_productos.php';
		break;
		case 'personal':
		var surl = 'personal_telefonia_movil/personal_productos.php';
		break;
		case 'electroprofesional':
		var surl = 'http://www.electroprofesional.com.ar/busqueda.php';
		break;
		default:
		var surl = 'catalogo_productos.php';
		break;
	}
	window.location = surl+'?buscar='+escape(buscar);
	return false;
}
function listaprecios(){
	if(document.getElementById('precio-txt').value.length==0){
		alert('Por Favor ingrese su dirección de correo electrónico');
	}else{
		document.getElementById('precios').submit();
	}
}
function ofertas(){
	if(document.getElementById('oferta-txt').value.length==0){
		alert('Por Favor ingrese su dirección de correo electrónico');
	}else{
		document.getElementById('ofertas').submit();
	}
}
function AServicio(){
	vent=window.open('http://servicio.electromisiones.net',"SERVBASE","height=450,width=650,left="+((screen.width / 2) -330)+",top="+((screen.height / 2) -240)+" ,toolbar = NO, scrollbars=yes, status =no");
}
function AElectroWEB(){
	vent=window.open("http://200.45.71.57/electroweb/acceso_electro_web.php?W=1","electroWeb","height=380,width=650,left="+((screen.width / 2) -330)+",top="+((screen.height / 2) -190)+" ,toolbar = NO, scrollbars=NO, status =no");
}
function buscarpro(){
	window.scrollTo(0,2000);
	document.getElementById('buscar').focus();
	document.getElementById('buscar').style.background = '#FFFFBF';
}
function buscarProducto(){
	document.getElementById('buscarProducto').submit();
}

/* FUNCIONES CARRITO DE COMPRAS */
function isVisible(id){
	if (document.getElementById){ // DOM3 = IE5, NS6
		if(document.getElementById(id).style.display == 'none') return false; else return true;
	}else{
		if (document.layers){ // Netscape 4
			if(document.id.display == 'none') return false; else return true;
		}else{ // IE 4
			if(document.all.id.style.display == 'none') return false; else return true;
		}
	}
}
function actCantidad(id){
	var cant = parseInt(document.getElementById('cant'+id).value);
	if(isNaN(cant) || cant==0){
		alert("Ingrese la cantidad deseada del producto. Para eliminar el producto del carro use el boton 'X'.");
	}else{
		window.location = "micarro.php?act=true&agregar="+id+"&cantidad="+cant;
	}
}
function setCantidad(id,cantidad){
	window.location = "micarro.php?act=true&agregar="+id+"&cantidad="+cantidad;
}
function removerProd(id){
	window.location = "micarro.php?remover="+id;
}
function setIva(ivacodigo){
	if(ivacodigo == 3){
		document.getElementById('nrocuit').disabled = true;
	}else{
		document.getElementById('nrocuit').disabled = false;
	}
}
function Finalizar(){
	document.getElementById('finalizar').style.display = 'block';
}
function checkEnter(e,id,act){
	var characterCode;
	if(e && e.which){
		characterCode = e.which;
	}else{
		characterCode = e.keyCode;
	}
	if(characterCode == 13){
		if(act==true) actCantidad(id); else agregarProd(id);
	}
	return true;
}
/* Manejo de popups */
function getWinSize(){
	var myWidth=0,myHeight=0;
	if(typeof(window.innerWidth)=='number'){
		//Non-IE
		myWidth=window.innerWidth;
		myHeight=window.innerHeight;
	}else if(document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight)){
		//IE6+ standards compliant mode
		myWidth=document.documentElement.clientWidth;
		myHeight=document.documentElement.clientHeight;
	}else if(document.body && (document.body.clientWidth || document.body.clientHeight)){
		//IE4 compatible
		myWidth=document.body.clientWidth;
		myHeight=document.body.clientHeight;
	}
	return [myWidth,myHeight];
}
function getScrollXY(){
	var scrOfX=0,scrOfY=0;
	if(typeof(window.pageYOffset)=='number'){
		//Netscape compliant
		scrOfY = window.pageYOffset;
		scrOfX = window.pageXOffset;
	}else if(document.body && (document.body.scrollLeft || document.body.scrollTop)){
		//DOM compliant
		scrOfY = document.body.scrollTop;
		scrOfX = document.body.scrollLeft;
	}else if(document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)){
		//IE6+ standards compliant mode
		scrOfY = document.documentElement.scrollTop;
		scrOfX = document.documentElement.scrollLeft;
	}
	return [scrOfX,scrOfY];
}
/* Otras */
function toggleItem(id){
	if(isVisible(id)){
		document.getElementById('linkmore').innerHTML = "Mostrar Más Categorías &raquo;";
		hideID(id);
	}else{
		document.getElementById('linkmore').innerHTML = "Mostrar Menos &laquo;";
		showID(id);
	}
}
function verFormContacto(forced){
	if(forced==null && isVisible('contacto')){
		hideID('contacto');
		document.getElementById('conCaption').innerHTML = 'Realizar una consulta sobre este Producto &raquo';
	}else{
		showID('contacto');
		document.getElementById('con_nombre').focus();
		document.getElementById('conCaption').innerHTML = 'Realizar una consulta sobre este Producto &laquo';
	}
}
function verFormRecomendar(){
	if(isVisible('recomendar')){
		hideID('recomendar');
		document.getElementById('recCaption').innerHTML = 'Enviar este producto por Email &raquo';
	}else{
		showID('recomendar');
		document.getElementById('rec_nombre').focus();
		document.getElementById('recCaption').innerHTML = 'Enviar este producto por Email &laquo';
	}
}
function checkEmail(strMail){
	var regMail =  /^\w+([-.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
	if(regMail.test(strMail)) return true; else return false;
}

/* Validar form registro */
function validarFormReg(myform){
	/* var paso = parseInt(myform.paso.value);*/
	if(isVisible('paso1')) var paso = 1;
	else if(isVisible('paso2')) var paso = 2;
	else if(isVisible('paso3')) var paso = 3;
	switch(paso){
		case 1:
		if(myform.nombre.value.length < 3){
			alert('Debe ingresar su nombre');
			myform.nombre.focus();
			return false;
		}else if(myform.apellido.value.length < 3){
			alert('Debe ingresar su apellido');
			myform.apellido.focus();
			return false;
		}else if(myform.dni.value.length < 5){
			alert('El número de documento debe tener al menos 5 digitos');
			myform.dni.focus();
			return false;
		}else if(isNaN(myform.dni.value)){
			alert('Ingrese su número de documento sin puntos ni espacios');
			myform.dni.focus();
			return false;
		}else if(checkEmail(myform.email.value) == false){
			alert('Debe ingresar una dirección de Email válida');
			myform.email.focus();
			return false;
		}else if(myform.password.value.length < 8){
			alert('La contraseña debe tener al menos 8 dígitos');
			myform.password.focus();
			return false;
		}else if(myform.password.value != myform.password2.value){
			alert('Las contraseñas ingresadas no coinciden');
			myform.password2.focus();
			return false;
		}else{
			hideID('paso1');
			showID('paso2');
			hideID('paso3');
			myform.paso.value = 2;
			return false;
		}
		break;
		case 2:
		if(myform.pais.value=='Argentina' && myform.provincia_ar.value == '-Seleccionar-'){
			alert('Debe elegir su provincia de residencia');
			myform.provincia_ar.focus();
			return false;
		}else if(myform.pais.value != 'Argentina' && myform.provincia.value == ''){
			alert('Debe ingresar su provincia de residencia');
			myform.provincia.focus();
			return false;
		}else if(myform.localidad.value == ''){
			alert('Debe ingresar su localidad');
			myform.localidad.focus();
			return false;
		}else if(myform.direccion.value == ''){
			alert('Debe ingresar su domicilio');
			myform.direccion.focus();
			return false;
		}else if(myform.telefono_cod.value == '' || myform.telefono_num.value == ''){
			alert('Debe ingresar su número de teléfono o celular');
			myform.telefono_cod.focus();
			return false;
		}else if(isNaN(myform.telefono_cod.value) || isNaN(myform.telefono_num.value)){
			alert('El código de área o teléfono ingresado es inválido');
			myform.telefono_cod.focus();
			return false;
		}else if(myform.fechanac_d.value == '' || myform.fechanac_m.value == '' || myform.fechanac_a.value == '' || isNaN(myform.fechanac_d.value) || isNaN(myform.fechanac_m.value) || isNaN(myform.fechanac_a.value)){
			alert('La fecha de nacimiento ingresada es inválida');
			myform.fechanac_d.focus();
			return false;
		}else if(parseInt(myform.fechanac_d.value) < 1 || parseInt(myform.fechanac_d.value) > 31 || parseInt(myform.fechanac_m.value) < 1 || parseInt(myform.fechanac_m.value) > 12 || parseInt(myform.fechanac_a.value) < 1900 || parseInt(myform.fechanac_d.value) > 2010){
			alert('La fecha de nacimiento ingresada es inválida');
			myform.fechanac_d.focus();
			return false;
		}else{
			hideID('paso1');
			hideID('paso2');
			showID('paso3');
			myform.paso.value = 3;
			myform.tipo.focus();
			return false;
		}
		break;
		case 3:
		if(myform.tipo.value == ''){
			alert('Seleccione su ocupación');
			myform.tipo.focus();
			return false;
		}else if(!myform.int_ele.checked && !myform.int_ilu.checked && !myform.int_inf.checked && !myform.int_seg.checked && !myform.int_tel.checked && !myform.int_per.checked){
			alert('Seleccione su área de interés');
			return false;
		}else if(myform.codigo.value == ''){
			alert('Ingrese el código de validación para continuar');
			myform.codigo.focus();
			return false;
		}else{
			return true;
		}
		break;
	}
	return false;
}
function setProv(){
	hideID('provincia');
	hideID('provincia_ar');
	var pais=document.getElementById('pais').value;
	if(pais=='Argentina'){
		showID('provincia_ar');
	}else{
		showID('provincia');
	}
}
