// Functions
// Javascript from egrem_asp
//
function selectOption(opt) {
	document.searchForm.criterio[opt].checked = true
}

function isEmpty(s)	{  
	return ((s == null) || (s.length == 0))
}
function isDigit(c) {   
	return ((c >= "0") && (c <= "9"))
}
function isInteger(s) {
	var i;
    for (i = 0; i < s.length; i++) 
        if (!isDigit(s.charAt(i))) return false;
    return true;
}
function isValidYear(y) {   
    return ((y.length==4)&&(isInteger(y)))          
}
function ValidateForm(f) {
 	var val_srch = f.searchText.value;
	var errors = 0;
	var rad = f.criterio;
	
	if (isEmpty(val_srch)) {
		alert("¡Especifique que desea buscar!");
		errors = 1;
	}else{
		
		if (rad && (rad[3].checked)) { // Dealing with the YEAR
			if (!isValidYear(val_srch)) {
				alert("El año no ha sido especificado de manera correcta.\n"+
					  "Debe teclear la cifra completa. (ej. 1989,2003,etc.)");
			 	errors = 1;
			}
		}else{ // Dealing with Artist/Disc/Song
			if (val_srch.length < 3) {
				alert("Por favor, use un término de más de 3 letras a buscar...");
				errors = 1;			
			}
		}
	}
 	return (errors==0);
}

// Custom Personal Scripts
// 
//
function winPV(pageurl) {
	features = "width=400,height=240";
	win = window.open(pageurl, "tienda", features);
	//alert(features+"--"+win);
}

function showCDCover(cover) {
	features = "width=404,height=404";
	pageurl = "/assets/showcdcover.asp?codigo="+cover;
	win = window.open(pageurl, "cdcovers", features);
	win.focus();
}
function showfoto(foto) {
	features = "width=450,height=338";
	pageurl = "/assets/showfoto.asp?codigo="+foto;
	win = window.open(pageurl, "fotos", features);
	win.focus();
}

function showfoto06(foto) {
	features = "width=450,height=338";
	pageurl = "/assets/showfoto06.asp?codigo="+foto;
	win = window.open(pageurl, "fotos", features);
	win.focus();
}
function showCDCoverO(cover) {
	features = "width=404,height=404";
	pageurl = "/assets/showcdcovero.asp?codigo="+cover;
	win = window.open(pageurl, "original", features);
	win.focus();
}

function showCover(cover) {
	features = "width=364,height=474";
	pageurl = "/assets/showcover.asp?codigo="+cover;
	win = window.open(pageurl, "covers", features);
	win.focus();
}
// Giveit2me4free Borrowed
// Contract/Expand
//
function ref(object)
{
	if (document.getElementById) { return document.getElementById(object);
	} else if (document.all) { return eval('document.all.' + object); }
	else return false;
}

function expand(object)
{
	object = ref(object);
	
	if( !object.style ) return false;
	else object.style.display = '';

	if (window.event) window.event.cancelBubble = true;
}

function contract(object)
{
	object = ref(object);
	
	if( !object.style ) return false;
	else object.style.display = 'none';

	if (window.event) window.event.cancelBubble = true;
}

function inset_toogle(obj_id) {

	the_image = ref(obj_id + '_img');
	obj_id = ref(obj_id);

	if( !obj_id.style ) return false;
	
	if( obj_id.style.display == 'none' )
	{
		obj_id.style.display = '';
		//the_image.src = path + 'contract.gif';
	}
	else
	{
		obj_id.style.display = 'none';
		//the_image.src = path + 'expand.gif';
	}	
}

// Rollon/off for TDs
function rollover(obj, astyle) {
	if (astyle){
		obj.MM_className = obj.className;
		obj.className = astyle;
	}
}
	
function rolloff(obj) {
	if (obj.MM_className){
		obj.className = obj.MM_className;
	}
}
	
function email(theElement)
{
var s = theElement.value;
var filter=/^[A-Za-z][A-Za-z0-9_\-\.]*@[A-Za-z0-9_]+\.[A-Za-z0-9_.]+[A-za-z]$/;
if (s.length == 0 ) return true;
if (filter.test(s))
return true;
else{
   alert('E-mail incorrecto');
   theElement.focus();   
   return false;
  }
}
