/* COMBINATOR START: common.js */
function doValidation(form) {
	$('status').removeClassName('errorfy');

	posturl = siteurl + '/wp-content/themes/default/do_form_validation.php';
	el = $('status');
	parameters = $(form).serialize();

	if(c4glang == "EN" || c4glang == "CAN")
		$(el).innerHTML = 'Sending...';
	else
		$(el).innerHTML = 'Mandando...';
	new Effect.Appear(el);

	var v = new Ajax.Request(posturl, {
		method: 'post',
		parameters: parameters,
		asynchronous:true,
		evalScripts:true,
		onSuccess: function(request){
			if(request.responseText == ''){
			}
			else{
				$(el).innerHTML = request.responseText;
			}
		}
	});
}

function Validator(frmname)
{
  this.formobj=document.forms[frmname];
	if(!this.formobj)
	{
	  alert("BUG: couldnot get Form object "+frmname);
		return;
	}
	if(this.formobj.onsubmit)
	{
	 this.formobj.old_onsubmit = this.formobj.onsubmit;
	 this.formobj.onsubmit=null;
	}
	else
	{
	 this.formobj.old_onsubmit = null;
	}
	this.formobj.onsubmit=form_submit_handler;
	this.addValidation = add_validation;
	this.setAddnlValidationFunction=set_addnl_vfunction;
	this.clearAllValidations = clear_all_validations;
	//this.AllowNoDups = AllowNoDups;
}

