
// Example: obj = findObj("image1");
function preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.p) d.p=new Array();
    var i,j=d.p.length,a=preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.p[j]=new Image; d.p[j++].src=a[i];}}
}


function swapImage() { //v3.0
  var i,j=0,x,a=swapImage.arguments; document.sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=findObj(a[i]))!=null){document.sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function findObj(theObj, theDoc)
{
  var p, i, foundObj;
  
  if(!theDoc) theDoc = document;
  if( (p = theObj.indexOf("?")) > 0 && parent.frames.length)
  {
    theDoc = parent.frames[theObj.substring(p+1)].document;
    theObj = theObj.substring(0,p);
  }
  if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
  for (i=0; !foundObj && i < theDoc.forms.length; i++) 
    foundObj = theDoc.forms[i][theObj];
  for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++) 
    foundObj = findObj(theObj,theDoc.layers[i].document);
  if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);
  
  return foundObj;
}

function nameColor(cname){
	var myobj;
	myobj = findObj("colorName");
	if(cname==0){
		myobj.value = "";
	}else{
		myobj.value = cname;
	}
}

function nameInputColor(cname,inputName){
	var myobj;
	myobj = findObj(inputName);
	if(cname==0){
		myobj.value = "";
	}else{
		myobj.value = cname;
	}
}

function listColor(cname,listname){
	var myobj;
	myobj = findObj(listname);
	
	if(cname==0){
		myobj.value = "";
	}else{
		myobj.value = cname;
	}
}
var popUpWin = 0;
function MM_openBrWindow(theURL,winName,features) { //v2.0


  window.open(theURL,winName,features);
  
   if(popUpWin)
  {
    if(!popUpWin.closed) popUpWin.close();
  }
}

function clearInput(formName,inputName){
	var theForm = findObj(formName);
	theForm[inputName].value = '';
}

function checkProduct(formName,productNumber)
{
	
	var theForm = findObj(formName);
	var missing = false;
	theForm['error'+productNumber].value = '';
	theForm['prodSize'+productNumber].className = 'formText';
	theForm['prodColor'+productNumber].className = 'formText';
	
	if ( theForm['prodQty'+productNumber].value != '0' )
	{
		if ( theForm['prodColor'+productNumber].value == '0' ) 
		{
			theForm['prodColor'+productNumber].className = 'error';
			theForm['error'+productNumber].value += 'No selecciono ningun color. ';
			missing = true;
		}
		if ( theForm['prodSize'+productNumber].value == '0' ) 
		{
			theForm['prodSize'+productNumber].className = 'error';
			theForm['error'+productNumber].value += 'No selecciono ninguna talla. ';
			missing = true;
			
		}
	}	

	return !missing;
}

function validateContactForm(formName){
	var theForm = findObj(formName);
	var missing = false;
	var errors = '';	
	
	if ( theForm['email'].value != '' )	{
		
		if(checkEmail(theForm['email'])){
				
		}else{
			errors += 'No insertó una dirección de correo válida.<br>';	
		}
		
	}else{
		errors += 'No insertó Correo Electrónico.<br>';	
	}
	
	
	if(theForm['cliente'].value == '')
	{
		errors += 'No ha insertado su nombre.<br>';
	}
	
	if(theForm['comentario'].value == '')
	{
		errors += 'No ha insertado un comentario.<br>';
	}
	
	if(errors == ''){
		missing = true;
	}
	
	document.getElementById("spanErrors").innerHTML=errors;
	
	return missing;
		
}

function checkEmail(email) {
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email.value)){
		return (true)
	}
		/*alert("Invalid E-mail Address! Please re-enter.")*/
		return (false)
}
