// JavaScript Document
function getPicLargeView(picName)
{
	newwin=window.open("LargeView.asp?pictureID="+picName,"displayWindow","toolbar=no,scrollbars=1,width=900,height=1000,top=0,left=0")
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0ss
  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 MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function verify_contactus()
{
	if(document.frmContectenos.Name.value=="")
	{
		alert("Por favor, introduzca su nombre !!!");
		document.frmContectenos.Name.focus();
		return false;
	}
	
	if(document.frmContectenos.phone.value=="")
	{
		alert("Por favor, introduzca su teléfono !!!");
		document.frmContectenos.phone.focus();
		return false;
	}

	if(document.frmContectenos.email.value=="")
	{
		alert("Por favor, introduzca su dirección de correo electrónico !!!");
		document.frmContectenos.email.focus();
		return false;
	}
	if (!isEmailValid())
	{
    	alert("Por favor, introduzca una dirección de correo electrónico válida!!!");
    	document.frmContectenos.email.focus();
    	return false;
	}
	
	return true;
}

function isvalidDigits(){
	var digits="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789@_.-";
	var temp;
	for(var i=0;i<document.frmContectenos.email.value.length;i++){
		temp=document.frmContectenos.email.value.substring(i,i+1);
		if(digits.indexOf(temp)==-1){
			return (false);
		}
	}
	return (true);
}

/*function for checking Email address*/
function isEmailValid(){
	if (!isvalidDigits()){
		return (false);
	}
	var EmailOk  = true;
	var Temp     = document.frmContectenos.email;
	var AtSym    = Temp.value.indexOf('@');
	var Period   = Temp.value.lastIndexOf('.');
	var Space    = Temp.value.indexOf(' ');
	var Dot      = Temp.value.indexOf('.');
	var Length   = Temp.value.length - 1;   // Array is from 0 to length-1

	if ((AtSym < 1) ||                     // '@' cannot be in first position
	    (Period <= AtSym+1) ||             // Must be atleast one valid char btwn '@' and '.'
	    (Period == Length ) ||             // Must be atleast one valid char after '.'
	    (Space  != -1)      ||              // No empty spaces permitted
	    (Dot ==0 )          ||            // No Dot on first position permitted
	    (Dot+1 ==AtSym ))                      // No Dot on first position permitted
	   {
	      EmailOk = false;
	   }
	return (EmailOk);
}

/*function for checking Email address*/
function isDirEmailValid(){
	if (!isvalidDigitsInDirEmail()){
		return (false);
	}
	var EmailOk  = true;
	var Temp     = document.frmDirecEmail.txtDirectionEmail;
	var AtSym    = Temp.value.indexOf('@');
	var Period   = Temp.value.lastIndexOf('.');
	var Space    = Temp.value.indexOf(' ');
	var Dot      = Temp.value.indexOf('.');
	var Length   = Temp.value.length - 1;   // Array is from 0 to length-1

	if ((AtSym < 1) ||                     // '@' cannot be in first position
	    (Period <= AtSym+1) ||             // Must be atleast one valid char btwn '@' and '.'
	    (Period == Length ) ||             // Must be atleast one valid char after '.'
	    (Space  != -1)      ||              // No empty spaces permitted
	    (Dot ==0 )          ||            // No Dot on first position permitted
	    (Dot+1 ==AtSym ))                      // No Dot on first position permitted
	   {
	      EmailOk = false;
	   }
	return (EmailOk);
}
function isvalidDigitsInDirEmail(){
	var digits="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789@_.-";
	var temp;
	for(var i=0;i<document.frmDirecEmail.txtDirectionEmail.value.length;i++){
		temp=document.frmDirecEmail.txtDirectionEmail.value.substring(i,i+1);
		if(digits.indexOf(temp)==-1){
			return (false);
		}
	}
	return (true);
}

function verify_checkout()
{
	if(document.frmContectenos.Name.value=="")
	{
		alert("Por favor, introduzca su nombre !!!");
		document.frmContectenos.Name.focus();
		return false;
	}
	
	if(document.frmContectenos.zip.value=="")
	{
		alert("Por favor, introduzca el código postal !!!");
		document.frmContectenos.zip.focus();
		return false;
	}
	
	if(document.frmContectenos.phone.value=="")
	{
		alert("Por favor, introduzca su teléfono !!!");
		document.frmContectenos.phone.focus();
		return false;
	}

	if(document.frmContectenos.email.value=="")
	{
		alert("Por favor, introduzca su dirección de correo electrónico !!!");
		document.frmContectenos.email.focus();
		return false;
	}
	if (!isEmailValid())
	{
    	alert("Por favor, introduzca una dirección de correo electrónico válida!!!");
    	document.frmContectenos.email.focus();
    	return false;
	}
	if(document.frmContectenos.ccNumber.value=="")
	{
		alert("Por favor, introduzca su número de tarjeta de crédito !!!");
		document.frmContectenos.ccNumber.focus();
		return false;
	}
	else
	{
		if(document.frmContectenos.CCtype.value == "V")
		{
			
			if(!isVisa(document.frmContectenos.ccNumber.value))
			{
				alert("Por favor, introduzca un visado válido número de tarjeta de crédito  !!!");
				document.frmContectenos.ccNumber.focus();
				return false;
			}
		 }
			
	 }
	if(document.frmContectenos.CCtype.value=="0")
	{
		alert("Por favor seleccione su tipo de tarjeta de crédito !!!");
		document.frmContectenos.CCtype.focus();
		return false;
	}
	if(document.frmContectenos.exmonth.value=="0")
	{
		alert("Por favor seleccione su tarjeta de crédito expiración mes !!!");
		document.frmContectenos.exmonth.focus();
		return false;
	}
	if(document.frmContectenos.exyear.value=="0")
	{
		alert("Por favor, slect su tarjeta de crédito expiración año !!!");
		document.frmContectenos.exyear.focus();
		return false;
	}
	if(document.frmContectenos.CVV.value=="")
	{
		alert("Por favor, introduzca su número CVV !!!");
		document.frmContectenos.CVV.focus();
		return false;
	}
	
	//HERE
	return true;
}

function isVisa(cc)
{
	
	if (((cc.length == 16) || (cc.length == 13)) && (cc.substring(0,1) == 4))
	return LuhnCheck(cc);
	return false;
}
function LuhnCheck(str) 
{
	
	var result = true;

	var sum = 0; 
	var mul = 1; 
	var strLen = str.length;

	for (i = 0; i < strLen; i++) 
	{
		var digit = str.substring(strLen-i-1,strLen-i);
		var tproduct = parseInt(digit ,10)*mul;
		if (tproduct >= 10)
 			sum += (tproduct % 10) + 1;
		else
			sum += tproduct;
		
		if (mul == 1)
			mul++;
		else
			mul--;
	}

	if ((sum % 10) != 0)
		result = false;
	else
		result = true;

	return result;
}
function GetByCategory(strPath)
{
	document.frmCategories.action = strPath;
	document.frmCategories.submit();	
}

