
/****
* remember me code
****************************/
var rememberdocument;
 if(navigator.appVersion.indexOf("Safari") > 0)
    if((rememberdocument = document.getElementById("iwashere")))
        rememberdocument.style.height = "787px";

        function RelocateWindow(location){
        //adaption of original function from zoom.php
            window.location.href=location;
        }
        function AddImage(id){
            var remwindow;
            if(remwindow = document.getElementById("iwashere"))
                remwindow.src = "/safety/Myimages.php?add_image=" + id;
            }

/****
* remember me code
****************************/

     /****
* form submission script
****************************/

function ClearInstructions(T){
       if(T.value.indexOf("Please add any comments or questions you may have.") == 0){
        T.value = "";
        T.style.color = "#000000";
        }
        else
        T.style.color = "#000000";
     }

     function LoadInstructions(T){
        if(T.value == ""){
            T.value = "Please add any comments or questions you may have.";
            T.style.color = "#8D8D8D";
        }
     }

     function Verify(TF,DM){
     var send = 1; 
     var defaultmessage = (DM != '' && DM != 'undefined' && typeof(DM) != 'undefined')? DM : "Thank You for requesting our Materials Sample Packet. It will go out to you the next business day via the U.S. Mail." ;
        for(t=0;t<TF.length;t++){
          if(TF[t].title == "required"){
             if(TF[t].value == ""){
               TF[t].style.backgroundColor = "#FF9595";
               send = 0;
             }
             else if(TF[t].tagName.toLowerCase() == "select"){
               if(TF[t].value < 1){
                 send = 0;
                 TF[t].style.backgroundColor = "#FF9595";
                 TF[t].options[0].style.backgroundColor = "#FF9595";
               }
               else{
                 TF[t].options[0].style.backgroundColor = "#C1FFC1";
                 TF[t].style.backgroundColor = "#C1FFC1";
                 }
             }
             else if(TF[t].name == "gemail" || TF[t].name == "vgemail"){
                if(TF[t].name == "gemail"){
                var refresh = document.getElementsByName(TF[t].name)[0];
                  if(TF[t].value == "" || TF[t].value != TF[(t + 1)].value || !EmailSure(refresh)){
                     send = 0;
                     TF[(t + 1)].style.backgroundColor = "#FF9595";
                     TF[t].style.backgroundColor = "#FF9595";
                  }
                  else{
                    TF[(t + 1)].style.backgroundColor = "#C1FFC1";
                    TF[t].style.backgroundColor = "#C1FFC1";
                  }
                }
             }
             else{
               TF[t].style.backgroundColor = "#C1FFC1";
             }
          }
          else if(TF[t].name == "gemail" || TF[t].name == "vgemail"){
          //if they have entered an email address, we need to validate it
                if(TF[t].name == "gemail" && TF[t].value != ""){
                var refresh = document.getElementsByName(TF[t].name)[0];
                  if(TF[t].value == "" || TF[t].value != TF[(t + 1)].value || !EmailSure(refresh)){
                     send = 0;
                     TF[(t + 1)].style.backgroundColor = "#FF9595";
                     TF[t].style.backgroundColor = "#FF9595";
                  }
                  else{
                    TF[(t + 1)].style.backgroundColor = "#C1FFC1";
                    TF[t].style.backgroundColor = "#C1FFC1";
                  }
                }
                else{
                //they didn't enter an email address, or they removed it.
                  if(TF[t].name == "vgemail" && TF[t].value == "" && TF[(t - 1)].value == ""){
                     TF[t].style.backgroundColor = "#C1FFC1";
                     TF[(t - 1)].style.backgroundColor = "#C1FFC1";
                  }
                  else{
                     TF[t].style.backgroundColor = "#FF9595";
                     //TF[(t - 1)].style.backgroundColor = "#FF9595";
                  }
                }
          }
          else
            TF[t].style.backgroundColor = "#C1FFC1";
        }
        if(send > 0){
          if(TF.id != "mailform")
            alert(defaultmessage);
            TF.submit();
        }
     }

     function EmailSure(T){
     var dot = T.value.indexOf(".");
     var lastdot = T.value.lastIndexOf(".");
     var at = T.value.indexOf("@");
     var pass = 1;
        if(T.value != ""){
          if(dot > 0 && at > 0 && at < lastdot){
            if(T.value.match(/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i) >= 0)
               pass = 0;
          }
          else
              pass = 0;
          if(pass < 1){
             T.style.backgroundColor = "#FF9595";
             T.focus();
             alert("Your email address is invalid, please check it and try again");
             return false;
          }
          if(pass > 0)
            T.style.backgroundColor = "#FFFFFF";
            return true;
        }
     }

  function windowPoP(id,src,groupname){
  var mailbox = document.getElementById("mailbox");
    if(mailbox){
      mailbox.style.display = "block";
      var productid = document.getElementsByName("imagecode")[0];
      var tipe = document.getElementsByName("tipe")[0];
      var group = document.getElementsByName("group")[0];
      if(group && productid && tipe && id != "" && src != ""){
        productid.value = id;
        tipe.value = src;
        group.value = groupname;
      }
      else
        mailbox.style.display = "hidden";
    }
    //else
    //alert("fails");
  }

  function closePoP(){
  var mailbox = document.getElementById("mailbox");
    if(mailbox){
      mailbox.style.display = "none";
      var formvals = document.getElementById("mailform");
      if(formvals){
       for(i=0;i<formvals.length;i++){
        if(formvals[i].type != "button")
            formvals[i].value = '';
        }
        var counter = document.getElementById("atb");
        if(counter)
            counter.innerHTML = 'Available(255) Used (0)';
      }
    }
  }

   function printwin(id,what,group){
        window.open(('/printpop.php?imgid='+id+'&tipe='+what+'&group='+group), "printthis","height=600,width=800,status=0,toolbar=0,location=0,menubar=0,directories=0,scrollbars=1");
  }

  function count_tag_chars(t,e,id,count){
  //alert(t.value.length);
  var maxlen = (count)? count:500 ;
  //var
    document.getElementById(id).innerHTML = 'Available ('+(maxlen - (t.value.length + 1))+') Used ('+ (t.value.length + 1) +')';
    return (t.value.length < maxlen);
  }

     /****
* form submission script
****************************/

