// this function toggles the status of a list
function toggle(list){ 
	var listElementStyle=document.getElementById(list).style;
	var more_text = list + "_moretext";
	var listElementText=document.getElementById(more_text);
	
	if (listElementStyle.display=="none"){ 
		listElementStyle.display="block"; 
		listElementText.innerHTML = "- Hide";
	}
	else{ 
		listElementStyle.display="none";
		listElementText.innerHTML = "+ More";
	} 
};

/* 
  ------------------------------------
  PVII Menu CSS Express Drop-Down Menu
  by Project Seven Development
  www.projectseven.com

  ------------------------------------
*/
function P7_ExpMenu(){ //v1.1.0.2 by PVII-www.projectseven.com
 	if(navigator.appVersion.indexOf("MSIE")==-1){
		return;
	}
 	var i,k,g,lg,r=/\s*p7hvr/,nn='',c,cs='p7hvr',bv='p7menubar';
 	for(i=0;i<10;i++){
		g=document.getElementById(bv+nn);
		if(g){
			lg=g.getElementsByTagName("LI");
			if(lg){
				for(k=0;k<lg.length;k++){
					lg[k].onmouseover=function(){
						c=this.className;cl=(c)?c+' '+cs:cs;
						this.className=cl;
					};
					lg[k].onmouseout=function(){
						c=this.className;
						this.className=(c)?c.replace(r,''):'';
					};
				}
			}
		}
		nn=i+1;
	}
};

function popUp(url,width,height,scroll,winname,toolbar,location) {
if (!winname)
 winname = "win";
if (winname == '')
 winname = "win";
if (!toolbar)
 toolbar = 0;
if (!location)
 location = 0;
sealWin=window.open(url,winname,"toolbar="+toolbar+",location="+location+",directories=0,status=0,menubar=0,scrollbars="+scroll+",resizable=1,width="+width+",height="+height);
self.name = "mainWin";sealWin.focus();};
 


function compareProducts() {
	if(!(parseInt(navigator.appVersion) < 4)) {
		if(validate(window.document.compare) != false) {
			window.document.compare.submit();
		}
	}
	else {
		window.document.compare.submit();
	}
};

function validate(myform) {
	if(!(parseInt(navigator.appVersion) < 4)) {
		var value = 0;		
		if (myform != null) {
			for (var i = 0; i < myform.elements.length; i++) {
				if (myform.elements[i].checked) {
					value++;
				}
			}
		}
		if (value < 1) {
			alert('This feature allows you to do side-by-side comparisons of products. To use this feature, please "check" the boxes of the products you would like to compare.');
			return false;
		}
		else if (value > 20) {
			alert('We are sorry but the comparison is limited to 20 products.');
			return false;	
		}
	}
};

// email sign up on left nav
function confirmationText(emailSiteId) {
	if(emailSiteId != 669)
		http('get',"/cart/iso.cfm?detail=emailsignup&email=" + document.email_signup.emailadd.value, completeMsg);
	else
		http('get',"/checkout/checkout_ajax.cfm?func=emailsignup&xml=N&email=" + document.email_signup.emailadd.value, completeMsg);
};

function validateEmail() {
	if(document.email_signup.emailadd.value == ""){
		alert("You must provide an email address! Please try again.");
		return false;
	}
	else if (document.email_signup.emailadd.value.indexOf("@") + "" == "-1" || document.email_signup.emailadd.value.indexOf(".") + "" == "-1"){
		alert("The email address you entered is not valid. Please try again.");
		return false;
	}
	else { 
		confirmationText(document.getElementById("emailSiteId").value);
		return false;
	}
};

// Preretail email sign up on left nav
function preretailValidateEmail() {
	if(document.preretail_email_signup.emailadd.value == ""){
		alert("You must provide an email address! Please try again.");
		return false;
	}
	else if(document.preretail_email_signup.nameadd.value == ""){
		alert("You must provide a name! Please try again.");
		return false;
	}
	else if (document.preretail_email_signup.emailadd.value.indexOf("@") + "" == "-1" || document.preretail_email_signup.emailadd.value.indexOf(".") + "" == "-1"){
		alert("The email address you entered is not valid. Please try again.");
		return false;
	}
	else { 
		return true;
	}
};


function numeric_only(string) {
    for (var i=0, output='', valid="1234567890"; i<string.length; i++)
       if (valid.indexOf(string.charAt(i)) != -1)
          output += string.charAt(i);
    return output;
};

