
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
};


function agregar(){
   if ((navigator.appName=="Microsoft Internet Explorer") && (parseInt(navigator.appVersion)>=4)) {
      var url="http://www.cucoroni.com/"; 
      var titulo="CUCORONI.COM - Bolsos y complementos de Moda.";
      window.external.AddFavorite(url,titulo);
   } else { 
      if(navigator.appName == "Netscape") 
         alert("Presione Crtl+D para agregar este sitio en sus Bookmarks"); 
   }
};


function confirmar_borrado(nombre){
	return confirm('Confirmar borrado de\n'+nombre+' ?.');
};


function numbersonly(e){
	var key;
	var keychar;
	if (window.event)
 		key = window.event.keyCode;
	else if (e)
 		key = e.which;
	else
 		return true;
	keychar = String.fromCharCode(key);
	// control keys
	if ((key==null) || (key==0) || (key==8) || 
 		(key==9) || (key==13) || (key==27) )
 		return true;
	// numbers
	else if ((("0123456789").indexOf(keychar) > -1))
		return true;
	else
 		return false;
};

//Comprueba que un campo de texto WHAT no tenga mas de LIMIT caracteres
//uso: onKeyPress="return maxchars(this, 280)" onBlur="return maxchars(this, 280)"
function maxchars(what,limit){
	if (what.value.length > limit){
		what.value = what.value.substring(0, limit);
	}
};

function comprobarFecha(campo){
	if(campo.value.match(/[0-9]{2}\/[0-9]{2}\/[0-9]{4}/)){
		return true;
	}
	else{
		alert("Fecha Invalida!");
		campo.focus();
		return false;
	}
}

function comprobarEmail(campo){
	if(campo.value.match(/^[a-z0-9]+([_\\.-][a-z0-9]+)*@([a-z0-9]+([\.-][a-z0-9]+)*)+.[a-z]{2,}$/i)){
		return true;
	}
	else{
		alert("e-mail Invalido!");
		campo.focus();
		return false;
	}
}

function comprobarWeb(campo){
	if(campo.value.match(/[a-z0-9]+.[a-z]{2,4}$/i)){
		return true;
	}
	else{
		alert("URL Invalida!");
		campo.focus();
		return false;
	}
}

function comprobarFormDisenyos(formulario) {

	//Flag de allOK
	var allOK = true;
	var textError = "";
	form = document.getElementById(formulario);

	if (form.ref_form.value=="") {
		textError = "ERROR: Se requiere una referencia.";
		form.ref_form.focus();
		allOK = false;
	}

	if (form.nombre_form.value=="") {
		textError += "\nERROR: Se requiere un nombre.";
		form.nombre_form.focus();
		allOK = false;
	}

	if (!allOK)
		alert(textError);

	return allOK;
};


function comprobarFormBanners(formulario) {

	//Flag de allOK
	var allOK = true;
	var textError = "";
	form = document.getElementById(formulario);

	if (form.ref_form.value=="") {
		textError = "ERROR: Se requiere una referencia.";
		form.ref_form.focus();
		allOK = false;
	}

	if (form.categoria_form.value=="0") {
		textError += "\nERROR: Se requiere una categoria.";
		form.categoria_form.focus();
		allOK = false;
	}

	if (!allOK)
		alert(textError);

	return allOK;
};

function comprobarEditBanners(formulario) {
	if(document.getElementById(formulario).ref_form.value == '')
		return false;
};

function comprobarFormProductos(formulario) {

	//Flag de allOK
	var allOK = true;
	var textError = "";
	form = document.getElementById(formulario);

	if (form.categoria_form.value=="0") {
		textError += "\nERROR: Se requiere una categoria.";
		form.categoria_form.focus();
		allOK = false;
	}

	if (form.ref_form.value=="") {
		textError = "ERROR: Se requiere una referencia.";
		form.ref_form.focus();
		allOK = false;
	}

	if (form.nombre_form.value=="") {
		textError += "\nERROR: Se requiere un nombre.";
		form.nombre_form.focus();
		allOK = false;
	}

	if (form.color_form.value=="") {
		textError += "\nERROR: Se requiere un Color.";
		form.color_form.focus();
		allOK = false;
	}

	if (form.precio_form.value=="") {
		textError += "\nERROR: Se requiere un precio.";
		form.precio_form.focus();
		allOK = false;
	}

	if (form.precio_form.value=="") {
		textError += "\nERROR: Se requiere un precio.";
		form.precio_form.focus();
		allOK = false;
	}

	if (!allOK)
		alert(textError);

	return allOK;
};