function V2validateData(strValidateStr,objValue,strError)
{
    var epos = strValidateStr.search("=");
    var  command  = "";
    var  cmdvalue = "";
    if(epos >= 0)
    {
     command  = strValidateStr.substring(0,epos);
     cmdvalue = strValidateStr.substr(epos+1);
    }
    else
    {
     command = strValidateStr;
    }
    switch(command)
    {
        case "req":
        case "required":
         {
           if(eval(objValue.value.length) == 0)
           {
              if(!strError || strError.length ==0)
              {
				if(c4glang == "EN" || c4glang == "CAN") {
					strError = objValue.name + " : Required Field";
				} else  {
					//ES
					strError = objValue.name + " : Campo Requerido";
				}
              }//if
              alert(strError);
              return false;
           }//if
           break;
         }//case required
        case "maxlength":
        case "maxlen":
          {
             if(eval(objValue.value.length) >  eval(cmdvalue))
             {
               if(!strError || strError.length ==0)
               {
					if(c4glang == "EN" || c4glang == "CAN") {
						strError = objValue.name + " : "+cmdvalue+" characters maximum ";
					} else  {
						//ES
						strError = objValue.name + " : "+cmdvalue+" maximo caracters ";
					}

               }//if
               //alert(strError + "\n[Current length = " + objValue.value.length + " ]");
							 alert(strError);
               return false;
             }//if
             break;
          }//case maxlen
        case "minlength":
        case "minlen":
           {
             if(eval(objValue.value.length) <  eval(cmdvalue))
             {
               if(!strError || strError.length ==0)
               {
					if(c4glang == "EN" || c4glang == "CAN") {
						strError = objValue.name + " : " + cmdvalue + " characters minimum  ";
					} else  {
						//ES
						strError = objValue.name + " : " + cmdvalue + " minimo caracters  ";
					}
               }//if
               //alert(strError + "\n[Current length = " + objValue.value.length + " ]");
							 alert(strError);
               return false;
             }//if
             break;
            }//case minlen
        case "alnum":
        case "alphanumeric":
           {
              var charpos = objValue.value.search("[^A-Za-z0-9]");
              if(objValue.value.length > 0 &&  charpos >= 0)
              {
               if(!strError || strError.length ==0)
                {
					if(c4glang == "EN" || c4glang == "CAN") {
						strError = objValue.name+": Only alpha-numeric characters allowed ";
					} else  {
						//ES
						strError = objValue.name+": Solo Se Permiten Caracters Alfa-Numericos ";
					}
                }//if
                //alert(strError + "\n [Error character position " + eval(charpos+1)+"]");
								alert(strError);
                return false;
              }//if
              break;
           }//case alphanumeric
		case "alnumspace":
		case "alphanumerichyphenspace":
           {
              var charpos = objValue.value.search("[^A-Za-z0-9\- ]");
              if(objValue.value.length > 0 &&  charpos >= 0)
              {
               if(!strError || strError.length ==0)
                {
					if(c4glang == "EN" || c4glang == "CAN") {
						strError = objValue.name+": Only alpha-numeric characters and space allowed ";
					} else  {
						//ES
						strError = objValue.name+": Solo Se Permiten Caracters Alfa-Numericos ";
					}
                }//if
                //alert(strError + "\n [Error character position " + eval(charpos+1)+"]");
								alert(strError);
                return false;
              }//if
              break;
           }//case alphanumericspace
		case "alphanumericspace":
           {
              var charpos = objValue.value.search("[^A-Za-z0-9 ]");
              if(objValue.value.length > 0 &&  charpos >= 0)
              {
               if(!strError || strError.length ==0)
                {
					if(c4glang == "EN" || c4glang == "CAN") {
						strError = objValue.name+": Only alpha-numeric characters and space allowed ";
					} else  {
						//ES
						strError = objValue.name+": Solo Se Permiten Caracters Alfa-Numericos ";
					}
                }//if
                //alert(strError + "\n [Error character position " + eval(charpos+1)+"]");
								alert(strError);
                return false;
              }//if
              break;
           }//case alphanumericspace
        case "num":
        case "numeric":
           {
              var charpos = objValue.value.search("[^0-9]");
              if(objValue.value.length > 0 &&  charpos >= 0)
              {
                if(!strError || strError.length ==0)
                {
                  if(c4glang == "EN" || c4glang == "CAN") {
						strError = objValue.name+": Only digits allowed ";
					} else  {
						//ES
						strError = objValue.name+": Solo digitos permite ";
					}
                }//if
                //alert(strError + "\n [Error character position " + eval(charpos+1)+"]");
								alert(strError);
                return false;
              }//if
              break;
           }//numeric
        case "numspace":
           {
              var charpos = objValue.value.search("[^0-9 ]");
              if(objValue.value.length > 0 &&  charpos >= 0)
              {
                if(!strError || strError.length ==0)
                {
                  if(c4glang == "EN" || c4glang == "CAN") {
						strError = objValue.name+": Only digits allowed ";
					} else  {
						//ES
						strError = objValue.name+": Solo digitos permite ";
					}
                }//if
                //alert(strError + "\n [Error character position " + eval(charpos+1)+"]");
								alert(strError);
                return false;
              }//if
              break;
           }//numeric
        case "NumberPlusMinusSpaceParenthesisForwardSlash":
           {
              var regex = /[^0-9 \+\-\(\)\/]/
              var charpos = objValue.value.search(regex);
              if(objValue.value.length > 0 &&  charpos >= 0)
              {
                alert(strError);
                return false;
              }//if
              break;
           }//numeric
        case "alphabetic":
        case "alpha":
           {
              var charpos = objValue.value.search("[^A-Za-z]");
              if(objValue.value.length > 0 &&  charpos >= 0)
              {
                  if(!strError || strError.length ==0)
                {
					if(c4glang == "EN" || c4glang == "CAN") {
						strError = objValue.name+": Only alphabetic characters allowed ";
					} else  {
						//ES
						strError = objValue.name+": Solo Se Permiten Caracters Alfabeticos ";
					}
                }//if
                //alert(strError + "\n [Error character position " + eval(charpos+1)+"]");
								alert(strError);
                return false;
              }//if
              break;
           }//alpha
		case "alnumhyphen":
			{
              var charpos = objValue.value.search("[^A-Za-z0-9\-_]");
              if(objValue.value.length > 0 &&  charpos >= 0)
              {
                  if(!strError || strError.length ==0)
                {
					if(c4glang == "EN" || c4glang == "CAN") {
						strError = objValue.name+": characters allowed are A-Z,a-z,0-9,- and _";
					} else  {
						//ES
						strError = objValue.name+": Caracters Permitidos Son A-Z, a-z, 0-9,-y_";
					}
                }//if
                //alert(strError + "\n [Error character position " + eval(charpos+1)+"]");
								alert(strError);
                return false;
              }//if
			break;
			}
		case "alphahyphenspace":
			{
              var charpos = objValue.value.search("[^A-Za-z\-_ ]");
              if(objValue.value.length > 0 &&  charpos >= 0)
              {
                  if(!strError || strError.length ==0)
                {
					if(c4glang == "EN" || c4glang == "CAN") {
						strError = objValue.name+": characters allowed are A-Z,a-z,0-9, , - and _";
					} else  {
						//ES
						strError = objValue.name+": Caracters Permitidos Son A-Z, a-z, 0-9,-y_";
					}

                }//if
                //alert(strError + "\n [Error character position " + eval(charpos+1)+"]");
								alert(strError);
                return false;
              }//if
			break;
			}
		case "nl_postal_validation": 
            {
                var regex = /^[0-9]{4}(\s{1})?[A-Za-z]{2}$/
                var charpos = objValue.value.search(regex);
                if(objValue.value.length > 0 &&  charpos == -1)
                {
                    if(!strError || strError.length ==0)
                    {	
                        strError = objValue.name+": Check postal code.";		
                        alert(strError); 
                    }
                    alert(strError);
                    return false;
                }
				else
				{
					// insert space if none is present
					if (objValue.value.substr(4, 1) != " ")
					{
						var ints = objValue.value.substr(0, 4);
						var chars = objValue.value.substr(4, 2);
						objValue.value = ints + " " + chars;
					}					
				}
                break;
            }
		case "heinouscharactersnonumbers": 
            {
                var regex = /[0-9\~\`\!\@\#\$\%\^\&\*\(\)\_\+\=\\\]\[\|\}\{\;\"\:\/\.\,\?\>\<]/
                var charpos = objValue.value.search(regex);
                if(objValue.value.length > 0 &&  charpos >= 0)
                {
                    if(!strError || strError.length ==0)
                    {	
                        strError = objValue.name+": No 0-9 ~ ` ! @ # $ % ^ & * ( ) _ + = - ] [ | } { ; \" : / . , ? > < \\";		
                        alert(strError); 
                    }
                    alert(strError);
                    return false;
                }//if
                break;
            }
        case "heinouscharactersallownumbers": 
            {
                var regex = /[\~\`\!\@\#\$\%\^\&\*\(\)\_\+\=\\\]\[\|\}\{\;\"\:\/\.\,\?\>\<]/
                var charpos = objValue.value.search(regex);
                if(objValue.value.length > 0 &&  charpos >= 0)
                {
                    if(!strError || strError.length ==0)
                    {	
                        strError = objValue.name+": No ~ ` ! @ # $ % ^ & * ( ) _ + = - ] [ | } { ; \" : / . , ? > < \\";
                        alert(strError); 
                    }
                    alert(strError);
                    return false;
                }//if
                break;
            }
		case "spanishPhoneNumber": 
            {
                var regex = /[\~\`\!\@\#\$\%\^\&\*\_\+\=\\\]\[\|\}\{\;\"\:\/\.\,\?\>\<]/
                var charpos = objValue.value.search(regex);
                if(objValue.value.length > 0 &&  charpos >= 0)
                {
                    if(!strError || strError.length ==0)
                    {	
                        strError = objValue.name+": No ~ ` ! @ # $ % ^ & * ( ) _ + = - ] [ | } { ; \" : / . , ? > < \\";
                        alert(strError); 
                    }
                    alert(strError);
                    return false;
                }
				else
				{
					// need to replace invalid characters...
					var string = objValue.value;
					objValue.value = string.replace(/[^0-9]/g, "");
				}
				
                break;
            }
		case "phone":
			{
              var charpos = objValue.value.search("[^A-Za-z0-9\-_]");
              if(objValue.value.length > 0 &&  charpos >= 0)
              {
                  if(!strError || strError.length ==0)
                {
					if(c4glang == "EN" || c4glang == "CAN") {
						strError = objValue.name+": characters allowed are A-Z,a-z,0-9,- and _";
					} else  {
						//ES
						strError = objValue.name+": Caracters Permitidos Son A-Z, a-z, 0-9,-y_";
					}

                }//if
                //alert(strError + "\n [Error character position " + eval(charpos+1)+"]");
								alert(strError);
                return false;
              }//if
			break;
			}//end phone
        case "email":
          {
               if(!validateEmailv2(objValue.value))
               {
                 if(!strError || strError.length ==0)
                 {
					if(c4glang == "EN" || c4glang == "CAN") {
						strError = objValue.name+": Enter a valid Email address ";
					} else  {
						//ES
						strError = objValue.name+": Entre Un Email Valido ";
					}

                 }//if
                 alert(strError);
                 return false;
               }//if
           break;
          }//case email
        case "lt":
        case "lessthan":
         {
            if(isNaN(objValue.value))
            {
              alert(objValue.name+": Should be a number ");
              return false;
            }//if
            if(eval(objValue.value) >=  eval(cmdvalue))
            {
              if(!strError || strError.length ==0)
              {
					if(c4glang == "EN" || c4glang == "CAN") {
						strError = objValue.name + " : value should be less than "+ cmdvalue;
					} else  {
						//ES
						strError = objValue.name + " : Valor De be Ser Menos De "+ cmdvalue;
					}

              }//if
              alert(strError);
              return false;
             }//if
            break;
         }//case lessthan
        case "gt":
        case "greaterthan":
         {
            if(isNaN(objValue.value))
            {
              alert(objValue.name+": Should be a number ");
              return false;
            }//if
             if(eval(objValue.value) <=  eval(cmdvalue))
             {
               if(!strError || strError.length ==0)
               {
					if(c4glang == "EN" || c4glang == "CAN") {
						strError = objValue.name + " : value should be greater than "+ cmdvalue;
					} else  {
						//ES
						strError = objValue.name + " : Valor Debe Ser Mas Grande Que "+ cmdvalue;
					}

               }//if
               alert(strError);
               return false;
             }//if
            break;
         }//case greaterthan
        case "regexp":
         {
		 	if(objValue.value.length > 0)
			{
				if(!objValue.value.match(cmdvalue))
				{
					if(!strError || strError.length ==0)
					{
						if(c4glang == "EN" || c4glang == "CAN") {
							strError = objValue.name+": Invalid characters found ";
						} else  {
							//ES
							strError = objValue.name+": Caracters Invalidos Encontrados ";
						}
					}//if
					alert(strError);
					return false;
				}//if
			}
           break;
         }//case regexp
        case "check":
         {
            //if(objValue.selectedIndex == null)
            //{
            //  alert("BUG: dontselect command for non-select Item");
            //  return false;
            //}

            if(!objValue.checked)
            {
                if(!strError || strError.length ==0)
                {
                    if(c4glang == "EN" || c4glang == "CA") {
                        alert("Please agree you are over 21 and have read our terms and conditions.");
                    } else  {
                        //ES
                        alert("Por Favor Confirme Que Es Mayor De 21 Anos De Edad Y Que Ha Leido Nuestros Terminos Y Condiciones.");
                    }
                }//if
                alert(strError);
                return false;
            }


             break;
         }//case dontselect

	case "dontselect":
         {
            if(objValue.selectedIndex == null)
            {
              alert("BUG: dontselect command for non-select Item");
              return false;
            }
            if(objValue.selectedIndex == eval(cmdvalue))
            {
             if(!strError || strError.length ==0)
              {
				if(c4glang == "EN" || c4glang == "CAN") {
					strError = objValue.name+": Please Select one option ";
				} else  {
					//ES
					strError = objValue.name+": Seleccione una opcion ";
				}

              }//if
              alert(strError);
              return false;
             }
             break;
         }//case dontselect
    }//switch
	
    return true;
}