/* bookmark functions for browser compatibility */
var addBookmarkObj = {
  linkText:'Bookmark This Site',
  addTextLink:function(parId){
    var a=addBookmarkObj.makeLink(parId);
    if(!a) return;
    a.appendChild(document.createTextNode(addBookmarkObj.linkText));
  },
  makeLink:function(parId) {
    if(!document.getElementById || !document.createTextNode) return null;
    parId=((typeof(parId)=='string')&&!isEmpty(parId))
      ?parId:'addBookmarkContainer';
    var cont=document.getElementById(parId);
    if(!cont) return null;
    var a=document.createElement('a');
    a.href=location.href;
    if(window.opera) {
      a.rel='sidebar'; 
    } else {
      a.onclick=function() {
        addBookmarkObj.exec(this.href,this.title);
        return false;
      }
    }
    a.title=document.title;
    return cont.appendChild(a);
  },
  exec:function(url, title) {
    var ua=navigator.userAgent.toLowerCase();
    var isKonq=(ua.indexOf('konqueror')!=-1);
    var isSafari=(ua.indexOf('webkit')!=-1);
    var isMac=(ua.indexOf('mac')!=-1);
    var buttonStr=isMac?'Command/Cmd':'CTRL';

    if(window.external && (!document.createTextNode ||
      (typeof(window.external.AddFavorite)=='unknown'))) {
        window.external.AddFavorite(url, title);
    } else if(window.opera) {
      void(0); 
    } else if(window.home || isSafari) { 
      alert('You need to press '+buttonStr+' + D to bookmark our site.');
    } else if(!window.print || isMac) {
      alert('You need to press Command/Cmd + D to bookmark our site.');    
    } else {
      alert('In order to bookmark this site you need to do so manually through your browser.');
    }
  }
};

function isEmpty(s){return ((s=='')||/^\s*$/.test(s));};

function dss_addEvent(el,etype,fn) {
  if(el.addEventListener && (!window.opera || opera.version) &&
  (etype!='load')) {
    el.addEventListener(etype,fn,false);
  } else if(el.attachEvent) {
    el.attachEvent('on'+etype,fn);
  } else {
    if(typeof(fn) != "function") return;
    if(typeof(window.earlyNS4)=='undefined') {
      window.earlyNS4=((navigator.appName.toLowerCase()=='netscape')&&
      (parseFloat(navigator.appVersion)<4.02)&&document.layers);
    }
    if((typeof(el['on'+etype])=="function")&&!window.earlyNS4) {
      var tempFunc = el['on'+etype];
      el['on'+etype]=function(e){
        var a=tempFunc(e),b=fn(e);
        a=(typeof(a)=='undefined')?true:a;
        b=(typeof(b)=='undefined')?true:b;
        return (a&&b);
      }
    } else {
      el['on'+etype]=fn;
    }
  }
};

dss_addEvent(window,'load',addBookmarkObj.addTextLink);

/* hide and show content based on ID */
function hide_show(div_id,img_id,img_off,img_on) {	
	// apply div
	if(document.getElementById)
		var elem = document.getElementById(div_id);
	else if (document.all)
		var elem = document.all[div_id];	
	if (elem.style.display == "" || elem.style.display == "block")
		elem.style.display = "none";
	else
		elem.style.display = "";
	
	// apply image
	if(document.getElementById)
		var img_elem = document.getElementById(img_id);
	else if (document.all)
		var img_elem = document.all[img_id];	
	if (elem.style.display == "")
		img_elem.src = img_on;
	else
		img_elem.src = img_off;
};
/*  This section validates the contact us form */

function checkContactSubmit() {
	
	var error = "no";
	var field_id = "none";
	var error_msg = "none";
	if(document.getElementById("from_name").value == '') {
		error = "yes";
		error_msg = "Please enter a valid name.";
		field_id = "from_name";
	}
	else if(document.getElementById("from_email").value == '') {
		error = "yes";
		error_msg = "Please enter a valid e-mail address.";
		field_id = "from_email";
	}
	else if(document.getElementById("order_num") && document.getElementById("order_num").value == '' && !document.getElementById("no_order_num").checked) {
		error = "yes";
		error_msg = "Please enter an order number or click \"No Order Number?\".";
		field_id = "order_num";
	}
	else if(document.getElementById("subject").value == 'none') {
		error = "yes";
		error_msg = "Please select a Subject for your message.";
		field_id = "subject";
	}
	else if(document.getElementById("message").value == '') {
		error = "yes";
		error_msg = "Please enter a message.";
		field_id = "message";
	}
	else if(document.getElementById("captcha").value == '') {
		error = "yes";
		error_msg = "Please enter the 4 digit code you see in the picture below.";
		field_id = "captcha";
	}
	
	if(error == "yes") {
		alert(error_msg);
		document.getElementById(field_id).focus();
		return false;
	}
	else {
		return true;
	}
};

