 var SHRSFLAG = "";
 var SHRSFLAGA = new Array();
 var iactive_tab = 1;

function sendForm(img) {

if(document.getElementById("keyword").value=="")
{
    alert("Enter keyword");
    return false;
}
 //document.getElementById("SIACTN").value = img.alt;
 //document.getElementById("theForm").submit();
 return true;
}



function sendFormkw(img) {

if(document.getElementById("PMKYWD").value=="")
{
    alert("Enter keyword");
    return false;
}
 document.getElementById("search").submit();
 return true;
}

function sendFormli(img) {

if(document.getElementById("SIUSER").value=="")
{
    alert("Enter User Id");
    return false;
}
if(document.getElementById("SIPASW").value=="")
{
    alert("Enter Password");
    return false;
}
 document.getElementById("login").submit();
 return true;
}

function sendformmvno(attr,cano,mvno) {
if(attr == "*")
{
    alert("Do not click values with a line through it");
    return false;
}

 document.getElementById("SIACTN").value = "REFINE";
 document.getElementById("SIATTR").value = attr;
 document.getElementById("SICANO").value = cano;
 document.getElementById("SIMVNO").value = mvno;
 document.getElementById("mainform").submit();
 return true;
}

function sendFormactn(actn) {
 document.getElementById("SIACTN").value = actn;
 document.getElementById("mainform").submit();
 return true;
}

function sendFormadd(actn,item,qty,acpt) {


  if (! IsNumeric(qty) || qty == "" )
{
    alert("Please enter a valid Quantity");
    return false;
}
 document.getElementById("SIACTN").value = actn;
 document.getElementById("SIPRNO").value = item;
 document.getElementById("SIPRNOQTY").value = qty;
 document.getElementById("SIACPT").value = acpt;
 document.getElementById("mainform").submit();
 return true;
}

function onEnter(objectid,e,actn,item,qty,acpt){



 //var code;
//        if (!e) var e = window.event;
//        if (e.keyCode) code = e.keyCode;
//        else if (e.which) code = e.which;
//        var character = String.fromCharCode(code);
//        alert('Character was ' + character);



if(e.keyCode==13) {
  sendFormadd(actn,item,qty,acpt);
 }
 return false;
}

function enterallowed()
{
 alert('enterallowed');
 return false;
}

function onEnter2(e,actn){


if(e.keyCode==13) sendFormactn(actn);

 return false;
}

function sendFormdlt(actn,cdno,item) {

answer = confirm("Are you sure you want to delete Item:"+item);
if (! answer){
    return false;
	}

 document.getElementById("SIACTN").value = actn;
 document.getElementById("SICDNODLT").value = cdno;
 document.getElementById("mainform").submit();
 return true;
}

function sendFormactnc(actn,pgm) {
 if (pgm == "WBCART" && actn == "NEXT") {
    if (! checkMail(document.getElementById("SIEMAL").value)) {
      alert("Please enter a valid Email Address");
      return false;
    }
    document.getElementById("SISIN").value = rtrim(document.getElementById("SISIN").value);
    if (document.getElementById("SISIN").value.length >160) {
      alert("Please limit Special Shipping Instructions to 160 characters");
      return false;
    }
 }

 if (pgm == "WBCONT") {
    if (! checkMail(document.getElementById("EMAIL").value)) {
      alert("Please enter a valid Email Address");
      return false;
    }
 }

 if (pgm == "WBUNSB") {
    if (! checkMail(document.getElementById("EMAIL").value)) {
      alert("Please enter a valid Email Address");
      return false;
    }
 }

 if (pgm == "WBCART" && actn == "UPDATE") {
    document.getElementById("SISIN").value = rtrim(document.getElementById("SISIN").value);
    if (document.getElementById("SISIN").value.length >160) {
      alert("Please limit Special Shipping Instructions to 160 characters");
      return false;
    }
 }

 document.getElementById("SIACTN").value = actn;
 document.getElementById("mainform").submit();
 return true;
}

function IsNumeric(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;


   for (i = 0; i < sText.length && IsNumber == true; i++)
      {
      Char = sText.charAt(i);
      if (ValidChars.indexOf(Char) == -1)
         {
         IsNumber = false;
         }
      }
   return IsNumber;

   }

function checkMail(email)
{
   var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
   if (filter.test(email)) return true;
   else return false;
}

function rtrim(stringToTrim) {
	return stringToTrim.replace(/\s+$/,"");
}

function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}

function ltrim(stringToTrim) {
	return stringToTrim.replace(/^\s+/,"");
}


