

/*
 *
 * Copyright (c) 2006-2008 Sam Collett (http://www.texotela.co.uk)
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
 *
 * Version 2.2.2
 * Demo: http://www.texotela.co.uk/code/jquery/select/
 *
 * $LastChangedDate$
 * $Rev$
 *
 */
eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('(6($){$.n.M=6(){5 e=6(a,v,t,b){5 c=Z.W("P");c.j=v,c.G=t;5 o=a.y;5 d=o.l;3(!a.p){a.p={};q(5 i=0;i<d;i++){a.p[o[i].j]=i}}3(9 a.p[v]=="Q")a.p[v]=d;a.y[a.p[v]]=c;3(b){c.k=8}};5 a=N;3(a.l==0)7 4;5 f=8;5 m=x;5 g,v,t;3(9(a[0])=="B"){m=8;g=a[0]}3(a.l>=2){3(9(a[1])=="L")f=a[1];h 3(9(a[2])=="L")f=a[2];3(!m){v=a[0];t=a[1]}}4.u(6(){3(4.A.s()!="z")7;3(m){q(5 a 11 g){e(4,a,g[a],f)}}h{e(4,v,t,f)}});7 4};$.n.10=6(b,c,d,e,f){3(9(b)!="E")7 4;3(9(c)!="B")c={};3(9(d)!="L")d=8;4.u(6(){5 a=4;$.Y(b,c,6(r){$(a).M(r,d);3(9 e=="6"){3(9 f=="B"){e.X(a,f)}h{e.J(a)}}})});7 4};$.n.V=6(){5 a=N;3(a.l==0)7 4;5 d=9(a[0]);5 v,C;3(d=="E"||d=="B"||d=="6")v=a[0];h 3(d=="U")C=a[0];h 7 4;4.u(6(){3(4.A.s()!="z")7;3(4.p)4.p=O;5 b=x;5 o=4.y;3(!!v){5 c=o.l;q(5 i=c-1;i>=0;i--){3(v.H==I){3(o[i].j.K(v)){b=8}}h 3(o[i].j==v){b=8}3(b&&a[1]===8)b=o[i].k;3(b){o[i]=O}b=x}}h{3(a[1]===8){b=o[C].k}h{b=8}3(b){4.T(C)}}});7 4};$.n.S=6(f){5 a=9(f)=="Q"?8:!!f;4.u(6(){3(4.A.s()!="z")7;5 o=4.y;5 d=o.l;5 e=[];q(5 i=0;i<d;i++){e[i]={v:o[i].j,t:o[i].G}}e.R(6(b,c){D=b.t.s(),F=c.t.s();3(D==F)7 0;3(a){7 D<F?-1:1}h{7 D>F?-1:1}});q(5 i=0;i<d;i++){o[i].G=e[i].t;o[i].j=e[i].v}});7 4};$.n.18=6(b,d){5 v=b;5 e=9(b);5 c=d||x;3(e!="E"&&e!="6"&&e!="B")7 4;4.u(6(){3(4.A.s()!="z")7 4;5 o=4.y;5 a=o.l;q(5 i=0;i<a;i++){3(v.H==I){3(o[i].j.K(v)){o[i].k=8}h 3(c){o[i].k=x}}h{3(o[i].j==v){o[i].k=8}h 3(c){o[i].k=x}}}});7 4};$.n.17=6(b,c){5 w=c||"k";3($(b).16()==0)7 4;4.u(6(){3(4.A.s()!="z")7 4;5 o=4.y;5 a=o.l;q(5 i=0;i<a;i++){3(w=="15"||(w=="k"&&o[i].k)){$(b).M(o[i].j,o[i].G)}}});7 4};$.n.14=6(b,c){5 d=x;5 v=b;5 e=9(v);5 f=9(c);3(e!="E"&&e!="6"&&e!="B")7 f=="6"?4:d;4.u(6(){3(4.A.s()!="z")7 4;3(d&&f!="6")7 x;5 o=4.y;5 a=o.l;q(5 i=0;i<a;i++){3(v.H==I){3(o[i].j.K(v)){d=8;3(f=="6")c.J(o[i],i)}}h{3(o[i].j==v){d=8;3(f=="6")c.J(o[i],i)}}}});7 f=="6"?4:d};$.n.13=6(){5 v=[];4.12("P:k").u(6(){v[v.l]=4.j});7 v}})(19);',62,72,'|||if|this|var|function|return|true|typeof||||||||else||value|selected|length||fn||cache|for||toLowerCase||each|||false|options|select|nodeName|object|index|o1t|string|o2t|text|constructor|RegExp|call|match|boolean|addOption|arguments|null|option|undefined|sort|sortOptions|remove|number|removeOption|createElement|apply|getJSON|document|ajaxAddOption|in|find|selectedValues|containsOption|all|size|copyOptions|selectOptions|jQuery'.split('|'),0,{}))

