function move(x) {
	if (document.all) {
		object1.style.pixelLeft += x;
		object1.style.visibility = "visible"
	}else if (document.layers) {
		document.object1.left += x;
		document.object1.visibility = "show"
	}
};

function makeStatic() {
	if (document.all) {
		object1.style.pixelTop=document.body.scrollTop+20
	}else{
		eval(document.object1.top=eval(window.pageYOffset+20));
	}
	setTimeout("makeStatic()",0);
}


/*--------------------------------------------------
Check the textbox email and return true if is in 
an correct format
--------------------------------------------------*/
function isEmailAddress(theElement, element_name ){
        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 return false;
}

//-----------------------------------------------------------
//Send information to calculate rates ships
//----------------------------------------------------------------
function envio(form,id){ 
        if (isBlank(form.txt_contactS.value) || isBlank(form.txt_addr1S.value) || isBlank(form.txt_cityS.value) || isBlank(form.txt_stateS.value)){
			alert("Please first fill shipping information");                
			form.txt_contactS.focus(true);  
			form.cmb_shipping.value=0;      
        }else{
			form.h_envio.value=id;  
			form.action = '../bins/envioRates.php';  				
			form.submit();          
        }
}


//-------------------------------------------------------------------
// remove spaces function
//   remove any space typed by the user
//-------------------------------------------------------------------
function removeSpaces(string) {
        var tstring = "";
        string = '' + string;
        splitstring = string.split(" ");
        for(i = 0; i < splitstring.length; i++)
        tstring += splitstring[i];
        return tstring;
}


//-----------------------------------
function isBlank(val){
	if(val==null){return true;}
	for(var i=0;i<val.length;i++) {
		if ((val.charAt(i)!=' ')&&(val.charAt(i)!="\t")&&(val.charAt(i)!="\n")&&(val.charAt(i)!="\r")){return false;}
		}
	return true;
	}

function isBlankMessage(campo){
        val=campo.value;
        if(val==null){
        falta+=campo.name;
        falta+="\n";            
        return true;}
        for(var i=0;i<val.length;i++) {
                if ((val.charAt(i)!=' ')&&(val.charAt(i)!="\t")&&(val.charAt(i)!="\n")&&(val.charAt(i)!="\r")){return false;}
                }       
        falta+=campo.name;
        falta+="\n";    
        return true;
        }
/*
	Validar que solo se digitaron numeros en las dos 
	casillas de codigo dearea y codigo de pais
*/
function esCodigo(campo){
	var filter=/[0-9]{1}$/;
	texto=campo.value;
	longitud=texto.length;
	todoBien=true;
	i=0;
	if(longitud!=0){
		while(i<longitud){			
			if(!filter.test(texto.charAt(i))){
				todoBien=false;
			}
			i++;
		}
	}
	return todoBien;
}

//-----------------------------------
function  isPhone(theElement){
	var s = theElement.value;
	var filter=/[0-9]{3}[-]{1}[0-9]{4}$/;
	if (filter.test(s))	return true;
	else{
		theElement.focus(true);
	 	return false;
	}
}


//-----------------------------------
function  SpecialCharacters(theElement){
	var s = theElement.value;
	var filter=/[0-9]{3}[-]{1}[0-9]{4}$/;
	if (filter.test(s))	return true;
	else{
		alert("");
	}
}


/*-----------------------------------------------
Selected country and it modifications.
theElement: where we are.
zip: field that contain zip code.
caja: textbox to disappear or appear
combo: combobox to disappear or appear
form: the form where the combo is.
-----------------------------------------------*/
function  WhichCountry(theElement,zip,caja,combo,form){
	var country= theElement.value;		
	if (country=="CA" || country=="US" || country=="BR"){
		zip.style.backgroundColor='#FFFFFF';
		zip.disabled=false;
	}else{
		zip.style.backgroundColor='#CCCCCC';
		zip.value="";
		zip.disabled=true;
	}

	if(country=="US"){
		combo.style.display="";
		caja.style.display="none";
		caja.value="NOTHING";           
	}else{
		combo.style.display="none";
		caja.style.display="";
		if(caja.value=="NOTHING"){
			caja.value="";                          
		}
	}
	
	
	if(form.cmb_shipping.value!=0){	
		form.cmb_shipping.value=0;
		envio(form,form.cmb_shipping.value);		
	}	
	
	if(country=="CR"){
		form.cmb_shipping.value=1;		
		form.h_fueEnvio.value=1;
		form.cmb_shipping.disabled=true;		
	}else{
		if(form.cmb_shipping.disabled==true){
			form.cmb_shipping.value=0;	
			form.h_fueEnvio.value=0;
			form.cmb_shipping.disabled=false;			
		}		
	}
	
}