function AllowNoDups()

{
   var date = new Date();
   date.setTime(date.getTime()+(1*3*60*60*1000));

   var expires = "expires="+date.toGMTString();

   var cookie_ls = document.cookie;
   if (cookie_ls.indexOf("cash4gold") > -1)
   {
		if(c4glang == "EN" || c4glang == "CAN") {
			alert("A Refiner's Return Kit has already been requested from this computer. \nPlease wait at least 3 hours before requesting additional kits. \nYour Road to Cash has begun!\n\nSincerely - Cash4Gold.com");
		} else  {
			//es
			alert("Un Kit (Pak) de Refinador de Regreso ya ha sido pedido de esta computadora. \nFavor de esperar por lo menos 3 horas antes de pedir un Kit (Pak) adicional. \nSu camino hacia Dinero ha empesado! \n\nSinceramente - DineroPorOro.com ");
		}
      return false;
   }
   else
   	{
      document.cookie = "cash4goldfrom " + document.referrer + "; path=/; "  + expires;
      return true;
   }
}

function set_addnl_vfunction(functionname)
{
  this.formobj.addnlvalidation = functionname;
}


function clear_all_validations()
{
	for(var itr=0;itr < this.formobj.elements.length;itr++)
	{
		this.formobj.elements[itr].validationset = null;
	}
}

