// JavaScript Browser Sniffer
// Eric Krok, Andy King, Michel Plungjan Jan. 31, 2002
// see http://www.webreference.com/tools/browser/javascript.html for more information

// convert all characters to lowercase to simplify comparisons
    var agt  = navigator.userAgent.toLowerCase();
    var appVer = navigator.appVersion.toLowerCase();

// *** BROWSER & VERSION ****
    var is_minor  = parseFloat(appVer);
    var is_major  = parseInt(is_minor);
    var is_ie   = (agt.indexOf("msie") != -1);
    var is_ie5up  = (is_ie && (!(is_ie && (is_major < 4))) && (!(is_ie && (is_major == 4) && (agt.indexOf("msie 4")!=-1) )));
    var is_nav  = (agt.indexOf('mozilla')!=-1);
    var is_nav6up = (is_nav && (is_major >= 5));
    var is_gecko = (agt.indexOf('gecko') != -1);

// Note: On IE, start of appVersion return 3 or 4 which supposedly is the version of Netscape it is compatible with.
// So we look for the real version further on in the string
    var iePos  = appVer.indexOf('msie');
    if (iePos !=-1) {
       is_minor = parseFloat(appVer.substring(iePos+5,appVer.indexOf(';',iePos)))
       is_major = parseInt(is_minor);
    }

// *** DOM SUPPORT ***
    var is_all                  = (document.all)                  ? true :false;  //definitve for ie
    var is_layers               = (document.layers)               ? true :false;  //definitive for old Netscape
    var is_getElementById       = (document.getElementById)       ? true :false;  //return ref to a unique page element
    var is_getElementsByName    = (document.getElementsByName)    ? true :false;  //return array of ALL elems having same name
    var is_getElementsByTagName = (document.getElementsByTagName) ? true :false;  //return array of child tags on selected node
    var is_documentElement      = (document.documentElement)      ? true :false;  //return ref to XML/HTML doc root node
    var is_documentBody         = (document.body)                 ? true :false;  //return ref to HTML <body> tag
    var is_option               = (window.Option)                 ? true :false;  //javascript 1.0 did not support form Select Options

// *** FEATURE SUPPORT ***
    var is_anchors  = (document.anchors)? true :false;
    var is_regexp   = (window.RegExp)   ? true :false;
    var is_images   = (document.images) ? true :false;
    var is_forms    = (document.forms)  ? true :false;
    var is_links    = (document.links)  ? true :false;
    var is_frames   = (window.frames)   ? true :false;
    var is_screen   = (window.screen)   ? true :false;
    var is_cookie   = (document.cookie) ? true :false;

// *** JAVA ***
    var is_java = (navigator.javaEnabled());

// If you can see this you are using Javascript, ECMAScript or proprietory Microsoft JScript and there is little value therefore
// checking for javascript suppport. We will test for javascript versions but remember that MS Jscript version numbering has little
//relationship to either javascript or ecmascript:
    var is_js = true;
    // NOTE: In the future, update this code when newer versions of JS
    // are released. For now, we try to provide some upward compatibility
    // so that future versions of Nav and IE will show they are at
    // *least* JS 1.x capable. Always check for JS version compatibility
    // with > or >=.
    if (is_nav || is_ie3){
        is_js = 1.0;
    } else if (is_nav){
        is_js = 1.1;
    } else if ((is_nav4 && (is_minor > 4.05)) || is_ie5up){
        is_js = 1.3;
    }else if (is_nav6up || is_gecko){
        is_js = 1.5;
    } else {
        is_js = 2.0;
    }

/*
Purpose  : Generic Forms validator
Algorithm: i)  determine which fields are required, optional or neither
           ii) for non-blank required/optional fields validate for data-type
           iii)for required option-groups validate the selected/checked
           Validation for special values relates to business rules and should be implemented separately,
           eg. function Validation(oForm){if (genericValidator(oForm) && specificBusinessRules(oForm)) {...}
Usage    :
  1. insert this into document HEAD
    <script type="text/javascript" language="javascript" src="../formvalidator.js"></script>

  2. insert 'required' or 'optional' attribute as necessary (can be done in code too) e.g.
    <tr>
      <td>Location of carts :</td>
      <td><input type="text" name="Store" size="8" required="number"></input></td>
      <td><script type="text/javascript">paintRequired();</script></td>
      </tr>

  3. DELETE existing form "onsubmit=..." AND
  4. REPLACE '<input type="submit"...'
  5. TO '<input type="button" onclick="if (genericValidator(this.form)){this.form.submit();}" '(or similar)

INDEX of Functions:
  function genericValidator(oForm) {
  function IsBlank(sValue) {
  function msgNotEmpty(sName){
  function msgNotApprop(sValue,sName){
  function msgOptionNotSelected(sName) {
  function IsAppropriate(oElement,sDataType,sCountry) {
  function RegExpTest(sRegName,sValue){
  function RegStateZipTest(sDataType,sDataValue,sCountry) {
  function IsValidDate(sValue) {
  function stripNonDigits(str) {
  function isYear(y) {
  function getFebDays(y) {
  function getNonFebDays(iMonth) {
  function isIntRange(s,a,b) {

Last Modified Author/Date : Peter Lamm, Friday November 22, 2002
*/