/****
* shopping cart image swap
****************************/
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;
  if(!d) d=document;
  p=n.indexOf("?");
  if(0 <p && parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
/****
* shopping cart image swap
****************************/

/****
* visual search zoom
****************************/
function visualSearchZoom(id) {
	var settings = 'status=no,toolbar=no,location=no,menubar=no,directores=no,resizable=yes,scrollbars=auto,height=400,width=540';
	var zoomWindow = window.open("/decal/zoom.php?image="+id,"zoomWindow",settings);
}

function visualSafetySearchZoom(id) {
	var settings = 'status=no,toolbar=no,location=no,menubar=no,directores=no,resizable=yes,scrollbars=auto,height=325,width=755';
	var zoomWindow = window.open("/safety/zoom.php?image="+id,"zoomWindow",settings);
}

function onPageLoad() {
	MM_preloadImages('/_ui/2007/img/getshippingrates2.gif','/_ui/2007/img/shippingtransit2.gif','/_ui/2007/img/addtocart2.gif','/_ui/2007/img/home2.gif','/_ui/2007/img/about2.gif','/_ui/2007/img/contact2.gif','/_ui/2007/img/search2.gif','/_ui/2007/img/freesample2.gif','/_ui/2007/img/bookmark2.gif','/_ui/2007/img/viewcart2.gif');
}

/**********************************************************/

var com_banners4safety_baseCartUrl = 'https://order.store.yahoo.net/cgi-bin/wg-order?yhst-73927439280571';

// add event handlers to quantity inputs
var qtys = [];
var inWarning = false;
$(document).ready(function() {
	qtys = $('#viewForm//input[@type=text]');
    if(qtys != null){
  	qtys.keydown(function() {
  		if (com_banners4safety_getNumTypes(this) >= 1) {
  			com_banners4safety_doShowTooManyTypesWarning();
  			$(this).val('');
  			return false;
  		}
  	});
    }
});

function com_banners4safety_doShowTooManyTypesWarning() {
	if (!inWarning) {
		inWarning = true;
		alert('We\'re sorry. You may only add one product to the cart at a time.');
	}
	inWarning = false;
}

function com_banners4safety_getNumTypes(ignore) {
	var types = 0;
	for (q in qtys) {
		var qty = qtys[q];
		if (parseInt(qty.value) > 0 && ignore != qty) {
			++types;
		}
		else {
			qty.value = (new String(qty.value)).replace(/[^0-9]*/g,'');
		}
	}
	return types;
}

function com_banners4safety_doSubmit() {
	// Test for banners4safety.com
	if( document.location.href.indexOf('banners4safety.com')!=-1 ) {
		window.location.href='http://www.safetybanners.org/current/banners4safety.php';
		return false;
	}

	switch (com_banners4safety_getNumTypes()) {
		case 0:
			alert('Nothing to add: no product selected.');
			return false;
		case 1:
			// get product and quantity
			var productId;
			var quantity;
			for (q in qtys) {
				var qty = qtys[q];
				if (parseInt(qty.value) > 0) {
					productId = qty.name;
					quantity = qty.value;
					break;
				}
			}

			// submit to cart
			$('#pfProductId')[0].value = productId;
			$('#pfQuantity')[0].value = quantity;
			var pf = $('#postForm')[0];
			pf.action = com_banners4safety_baseCartUrl + '+' + productId;
			pf.target = '_self';
			pf.submit();

			break;
		default:
			com_banners4safety_doShowTooManyTypesWarning();
			return false;
	}
}

/*****************************/
/*
var ht = 100;
function scroll() {
	ht = ht + 2;
	var el = document.getElementById("bannersInner");
	el.style.height = ht + "px";
	setTimeout("scroll()", 50);
}

function onPageLoad2() {
	ntg = com_newtechgraphics_Pricing_Main();
	ntg.getPrice();
}
var onLoadArr = new Array();
var _onLoad = function() {
    for (var i=0;i<onLoadArr.length;i++) onLoadArr[i]();
}

function addToCart() {
	if (document.getElementById('addTotal').value == '- call -') {
		return false;
	}
	cartForm = document.getElementById('addCartForm');
	cartForm.action = "http://order.store.yahoo.net/cgi-bin/wg-order?yhst-73927439280571+" + cartForm.vwitem.value;
	cartForm.submit();
}

onLoadArr[onLoadArr.length] = onPageLoad2;
onLoadArr[onLoadArr.length] = loadExts;

// JSX stuff
JSX.setPath('/jsx/');
JSX.useClass('com.newtechgraphics.Pricing.Main');
var ntg = {};
*/

/********************************************************/



//	var interPostDelay = 2500;
//	var perPostDelay = 2500;
//	var additionalDelay = 2000;
//	var els = $('#viewForm')[0].elements;
//
//	// determine number of types and, if there is only one, record as singleType
//	var productId;
//	var quantity;
//	for (q in qtys) {
//		var qty = qtys[q];
//		if (parseInt(qty.value) > 0) {
//			productId = qty.name;
//			quantity = qty.value;
//			break;
//		}
//	}
//
//	for (var i = 0; i < els.length; ++i) {
//		if (parseInt(els[i].value) > 0) {
//			++numTypes;
//			singleType.productId = els[i].name;
//			singleType.quantity = els[i].value;
//		}
//	}
//
//
//	$('#pfProductId')[0].value = productId;
//	$('#pfQuantity')[0].value = quantity;
//	var pf = $('#postForm')[0];
//	pf.action = com_banners4safety_baseCartUrl + '+' + productId;
//	pf.target = target;
//	pf.submit();
//
//
//	if (numTypes == 1) { // single type
//		com_banners4safety_doIframePost(singleType.productId, singleType.quantity, 1, '_self');
//	}
//	else { // multiple types
//		var itemCount = 0;
//
//		for (var i = 0; i < els.length; ++i) {
//			if (parseInt(els[i].value) > 0) {
//				var productId = els[i].name;
//				var quantity = els[i].value;
//				++itemCount;
//				setTimeout('com_banners4safety_doIframePost("' + productId + '", ' + quantity + ', ' + itemCount + ', "iframe_' + itemCount + '")', (itemCount - 1) * interPostDelay);
//			}
//		}
//		setTimeout('document.location.href = "' + com_banners4safety_baseCartUrl + '";', (itemCount * perPostDelay + additionalDelay));
//		$('#placingOrder').show();
////		setTimeout('alert("going to cart NOW")', (itemCount * perPostDelay + additionalDelay));
//	}
//}

//function com_banners4safety_doIframePost(productId, quantity, count, target) {
//	$('<iframe name="iframe_' + count + '" style="position: absolute; left: -1000px; top: -300px; width: 900px; height: 275px" />').appendTo("body");
////	$('<iframe name="iframe_' + count + '" style="position: absolute; left: 0px; top: ' + ((count - 1)*300) + 'px; width: 900px; height: 275px" />').appendTo("body");
//
//	$('#pfProductId')[0].value = productId;
//	$('#pfQuantity')[0].value = quantity;
//	var pf = $('#postForm')[0];
//	pf.action = com_banners4safety_baseCartUrl + '+' + productId;
//	pf.target = target;
//	pf.submit();
//}
//-->


/*********************************************************/
/****
* visual search zoom
****************************/
/****
* MenuManager
****************************/
var M_M;// = new MenuManager();
/****
* MenuManager
****************************/