function form_submit_handler()
{
   var date = new Date();
   date.setTime(date.getTime()+(1*3*60*60*1000));

   var expires = "expires="+date.toGMTString();

   var cookie_ls = document.cookie;

   if (cookie_ls.indexOf(document.location) < -1)
   {
		if(c4glang == "EN" || c4glang == "CAN") {
			alert("A Refiner's Return Kit has already been requested from this computer. \nPlease wait at least 3 hours before requesting additional kits. \nYour Road to Cash has begun!\n\nSincerely - Cash4Gold.com");
		} else  {
			//es
			alert("Un Kit (Pak) de Refinador de Regreso ya ha sido pedido de esta computadora. \nFavor de esperar por lo menos 3 horas antes de pedir un Kit (Pak) adicional. \nSu camino hacia Dinero ha empesado! \n\nSinceramente - DineroPorOro.com");
		}
      return false;
   }
   else
   	{



        for(var itr=0;itr < this.elements.length;itr++)
	{
		if(this.elements[itr].validationset &&
	   !this.elements[itr].validationset.validate())
		{
		  return false;
		}
	}

	if(this.addnlvalidation)
	{
	  str =" var ret = "+this.addnlvalidation+"()";
	  eval(str);

       if(!ret) return ret;
	}
	document.cookie = window.location.href + " from " + document.referrer + "; path=/; "  + expires;
	return true;


      return true;
   }

}