function genericValidator(oForm){
  //Finds Required or Optional fields and validates while error-checking
  var sType = "";
  var sCountry = "";
  for (var i=0; i < oForm.elements.length; i++) {
    var oElement=oForm.elements[i];
    if (oElement.getAttribute('required') ? true: false) {
      sType = oElement.getAttribute('required') ;

      if (IsBlank(oElement.value)) {

        msgNotEmpty(oElement.name);
        oElement.focus();
        return false;

      } else if (oElement.getAttribute('required')=="option") {
        //Option group controls each have an appropriate value... test if any is checked!

        var oGrp=oForm.elements(oElement.name);
        var IsChecked = false;
        for (var j=0; j<oGrp.length; j++) {
          //alert(oGrp[j].name+"."+oGrp[j].value);
          if (oGrp[j].checked) {
            IsChecked = true;
            break;
          }
        }
        if (!IsChecked) {
          msgOptionNotSelected(oElement.name);
          oElement.focus();
          return false;
        }

      } else if (!IsAppropriate(oElement,sType,sCountry)) {
          msgNotApprop(oElement.value,oElement.name);
          oElement.focus();
          return false;
      }

    } else if (oElement.getAttribute('optional') ? true: false) {

      if (!IsBlank(oElement.value)) {
        if (oElement.value!=oElement.defaultValue) {

          sType = oElement.getAttribute('optional') ;
          if (!IsAppropriate(oElement,sType,sCountry)) {
            msgOptionalNotApprop(oElement.value,oElement.name);
            oElement.focus();
            return false;
          }
        }
      }
    }
  }
  if (!IsBlank(document.feedback.email.value)&&!IsBlank(document.feedback.emailconfirm.value)){
		if (document.feedback.emailconfirm.value != document.feedback.email.value){
			alert('Alert - Your email addresses do not match.');
			return false;
		}   
  }
  if ((document.feedback.Oakdale.checked == false)&&(document.feedback.CottageGrove.checked == false)&&(document.feedback.Woodbury.checked == false)){
  	  	alert('Alert - Please select a city.');
  	  	return false;
  	}

  //Functions NESTED in genericValidator()

    function msgNotEmpty(sName){
      alert('Alert - Required Field\n\n'+ sName.toUpperCase() +
            ' seems to be empty.\n\nPlease type a suitable value and continue.');
      return false;
    }

    function msgNotApprop(sValue,sName){
      alert('Alert - Required Field\n\n'+"'"+ sValue +"' is not appropriate for\n\n"+ sName.toUpperCase());
      return false;
    }

    function msgOptionalNotApprop(sValue,sName){
      alert('Alert - Optional Field\n\n'+"'"+ sValue +"' is not appropriate for\n\n"+ sName.toUpperCase());
      return false;
    }

    function msgOptionNotSelected(sName) {
      alert('Alert - A Required Option :'+"'" + sName.toUpperCase() +"'\n\nwas not selected");
      return false;
    }
    function msgEmailsDoNotMatch(sName) {
      alert('Alert - Your email addresses do not match');
      return false;
    }

    function IsAppropriate(oElement,sDataType,sCountry) {
      // control hub... directs all types of validation
      var s = oElement.value;
      switch(sDataType) {
        case '3email':
          return IsValid3email(oElement.value);
        case 'exmail':
          return IsValideXmail(oElement.value);
        case 'text':
          return true;
        default :
          alert(oElement.name.toUpperCase() +
                " is required but cannot be validated\n"+
                "because it has an unknown or mis-typed data type.\n"+
                "Please use the Feedback form to report this issue.");
          return false;
      }
      return RegExpTest(sDataType,s);

    //Functions NESTED in IsAppropriate()

    // Test for missing data
      function IsBlank(sValue) {
        switch(sValue) {
          case NaN:
          case "???":
          case null:
          case 'Null':
          case "undefined":
            return true;
          default:
            //: \S Matches a character other than white space -- equivalent to [^ \f\n\r\t\v]
            var regBlank = /\S/i;
        }
        return !regBlank.test(sValue);
      }

      function RegExpTest(sRegName,sValue){
        //Create associative array of standard Regular Expressions
        switch (sRegName){
          case 'bol':
            this.bol        = /yes|no|true|false|on|off/i;
            break;
          case 'year':
            return IsYear(sValue);
            break;
          default :
            this.country  = /Canada|Mexico|USA/i;
            this.dollar   = /^\d*$|^\d*\.\d{2}$/;
            this.num      = /[0-9]|[0-9].[0-9]/;
            this.tel      = /^\d{10}$/;
            this.time     = /^(\d{1,2}):(\d{1,2})?(\s?([AP]m))?$/i;
        }
      //the next line works because RegExpTest() properties are 'associative' arrays!
        return this[sRegName].test(sValue)? true:false;
      }

      function IsValid3Email(sValue){
        this["email"]  = /^[a-z0-9]+\.[a-z0-9]+@mmm\.com$/i;
        //assume ';' is separator for 2 or more emails
        var A = sValue.split(";");
        for (var i=0; i<A.length; i++){
          if (!this["email"].test(A[i])){
            return false;
          }
        }
        return true;
      }

      function IsValideXmail(sValue){
        this["email"]  = /^\w+([\.-_]?\w+)*@\w+([\.-_]?\w+)*(\.\w{2,3})+$/i;
        //assume ';' is separator for 2 or more emails
        var A = sValue.split(";");
        for (var i=0; i<A.length; i++){
          if (!this["email"].test(A[i])){
            return false;
          }
        }
       	return true;
        
      }

      
    // end-point for function IsAppropriate()
    }
    
    
//end-point for function genericValidator()
  
  return true;
}
/*
//INDEX of Functions:
  function getReference(sID){
  function GetAttribute(oElem,sID){
  function SetAttribute(oElem,sID,sValue){
  function DelAttribute(oElem,sID){
*/

