//
/*
// 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;
}
// OLD function for money formatting
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;
}
*/
function formatCurrency(num) {
	num = num.toString().replace(/\$|\,/g,'');
	if (isNaN(num)) num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num * 100 + 0.50000000001);
	cents = num % 100;
	num = Math.floor(num / 100).toString();
	if (cents < 10)
	cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length - (1 + i)) / 3); i++)
	num = num.substring(0, num.length-(4 * i + 3)) + ',' + num.substring(num.length-(4 * i + 3));
	return (((sign) ? '' : '-') + num + '.' + cents);
}
//
//forms validator  
// 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 ));
}
// Checks to see if email address is 'valid'
function notValidDate( str ) {
    dateRE = new RegExp( );
    dateRE.compile( '(19|20)[0-9]{2}[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])', 'gi' );
    return !(dateRE.test( str.value ));
}
// Checks to see if password fields doesn't match
/* original 
function doesntMatch( str, str2 ) {
		if (str.value.length && str2.value.length) {
				if (str.value != str2.value) return true;
				return false;
		} else return true;
}
*/
function dontMatch( str, str2 ) {
		if (str.value != str2.value) return true;
		return false;
}
// Checks to see if form element value is numeric
function isNumeric( str ) {
		if (str.value.length == 0) return false;
		for (var i = 0; i < str.value.length; ++i) {   
        var c = str.value.charAt(i);
        if ((c < '0') || (c > '9')) return false;
    }
    return true;
}
//
function jumpField (from, target) {
	if (parseInt(from.value.length) == 4) document.getElementById(target).focus(); else return false;
}
//
// Functions to validate user login and search form
function checkLogin( form ) {
var errorCount = 0;
// If the email address is not 'valid' display a message
	if( notValidEmail( form.usern ) ) {
		document.getElementById('usern').style.background = "url(images/search_error.jpg)";
		errorCount++;
	} else {
		document.getElementById('usern').style.background = "url(images/search_bkg.jpg)";
	}
// If the form is empty, display message
	if( isEmpty( form.passw ) ) {
		document.getElementById('passw').style.background = "url(images/search_error.jpg)";
		errorCount++;
	} else {
		document.getElementById('passw').style.background = "url(images/search_bkg.jpg)";
	}
// Otherwise, if everything is ok...return true and let the email send.
	if (errorCount) return false;
	form.submit();
}
//
function checkSearch( form ) {
	if( isEmpty( form.searchtext ) ) {
		document.getElementById('searchtext').style.background = "url(images/search_error.jpg)";
		return false;
	} else {
		document.getElementById('searchtext').style.background = "url(images/search_bkg.jpg)";
		form.submit();
	}
}
//
function checkSubscribe( form ) {
	if( isEmpty( form.nombre ) || isEmpty( form.correo )) {
		alert("Todos los campos son obligatorios");
		return false;
	}
	if( notValidEmail( form.correo ) ) {
		alert("El e-mail ingresado contiene errores");
		return false;
	}
	return true;
}
//