function KeyWord(id,idc,word) {
    if (word == "")
       {
         $(id).className='ajaxwindow_off';
         $(idc).className='ajaxwindowC_off';
         return false;
        }

	var url = "/WBKWLST";
      pm = "PMWORD="+word;
      new Ajax.Request(url, {
	  method: 'get',
	  parameters: pm,
	  onSuccess: function(response) {

      if (response.responseText == "")
       {
         $(id).className='ajaxwindow_off';
         $(idc).className='ajaxwindowC_off';
         return false;
        }

      $(idc).className='ajaxwindowC';
      $(idc).update("Make a selection or<br><u>Click here to close</u>");

      $(id).className='ajaxwindow';
      $(id).update("<TABLE>"+response.responseText+"</TABLE>");

	  },
   	  onFailure: function() {
		$(id).update('Something is wrong...');
	  }
//	  onComplete: function() {
//		$(id).setStyle({ background: '#dfd',color:'red' });
//		$('loader_1').update('');
//	  },
//	  onLoading: function() {
//		$('loader_1').update('<img src="http://www.personalsafetyshop.com/images/contactus.jpg">');
//	  }
	});

    return false;
}

 function closekw(id,idc) {
         $(idc).className='ajaxwindowC_off';
         $(id).className='ajaxwindow_off';

}

function shrs(id,rgno) {

    if (SHRSFLAG == "S")
         {
         $(id).hide();
         SHRSFLAG = "H";
         return false;
         }

    if (SHRSFLAG == "H")
         {
         $(id).show();
         SHRSFLAG = "S";
         return false;
         }

    $(id).className='ajaxwindow';
    SHRSFLAG = "S";
    var url = "/WBSHRS";
      new Ajax.Request(url, {
	  method: 'get',
	  parameters: 'PMAJAX=Y&PMRGNO='+rgno,
	  onSuccess: function(response) {
      $(id).update("<TABLE>"+response.responseText+"</TABLE>");

	  },
   	  onFailure: function() {
		$(id).update('Something is wrong...');
	  }

	});
     return false;
    }

 function shrs2(id,rgno,I) {

    if (SHRSFLAGA[I] == "S")
         {
         $(id).hide();
         SHRSFLAGA[I] = "H";
         return false;
         }

    if (SHRSFLAGA[I] == "H")
         {
         $(id).show();
         SHRSFLAG[I] = "S";
         return false;
         }

    $(id).className='ajaxwindow';
    SHRSFLAGA[I] = "S";
    var url = "/WBSHRS";
      new Ajax.Request(url, {
	  method: 'get',
	  parameters: 'PMAJAX=Y&PMRGNO='+rgno,
	  onSuccess: function(response) {
      $(id).update("<TABLE>"+response.responseText+"</TABLE>");

	  },
   	  onFailure: function() {
		$(id).update('Something is wrong...');
	  }

	});
     return false;
    }


    function menutabonf(id) {
             $(id).className='menutabon';
      }

 function toggleattrbox() {

     if (document.getElementById("SIATBX").value == "1"  )
         {
         $("attrbox1").hide();
         $("attrbox2").show();
         document.getElementById("SIATBX").value = "2";
         return false;
         }

    if (document.getElementById("SIATBX").value == "2")
         {
         $("attrbox2").hide();
         $("attrbox1").show();
         document.getElementById("SIATBX").value = "1";
         return false;
         }

     return false;
    }

function setattrbox() {

     if (document.getElementById("SIATBX").value == "2"  )
         {
         $("attrbox1").hide();
         $("attrbox2").show();
         return false;
         }

    if (document.getElementById("SIATBX").value == "1")
         {
         $("attrbox2").hide();
         $("attrbox1").show();
         return false;
         }

     return false;
    }


 function toggleshipbox() {
         
     if (document.getElementById("SISHIPBOX").value == "2")
         {
         $("shipbox").hide();
         document.getElementById("SISHIPBOX").value = "1";
         return false;
         }

    if (document.getElementById("SISHIPBOX").value == "1")
         {
         $("shipbox").show();
         document.getElementById("SISHIPBOX").value = "2";
         return false;
         }

     return false;
    }

function setshipbox() {

     if (document.getElementById("SISHIPBOX").value == "1")
         {
         $("shipbox").hide();
         return false;
         }

    if (document.getElementById("SISHIPBOX").value == "2")
         {
         $("shipbox").show();
         return false;
         }

     return false;
    }

function setfocus(id) {
   //  alert(id);
    document.getElementById(id).focus();

    }

 function ichangeTab(tab) {
		document.getElementById('itab_'+iactive_tab).className = "";
		document.getElementById('ic_tab_'+iactive_tab).className = "inactive";

		document.getElementById('itab_'+tab).className = "active";
		document.getElementById('ic_tab_'+tab).className = "active";

		iactive_tab = tab;
	}