//Purpose: cross-browser tool for obtaining an object reference
  function getReference(sID){
    var oElem = "";
    if (!IsBlank(sID)) {

      if (is_getElementById){
        //W3C Standards compliant (most v5plus browsers)
        oElem = document.getElementById(sID);
        //an element may have a "name" and no "id"...!
        if (!oElem){
          alert("The HTML element '"+ sID +"' has a name\nbut NO 'ID' ATTRIBUTE\n Please have this fixed!");
        }

      } else if (is_all){
        //IE 4plus
        oElem = document.all(sID);

      } else if (is_layers){
        //NE 4plus
        oElem = document.layers[sID];
      }
    }
    return oElem;
  }


//Purpose: cross-browser tools for deleting element attributes...
  function DelAttribute(oElem,sID){
    if (!IsBlank(sID)){
      //IE or GECKO...
      if (is_ie5up || is_nav6up){
        oElem.removeAttribute(sID);
        return true;
      }
    }
    return false;
  }
//Purpose: cross-browser tools for getting element attributes...
  function GetAttribute(oElem,sID){
    if (!IsBlank(sID)){
      //IE or GECKO...
      if (is_ie5up || is_nav6up){
        oElem.getAttribute(sID);
        return true;
      }
    }
    return false;
  }
//Purpose: cross-browser tools for setting element attributes...
  function SetAttribute(oElem,sID,sValue){
    if (!IsBlank(sID)){
      //IE ...
      if (is_ie5up) {
        oElem.setAttribute(sID,sValue);
        return true;
      //GECKO...
      } else if (is_nav6up){
        var oAtt = document.createAttribute(sID);
            oAtt.value = sValue;
        oElem.setAttributeNode(oAtt);
        return true;
      }
    }
    return false;
  }


//Purpose: Paint a 'Required' flag in forms
//USEAGE: <script type="text/javascript">paintRequired();</script>
  function paintRequired() {
    var sRequired = "<img align='middle' border='0' src='/gallery/images/forms/RequiredRed.gif'>";
    document.write(sRequired);
  }

//Purpose: Paint an 'Optional' flag in forms
//USEAGE: <script type="text/javascript">paintOptional();</script>
  function paintOptional() {
    var sOptional = "<span class='frmRequired'>Optional</span>";
    document.write(sOptional);
  }
  

// Test for missing data
  function IsBlank(sValue) {
    switch(sValue) {
      case NaN:
      case "???":
      case null:
      case 'Null':
      case "undefined":
        return true;
      default:
        //: \S Matches a character other than white space -- equivalent to [^ \f\n\r\t\v]
        var regBlank = /\S/i;
    }
    return !regBlank.test(sValue);
  }






{
function isEmail(str) {
  return ((str != "") && (str.indexOf("@") != -1) && (str.indexOf(".") != -1));}

function validateForm(form) {
    if(document.feedback.mail_subject.value.length < 1) {
        alert("Please enter your subject");
                document.feedback.mail_subject.focus();
        return false;
      }
    if(document.feedback.message.value.length < 1) {
        alert("Please enter your message");
                document.feedback.message.focus();
        return false;
      }
    if(document.feedback.name.value.length < 1) {
        alert("Please enter your name");
                document.feedback.name.focus();
        return false;
      }
    if( !isEmail(document.feedback.email.value) ){
        alert("Please enter a valid e-mail address");
                document.feedback.email.focus();
        return false;
      }
    if( !isEmail(document.feedback.emailconfirm.value) ){
        alert("Please enter a valid e-mail address");
                document.feedback.emailconfirm.focus();
        return false;
      }
    if ( document.feedback.emailconfirm.value != document.feedback.email.value){
        alert("Your E-mail addresses do not match");
                document.feedback.email.focus();
        return false;
      }
      }
}
//

var str = location.search; 

var parsedStr = str.split("referrer="); 
var val = unescape(parsedStr[1]); 

if(val == "undefined" || val == ""){
	val=document.referrer;
	}

//alert(val); 

document.write("<input type='hidden' name='init_url' value='" + val + "'>"); 

//