function comprobarFormPromociones() {

	//Flag de allOK
	var allOK = true;
	var textError = "";

	if (document.promociones.ref_form.value=="") {
		textError = "ERROR: Se requiere una referencia.";
		document.promociones.ref_form.focus();
		allOK = false;
	}

	if (document.promociones.nombre_form.value=="") {
		textError += "\nERROR: Se requiere un nombre.";
		document.promociones.nombre_form.focus();
		allOK = false;
	}
	
	if (!allOK)
		alert(textError);

	return allOK;
};

function comprobarvender() {

	//Flag de allOK
	var allOK = true;
	var textError = "";

	if (document.venderfinca.nombre.value=="") {
		textError = "ERROR: Se requiere un Nombre.";
		document.venderfinca.nombre.focus();
		allOK = false;
	}

	if (document.venderfinca.telefono.value=="") {
		textError += "\nERROR: Se requiere un Teléfono.";
		document.venderfinca.telefono.focus();
		allOK = false;
	}

	if (document.venderfinca.email.value=="") {
		textError += "\nERROR: Se requiere un e-mail.";
		document.venderfinca.email.focus();
		allOK = false;
	}

	if (!allOK)
		alert(textError);

	return allOK;
};

function comprobarcomprar() {

	//Flag de allOK
	var allOK = true;
	var textError = "";

	if (document.comprarfinca.nombre.value=="") {
		textError = "ERROR: Se requiere un Nombre.";
		document.comprarfinca.nombre.focus();
		allOK = false;
	}

	if (document.comprarfinca.telefono.value=="") {
		textError += "\nERROR: Se requiere un Teléfono.";
		document.comprarfinca.telefono.focus();
		allOK = false;
	}

	if (document.comprarfinca.email.value=="") {
		textError += "\nERROR: Se requiere un e-mail.";
		document.comprarfinca.email.focus();
		allOK = false;
	}

	if (!allOK)
		alert(textError);

	return allOK;
};

function comprobarcontactar() {

	//Flag de allOK
	var allOK = true;
	var textError = "";

	if (document.contactar.nombre.value=="") {
		textError = "ERROR: Se requiere un Nombre.";
		document.contactar.nombre.focus();
		allOK = false;
	}
	
	if (document.contactar.email.value=="") {
		textError += "\nERROR: Se requiere un e-mail.";
		document.contactar.email.focus();
		allOK = false;
	}
	
		if (!comprobarEmail(document.contactar.email)) {
		
		
		allOK = false;
		}
	
	
	if (document.contactar.telcontacto.value=="") {
		textError += "\nERROR: Se requiere un Teléfono de contacto.";
		document.contactar.telcontacto.focus();
		allOK = false;
	}

	if (!allOK)
		alert(textError);

	return allOK;
};



function comprobarcontactarcomprar() {

	//Flag de allOK
	var allOK = true;
	var textError = "";

	if (document.contactarcomprar.nombre.value=="") {
		textError = "ERROR: Se requiere un Nombre.";
		document.contactarcomprar.nombre.focus();
		allOK = false;
	}
	
	if (document.contactarcomprar.email.value=="") {
		textError += "\nERROR: Se requiere un e-mail.";
		document.contactarcomprar.email.focus();
		allOK = false;
	}
	
		if (!comprobarEmail(document.contactarcomprar.email)) {
		
		
		allOK = false;
		}
	
	
	if (document.contactarcomprar.telcontacto.value=="") {
		textError += "\nERROR: Se requiere un Teléfono de contacto.";
		document.contactarcomprar.telcontacto.focus();
		allOK = false;
	}

	if (!allOK)
		alert(textError);

	return allOK;
};



function desactivador(origen, valor, objetivo){
	if(origen.value == valor)
		objetivo.disabled = false
	else
		objetivo.disabled = true;
}

function terrenos(origen){
	desactivador(origen, "1", document.fincas.texto1_form);
	desactivador(origen, "1", document.fincas.texto2_form);
}