function add_validation(itemname,descriptor,errstr)
{
  if(!this.formobj)
	{
	  alert("BUG: the form object is not set properly");
		return;
	}//if
	var itemobj = this.formobj[itemname];
  if(!itemobj)
	{
	  alert("BUG: Couldnot get the input object named: "+itemname);
		return;
	}
	if(!itemobj.validationset)
	{
	  itemobj.validationset = new ValidationSet(itemobj);
	}
  itemobj.validationset.add(descriptor,errstr);
}
function ValidationDesc(inputitem,desc,error)
{
  this.desc=desc;
	this.error=error;
	this.itemobj = inputitem;
	this.validate=vdesc_validate;
}
function vdesc_validate()
{
 if(!V2validateData(this.desc,this.itemobj,this.error))
 {
	if (this.itemobj.type != "hidden")
	{
		this.itemobj.focus();
	}
	
	return false;
 }
 return true;
}
function ValidationSet(inputitem)
{
    this.vSet=new Array();
	this.add= add_validationdesc;
	this.validate= vset_validate;
	this.itemobj = inputitem;
}
function add_validationdesc(desc,error)
{
  this.vSet[this.vSet.length]=
	  new ValidationDesc(this.itemobj,desc,error);
}
function vset_validate()
{
   for(var itr=0;itr<this.vSet.length;itr++)
	 {
	   if(!this.vSet[itr].validate())
		 {
		   return false;
		 }
	 }
	 return true;
}
function validateEmailv2(email)
{
// a very simple email validation checking.
// you can add more complex email checking if it helps

    //removes preceding and trailing spaces so that they are not included in the test.
    email = email.replace(/^\s*/, "").replace(/\s*$/, "");
    
    if(email.length <= 0)
	{
	  return true;
	}
    var splitted = email.match("^(.+)@(.+)$");
    if(splitted == null) return false;
    if(splitted[1] != null )
    {
      var regexp_user=/^\"?[\w-_\.]*\"?$/;
      if(splitted[1].match(regexp_user) == null) return false;
    }
    if(splitted[2] != null)
    {
      var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,4}$/;
      if(splitted[2].match(regexp_domain) == null)
      {
	    var regexp_ip =/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;
	    if(splitted[2].match(regexp_ip) == null) return false;
      }// if
      return true;
    }
return false;
}

function autoTab(input,len, e) {
	var keyCode = (isNN) ? e.which : e.keyCode;
	var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
	if(input.value.length >= len && !containsElement(filter,keyCode)) {
		input.value = input.value.slice(0, len);
		input.form[(getIndex(input)+1) % input.form.length].focus();
	}

	function containsElement(arr, ele) {
	var found = false, index = 0;
	while(!found && index < arr.length)
		if(arr[index] == ele)
			found = true;
		else
			index++;
	return found;
	}

	function getIndex(input) {
	var index = -1, i = 0, found = false;
	while (i < input.form.length && index == -1)
		if (input.form[i] == input)index = i;
		else i++;
			return index;
	}
	return true;
}

function openPopup(url) {
     var w=window.open(url,"","width=600,height=600,scrollbars=yes");
     if (!w) alert('Please allow popups')
     return false;
}

function autoTab(input,len, e) {
	return;
	/*
	var keyCode = (isNN) ? e.which : e.keyCode;
	var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
	if(input.value.length >= len && !containsElement(filter,keyCode)) {
		input.value = input.value.slice(0, len);
		input.form[(getIndex(input)+1) % input.form.length].focus();
	}

	function containsElement(arr, ele) {
	var found = false, index = 0;
	while(!found && index < arr.length)
		if(arr[index] == ele)
			found = true;
		else
			index++;
	return found;
	}

	function getIndex(input) {
	var index = -1, i = 0, found = false;
	while (i < input.form.length && index == -1)
		if (input.form[i] == input)index = i;
		else i++;
			return index;
	}
	return true;
	*/
}
