// functions for showing and hiding divs
//
function getRefToDiv(div_ID) {
	if( document.layers ) {
		//Netscape layers
		return document.layers[div_ID];
	}
	if( document.getElementById ) {
		//DOM; IE5, NS6, Mozilla, Opera
		return document.getElementById(div_ID);
	}
	if( document.all ) {
		//Proprietary DOM; IE4
		return document.all[div_ID];
	}
	if( document[div_ID] ) {
		//Netscape alternative
		return document[div_ID];
	}
	return false;
}
function showDiv(divID, action) {
	myReference = getRefToDiv(divID);
	if( !myReference ) {
		window.alert('Nada funciona en este navegador! Por qué no instalas Firefox?');
		return; //don't go any further
	}
	//now we have a reference to it
	if( myReference.style ) {
		//DOM & proprietary DOM
		if (action)
			myReference.style.display = 'block';
		else 
			myReference.style.display = 'none';
	} else {
		//layers syntax
		if (action)
			myReference.display = 'block';
		else 
			myReference.display = 'none';
	}
}
function swapImg(imgId, newImg) {
	myReference = getRefToDiv(imgId);
	if( !myReference ) {
		window.alert('Nada funciona en este navegador! Por qué no instalas Firefox?');
		return; //don't go any further
	}
	//now we have a reference to it
	myReference.src = newImg;
}

//convierte a formato de monedas
function money(amount) {
	var i = parseFloat(amount);
	if(isNaN(i)) { i = 0.00; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	i = parseInt((i + .005) * 100);
	i = i / 100;
	s = new String(i);
	if(s.indexOf('.') < 0) { s += '.00'; }
	if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
	s = minus + s;
	return s;
}

//valida formulario de contacto
function checkForm( form ) {
 var errorCount = 0;
// If the form is empty, display message
    if( isEmpty( form.nombre ) ) {
		document.getElementById('nombre').className = "formCaptionError";
        errorCount++;
    } else {
		document.getElementById('nombre').className = "formCaption";
    }	
// If the email address is not 'valid' display a message
    if( notValidEmail( form.correo1 ) ) {
		document.getElementById('correo1').className = "formCaptionError";
        errorCount++;
    } else {
		document.getElementById('correo1').className = "formCaption";
    }	

// Otherwise, if everything is ok...return true and let the email send.
	if (errorCount) return false;
		else return true;
}
// Checks to see if form element is empty
function isEmpty( str) {
    strRE = new RegExp( );
    strRE.compile( '^[s ]*$', 'gi' );
    return strRE.test( str.value );
}
// Checks to see if email address is 'valid'
function notValidEmail( str ) {
    mailRE = new RegExp( );
    mailRE.compile( '^[._a-z0-9-]+@[.a-z0-9-]+[.]{1}[a-z]{2,4}$', 'gi' );
    return !(mailRE.test( str.value ));
}
//
