/*************************************
	DARKBLUE FORM VALIDATIONS
	(C)2007 DarkAngel
	DarkBlue Consulting
	http://www.darkblue.com.ar
	
	Si usas este script por favor coloca un link a nuestro sitio. gracias!
	if you use this script please place a link to our website. thank you!

**/

/*******
** Macromedia Dreamweaver Generated Functions
***/
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function genIsEmpty(oField, sMessage, sPrefix){
	var isOk = false;
	var fType= new String();
	fType=oField.type
	if (fType==undefined){fType=oField[0].type}

	switch(fType){
		case 'textarea':
		case 'text':
			isOk=(oField.value!='');
			break;
		
		case 'select-one':
			isOk=(!(oField[0].selected)); 
			break;

		case 'radio':
		case 'checkbox':
			if(oField.length>0){
				for(i=0; i<oField.length; i++){if(oField[i].checked){isOk=true}}
			}else{
				isOk = (oField.checked)
			}
			break;
		
		default:
			alert ('field: ' + oField.name + '\ntype: ' + fType + '\nvalue: ' + oField.value);
			alert (oField.type)

	}

	if(!(isOk)){
		genShowError(oField, sMessage, sPrefix);
		return true;
	}
	return false;
}

function genIsEmail(oField, sMessage, sPrefix){
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	if (!filter.test(oField.value))
	{
		genShowError(oField, sMessage, sPrefix);
		return true;
	}
	return false;
}

function genIsNumber(oField, sMessage, sPrefix){
	var filter=/(^\d+$)/
	if (!filter.test(oField.value))
	{
		genShowError(oField, sMessage, sPrefix);
		return true;
	}
	return false;
}

function genShowError(oField, sMessage, sPrefix){
	
	if(sPrefix==undefined)
	{alert('Por favor ingrese ' + sMessage);}
	else
	{alert(sPrefix + sMessage);}
	oField.focus();
}

function showInPopup(URL){
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=300,height=300,left = 490,top = 362');");
}	

function gryForm(oForm){
	var oElem=oForm.elements
	var i=new Number();
	for(i=0; i<oElem.length; i++){oElem[i].disabled=true}
}

function swDisplay(sHide, sShow){
	document.getElementById(sHide).style.display='none';
	document.getElementById(sShow).style.display='inline';
}

function getQS(ji) {
	hu = window.location.search.substring(1);
	gy = hu.split("&");
	for (i=0;i<gy.length;i++) {
		ft = gy[i].split("=");
		if (ft[0] == ji) {return ft[1];}
	}
}

function onLoadMsg() {
	var txt = getQS('msg');
	if (!(txt == undefined)){document.write('<p class="msg">' + unescape(txt) + '</p>')}
}

/** image gallery ****************************************************************************************************************************************/

function cmImgGalPreload() {
	var igImg = new Array();
	var a=cmImgGalPreload.arguments;
	var i=new Number();
	for(i=0; i<a.length; i++)
		{
			igImg[i]=new Image();
			igImg[i].src=a[i];
		}
}
function cmImgGalShow(fn, msrc){
	var mp = document.getElementById('igMain').src;
	if (document.getElementById('igMain')){document.getElementById('igMain').src=mp.substring(0,mp.lastIndexOf('/')+1) + msrc;}
	if (document.getElementById('igEpigraph')){document.getElementById('igEpigraph').innerHTML=fn.alt}
}


/** contact ****************************************************************************************************************************************/

function commSendMail(){
	var oForm=document.contactForm;
	if(genIsEmpty(oForm.mxNombre, 'su nombre')){return true;}
	if(genIsEmpty(oForm.mxEmpresa, 'el nombre de su empresa')){return true;}
	if(genIsEmpty(oForm.mxEmail, 'un email para poder contactarlo')){return true;}
	if(genIsEmail(oForm.mxEmail, 'un email VALIDO para poder contactarlo')){return true;}
	if(genIsEmpty(oForm.mxTelefono, 'un telefono para contactarlo')){return true;}
	if(genIsEmpty(oForm.mxPais, 'el pais donde se encuentra')){return true;}
	if(genIsEmpty(oForm.mxProvincia, 'la provincia donde se encuentra (o -No Argentina- si es del exterior)')){return true;}
	if(genIsEmpty(oForm.mxConsulta, 'su consulta')){return true;}
	//gryForm(oForm);
	swDisplay('contactButton', 'contactWait');oForm.submit();
}

function onSendMXres(){
	switch(getQS('mxstat')){
		case 'ok':
			document.write('<p class="msg">Su mensaje fué recibido correctamente.</p>');
			document.getElementById('contact').style.display='none';
			break;
		case 'fail':
			document.write('<p class="msg">Su mensaje no pudo ser recibido, <br>Por favor intente más tarde o notifiquenos por otra vía.<br><br>Disculpe las molestias.</p>');
			break;
	}
}


/** link exchange ****************************************************************************************************************************************/

function addLink_valid(){
	var oForm=document.lnkXchanger;
	if(genIsEmpty(oForm.lnkLink, 'la dirección donde colocó el link a nuestro sitio.')){return true;}
	if(genIsEmpty(oForm.lnkTitle, 'El título de su sitio')){return true;}
	if(genIsEmpty(oForm.lnkUrl, 'la dirección de su sitio web')){return true;}
	if(genIsEmpty(oForm.lnkDescrip, 'una descripción para su sitio web')){return true;}
	if(genIsEmpty(oForm.lnkEmail, 'un email para contactarlo en caso de ser necesario')){return true;}
	if(genIsEmail(oForm.lnkEmail, 'un email VALIDO para poder contactarlo')){return true;}
	if(genIsEmpty(oForm.chkRules, 'aceptar las reglas para intercambiar un enlace', 'debe ')){return true;}
	if(genIsEmpty(oForm.chkPublished, 'agregar el enlace para que podamos validarlo', 'debe ')){return true;}
	//gryForm(oForm);
	swDisplay('btnAddLink', 'lnkPlsWait');oForm.submit();
}