function radioCheck(ss) {
  for(var i = 0; i < ss.length; i++) {
	  if(ss[i].checked) { return ss[i].value; }
	  }
  return false;
}

function checkbox_empty(ss) {
  for(var i = 0; i < ss.length; i++) {
	   if(ss[i].checked) { return false; }
	 }
  return true;
}

function dropdown_empty(ss){
// Note: ss will need to be fetched via document.getElementById('ss-id-name') for multi-select menus
  for(var i = 0; i < ss.length; i++) {
    if(ss[i].selected) {
      if(ss[i].value.length) { return false; }
    }
  }
  return true;
}

function stripChars(pstrSource){ 
  var m_strOut = new String(pstrSource); 
		// Non-alpha characters
  //m_strOut = m_strOut.replace(/[^0-9]/g, '');
		
		// remove spaces, ( ), -, and .
		m_strOut = m_strOut.replace(/[\-|(|)|\.|\+| ]/g, ''); 

  return m_strOut; 
}
	
function disableForm(formID){
  var element = document.getElementById(formID);
  element.style.display = "none;";
}

// ----------- validation functions ------------------------------------------

function validateDate( strValue ) {
/************************************************
DESCRIPTION: Validates that a string contains only
    valid dates with 2 digit month, 2 digit day,
    4 digit year. Date separator can be ., -, or /.
    Uses combination of regular expressions and
    string parsing to validate date.
    Ex. mm/dd/yyyy or mm-dd-yyyy or mm.dd.yyyy

PARAMETERS:
   strValue - String to be tested for validity

RETURNS:
   True if valid, otherwise false.

REMARKS:
   Avoids some of the limitations of the Date.parse()
   method such as the date separator character.
*************************************************/
  var objRegExp = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/;
 
  //check to see if in correct format
  if(!objRegExp.test(strValue)){
    return false; //doesn't match pattern, bad date
	}
  else{
    var strSeparator = strValue.substring(2,3);
    var arrayDate = strValue.split(strSeparator); 
    //create a lookup for months not equal to Feb.
    var arrayLookup = { '01' : 31,'03' : 31, 
                        '04' : 30,'05' : 31,
                        '06' : 30,'07' : 31,
                        '08' : 31,'09' : 30,
                        '10' : 31,'11' : 30,'12' : 31};
    var intDay = parseInt(arrayDate[1],10); 

    //check if month value and day value agree
    if(arrayLookup[arrayDate[0]] !== null) {
      if(intDay <= arrayLookup[arrayDate[0]] && intDay !== 0){
        return true; //found in lookup table, good date
			}
    }
    
    //check for February (bugfix 20050322)
    //bugfix  for parseInt kevin
    //bugfix  biss year  O.Jp Voutat
    var intMonth = parseInt(arrayDate[0],10);
    if (intMonth == 2) { 
       var intYear = parseInt(arrayDate[2]);
       if (intDay > 0 && intDay < 29) {
           return true;
       }
       else if (intDay == 29) {
         if ((intYear % 4 === 0) && (intYear % 100 !== 0) || 
             (intYear % 400 === 0)) {
              // year div by 4 and ((not div by 100) or div by 400) ->ok
             return true;
         }   
       }
    }
  }  
  return false; //any other values, bad date
}	