//----------------------------------------
function isPasswordValid(theElement, element_name ){
	var s = theElement.value;
	var filter=/(?!^[0-9]*$)(?!^[a-z]*$)^([a-zA-Z0-9]{6,10})$/;
	if (s.length == 0 ) return true;
	if (filter.test(s))	return true;
	else return false;
}





//-----------------------------------------------------------
function esInteger(e){
	var charCode
	charCode = e.keyCode
	if (charCode < 48 || charCode > 57){
		alert("Please just type numbers!");		 
		return false
	}else{
		return true
	}
}



//-------------------------------
function isString(campo){	
	var	valor=campo.value;
	if(isBlank(valor)){return true;}
	var filter=/^[A-Za-z0-9_&/\-% ]+$/;
	if (filter.test(valor)) {return true;}
	else{return false; }
}

//-----------------------------------
//this function check the validation of the credit card
//----------------------------------
var ccErrorNo = 0;
var ccErrors = new Array ();

ccErrors [0] = "Unknown card type";
ccErrors [1] = "No card number provided";
ccErrors [2] = "Credit card number is in invalid format";
ccErrors [3] = "Credit card number is invalid";
ccErrors [4] = "Credit card number has an inappropriate number of digits";

function CheckCreditCard(cardnumber,cardname){
var cards = new Array();
  cards [0] = {name: "VI",
               length: "13,16",
               prefixes: "4",
               checkdigit: true};
  cards [1] = {name: "MC", 
               length: "16", 
               prefixes: "51,52,53,54,55",
               checkdigit: true};
  cards [2] = {name: "AE", 
               length: "15", 
               prefixes: "34,37",
               checkdigit: true};
  cards [3] = {name: "DI", 
               length: "16", 
               prefixes: "6011",
               checkdigit: true};
                           
  var cardType = -1;
  for (var i=0; i<cards.length; i++) {
    // See if it is this card (ignoring the case of the string)
    if (cardname.toLowerCase() == cards[i].name.toLowerCase()) {
      cardType = i;
      break;
    }
  }
  
  // If card type not found, report an error
  if (cardType == -1) {
     ccErrorNo = 0;
     return false; 
  }

  // Ensure that the user has provided a credit card number
  if (isBlank(cardnumber))  {
     ccErrorNo = 1;
     return false; 
  }
  
  // Now remove any spaces from the credit card number
  var cardNo = removeSpaces(cardnumber);
 
 // Now check the modulus 10 check digit - if required
  if (cards[cardType].checkdigit) {
    var checksum = 0;                                  // running checksum total
    var mychar = "";                                   // next char to process
    var j = 1;                                         // takes value of 1 or 2
  
    // Process each digit one by one starting at the right
    var calc;
    for (i = cardNo.length - 1; i >= 0; i--) {
    
      // Extract the next digit and multiply by 1 or 2 on alternative digits.
      calc = Number(cardNo.charAt(i)) * j;
    
      // If the result is in two digits add 1 to the checksum total
      if (calc > 9) {
        checksum = checksum + 1;
        calc = calc - 10;
      }      
      // Add the units element to the checksum total
      checksum = checksum + calc;
    
      // Switch the value of j
      if (j ==1) {j = 2} else {j = 1};
    } 
  
    // All done - if checksum is divisible by 10, it is a valid modulus 10.
    // If not, report an error.
    if (checksum % 10 != 0)  {
     ccErrorNo = 3;
     return false; 
    }
  }  
  
   // The following are the card-specific checks we undertake.
  var LengthValid = false;
  var PrefixValid = false; 
  var undefined; 

  // We use these for holding the valid lengths and prefixes of a card type
  var prefix = new Array ();
  var lengths = new Array ();
    
  // Load an array with the valid prefixes for this card
  prefix = cards[cardType].prefixes.split(",");
      
  // Now see if any of them match what we have in the card number
  for (i=0; i<prefix.length; i++) {
    var exp = new RegExp ("^" + prefix[i]);
    if (exp.test (cardNo)) PrefixValid = true;
  }
      
  // If it isn't a valid prefix there's no point at looking at the length
  if (!PrefixValid) {
     ccErrorNo = 3;
     return false; 
  }
    
  // See if the length is valid for this card
  lengths = cards[cardType].length.split(",");
  for (j=0; j<lengths.length; j++) {
    if (cardNo.length == lengths[j]) LengthValid = true;
  }
  
  // See if all is OK by seeing if the length was valid. We only check the 
  // length if all else was hunky dory.
  if (!LengthValid){
     ccErrorNo = 4;
     return false;
  };   

 return true;

    
}//end function