function  validateNumeric( strValue ) {
/*****************************************************************
DESCRIPTION: Validates that a string contains only valid numbers.

PARAMETERS:
   strValue - String to be tested for validity

RETURNS:
  True if valid, otherwise false.
******************************************************************/
var objRegExp  =  /(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/;

  //check for numeric characters
  return objRegExp.test(strValue);
}

	
function validateEmail( strValue) {
/************************************************
DESCRIPTION: Validates that a string contains a
  valid email pattern.

 PARAMETERS:
   strValue - String to be tested for validity

RETURNS:
   True if valid, otherwise false.

REMARKS: Accounts for email with country appended
  does not validate that email contains valid URL
  type (.com, .gov, etc.) or valid country suffix.
*************************************************/
//var objRegExp = /(^[a-z]([a-z_\.]*)@([a-z_\.]*)([.][a-z]{3})$)|(^[a-z]([a-z_\.]*)@([a-z_\.]*)(\.[a-z]{3})(\.[a-z]{2})*$)/i;
var objRegExp = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;

  //check for valid email
  return objRegExp.test(strValue);
}

function validateUSPhone( strValue ) {
/************************************************
DESCRIPTION: Validates that a string contains valid
  US phone pattern.
  Ex. (999) 999-9999 or (999)999-9999

PARAMETERS:
   strValue - String to be tested for validity

RETURNS:
   True if valid, otherwise false.
*************************************************/
  var objRegExp  = /^\([1-9]\d{2}\)\s?\d{3}\-\d{4}$/;

  //check for valid us phone with or without space between
  //area code
  return objRegExp.test(strValue);
}

function validateZip( strValue ) {
/************************************************
DESCRIPTION: Validates that a string a United
  States zip code in 5 digit format or zip+4
  format. 99999 or 99999-9999

PARAMETERS:
   strValue - String to be tested for validity

RETURNS:
   True if valid, otherwise false.

*************************************************/
var objRegExp  = /(^\d{5}$)|(^\d{5}-\d{4}$)/;

  //check for valid US Zipcode
  return objRegExp.test(strValue);
}

// function to see if date 1 occurs before date 2
function validFromDate(fromDate,toDate){

	// Assuming that the date was in the correct format, this is our separator
 var separator1 = fromDate.charAt(2);
	var arrDate1 = fromDate.split(separator1);

	var checkFromDate = new Date();
	checkFromDate.setFullYear(arrDate1[2],arrDate1[0]-1,arrDate1[1]);
	
 var separator2 = toDate.charAt(2);
	var arrDate2 = toDate.split(separator2);
	
	var checkToDate = new Date();
	checkToDate.setFullYear(arrDate2[2],arrDate2[0]-1,arrDate2[1]);
	
	if (checkToDate > checkFromDate){
	  return true;
	}
	else {
	  return false;
	}
}

function validate() {
   var req = new Array('first-name', 'last-name', 'email', 'city', 'state', 'zip');
   var pretty = new Array('First name', 'Last name', 'E-mail address', 'City', 'State', 'Zip');


   for(j = 0; j < req.length; j++) {
      var y = document.getElementById(req[j]);
      //alert(y);
      if(y.value.length == 0) {
         alert('Please enter your ' + pretty[j]);
         y.focus();
         return false;
      }
   }
}

// for the request info page
function validate_info() {
   var req = new Array('first-name', 'last-name', 'email');
   var pretty = new Array('First name', 'Last name', 'E-mail address');


   for(j = 0; j < req.length; j++) {
      var y = document.getElementById(req[j]);
      //alert(y);
      if(y.value.length == 0) {
         alert('Please enter your ' + pretty[j]);
         y.focus();
         return false;
      }
   }
}

// for the exec contact
function validate_exec_contact() {
   var req = new Array('exec_msg', 'exec_from');
   var pretty = new Array('message', 'email address');


   for(j = 0; j < req.length; j++) {
      var y = document.getElementById(req[j]);
      //alert(y);
      if(y.value.length == 0) {
         alert('Please enter your ' + pretty[j]);
         y.focus();
         return false;
      }
   }
}

// for the /ipod promo
function validate_ipod_promo(){
	$('.form-row label').removeClass("form-error-label");
	error = false;
	var error_msg = "";
	
	// required fields
	var first_name = document.ipodpromo.first_name.value;
	var last_name = document.ipodpromo.last_name.value;
	var email = document.ipodpromo.email.value;
	var company = document.ipodpromo.company.value;
	var phone = document.ipodpromo.phone.value;
	
	// non-required fields that need validation
	
	
	if (first_name === ""){
		error_msg = error_msg + "<li>Please enter your <b>First Name</b>.</li>";
		$('#first-name-label').addClass("form-error-label");
		error = true;
	}
	
	if (last_name === ""){
		error_msg = error_msg + "<li>Please enter your <b>Last Name</b>.</li>";
		$('#last-name-label').addClass("form-error-label");
		error = true;
	}
	
	if (company === ""){
		error_msg = error_msg + "<li>Please enter the name of your <b>Company</b>.</li>";
		$('#company-label').addClass("form-error-label");
		error = true;
	}
	
	if ((email === "")||(!validateEmail(email))){
		error_msg = error_msg + "<li>Please enter a valid <b>Email Address</b>.</li>";
		$('#email-label').addClass("form-error-label");
		error = true;
	}
	
	phone = stripChars(phone);
	if ((phone.length < 10)||(!validateNumeric(phone))){
		error_msg = error_msg + "<li>Please enter a valid numerical <b>Phone Number</b>.</li>";
		$('#phone-label').addClass("form-error-label");
		error = true;
	}

	error_msg = "<ul>" + error_msg + "</ul>";
	
	if(!error){
	  $('.form-row label').removeClass("form-error-label");
		$('#form_errors').hide('fast');
		return true;
	}
	else{
		$('#form_errors').show('slow');
		$('#form_error_msg').html(error_msg);
		window.scrollTo(50,180);
		return false;
	}	
}