function CleanSpaces(form){
	var longitud= form.length;
	for( k=0; k<longitud; k++){
		var name=form[k].name;
				
		if(form[k].type == "text" && !isBlank(form[k].value)){
			 var hilera=form[k].value;
			 form[k].value=removeSpaces(hilera);			 
		}	
		
	}
}


//--------------------------------


function theSame(form,check){
	
   if(check.checked == true){
   		form.cmb_countryS.value=form.cmb_country.value;
   		WhichCountry(form.cmb_countryS,form.txt_codeS,form.txt_stateS,form.cmb_stateS,form);
		form.cmb_stateS.value=form.cmb_state.value;
		form.txt_contactS.value=form.txt_contact.value;
		form.txt_addr1S.value=form.txt_addr1.value;
		form.txt_addr2S.value=form.txt_addr2.value;
		form.txt_cityS.value=form.txt_city.value;
		form.txt_stateS.value=form.txt_state.value;
		form.txt_codeS.value=form.txt_code.value;		
	}else{
		form.cmb_countryS.value="AR";		
		WhichCountry(form.cmb_countryS,form.txt_codeS,form.txt_stateS,form.cmb_stateS,form);
		form.txt_contactS.value="";
		form.txt_addr1S.value="";
		form.txt_addr2S.value="";
		form.txt_cityS.value="";
		form.txt_stateS.value="";
		form.txt_codeS.value="";				
	}
	
}


var patron = new Array(3,4,0)
var patron2 = new Array(1,3,3,3,0)
function mascara(d,sep,pat,nums){
	if(d.valant != d.value){
		val = d.value
		largo = val.length
		val = val.split(sep)
		val2 = ''
		for(r=0;r<val.length;r++){
			val2 += val[r]	
		}
		if(nums){
			for(z=0;z<val2.length;z++){
				if(isNaN(val2.charAt(z))){
					letra = new RegExp(val2.charAt(z),"g")
					val2 = val2.replace(letra,"")
				}
			}
		}
		val = ''
		val3 = new Array()
		for(s=0; s<pat.length; s++){
			val3[s] = val2.substring(0,pat[s])
			val2 = val2.substr(pat[s])
		}
		for(q=0;q<val3.length; q++){
			if(q ==0){
				val = val3[q]
			}
			else{
				if(val3[q] != ""){
					val += sep + val3[q]
					}
			}
		}
		d.value = val
		d.valant = val
		}
}

/*----------------------------------------
used to load the default values in 
newuser.php
----------------------------------------*/
function useZip(){
	document.frm_NewUser.txt_name.focus(true);
	document.frm_NewUser.txt_code.style.backgroundColor='#CCCCCC'; 
	document.frm_NewUser.txt_code.disabled=true;	
	document.frm_NewUser.cmb_state.style.display="none";
}

function updateUser(form){
	 form.txt_name.focus(true);
	 form.txt_code.style.backgroundColor='#CCCCCC'; 
	 form.txt_code.disabled=true;	
	 form.cmb_state.style.display="none";
	
	 form.txt_name.focus(true);
	 form.txt_Uname.style.backgroundColor='#CCCCCC'; 
	 form.txt_Uname.disabled=true;		
}

function ClearComplete(form){
	form.action="CompleteUser.php?vengo=0";
	form.submit();
	form.txt_name.focus(true)
}
