// JavaScript Document
/* null checking */
function check_fields(form_name,f_name,d_name,c_array)
{

	var incre=0;
	for (incre=0; incre<c_array; incre++)
	{
		var frm="document."+form_name+"."+f_name[incre]+".value";
		var foc="document."+form_name+"."+f_name[incre];
		
		if(trimSpaces(eval(frm))=="")
		{	
		      alert(d_name[incre]+" is a Required Field !!");
			  var foc_field=eval(foc);
			  foc_field.focus();
			  return false;
		}		
	}
	
	return true;
}

// Validation for Login Form

function checkLoginForm()
{
	
	if(document.frmLogin.txtUserName.value=="")
	{
		alert("Please enter username");
		document.frmLogin.txtUsername.focus();
		document.frmLogin.txtUsername.select();
		return false;
	
	}
	
	if(document.frmLogin.txtPassword.value=="")
	{
		alert("Please enter password");
		document.frmLogin.txtPassword.focus();
		document.frmLogin.txtPassword.select();
		return false;
	
	}
	
	else
	{
		return true;
	}
	
	
}

// End Function 




function trimSpaces(stringValue) 
{
	   // Checks the first occurance of spaces and removes them
	   for(i = 0; i < stringValue.length; i++) 
	   {
		    if(stringValue.charAt(i) != " ") 
		     {			break;		}
	   }
	
	   if(i > 0) 
	   {		stringValue = stringValue.substring(i);	}
	
	   // Checks the last occurance of spaces and removes them
	   strLength = stringValue.length - 1;
	   for(i = strLength; i >= 0; i--) 
	   {
		   if(stringValue.charAt(i) != " ") 
		   {		break;		}
	   }
	
	   if(i < strLength) 
	   {		stringValue = stringValue.substring(0, i + 1);	}
	
	   // Returns the string after removing leading and trailing spaces.
	return stringValue;
}


function checkEmail(emailString)
{
	splitVal = emailString.split('@');
	
	if(splitVal.length <= 1) 
	{
		alert("Please Enter A Valid Email Address !!");
		return false;
	}
	if(splitVal[0].length <= 0 || splitVal[1].length <= 0) 
	{
		alert("Please Enter A Valid Email Address !!");
		return false;
	}
	
	splitDomain = splitVal[1].split('.');
	if(splitDomain.length <= 1) 
	{
		alert("Please Enter A Valid Email Address !!");
		return false;
	}
	
	if(splitDomain[0].length <= 0 || splitDomain[1].length <= 1) 
	{
		alert("Please Enter A Valid Email Address !!");
		return false;
	}
	return true;
}

function checkMail(email)
{
        var str1=email;
        var arr=str1.split('@');
        var eFlag=true;
        if(arr.length != 2)
        {
                eFlag = false;
        }
        else if(arr[0].length <= 0 || arr[0].indexOf(' ') != -1 || arr[0].indexOf("'") != -1 || arr[0].indexOf('"') != -1 || arr[1].indexOf('.') == -1)
        {
                        eFlag = false;
        }
        else
        {
                var dot=arr[1].split('.');
                if(dot.length < 2)
                {
                        eFlag = false;
                }
                else
                {
                        if(dot[0].length <= 0 || dot[0].indexOf(' ') != -1 || dot[0].indexOf('"') != -1 || dot[0].indexOf("'") != -1)
                        {
                                eFlag = false;
                        }

                        for(i=1;i < dot.length;i++)
                        {
                                if(dot[i].length <= 0 || dot[i].indexOf(' ') != -1 || dot[i].indexOf('"') != -1 || dot[i].indexOf("'") != -1 || dot[i].length > 4)
                                {
                                        eFlag = false;
                                }
                        }
                }
        }
                return eFlag;
}


// Function To Check Whether The Value Entered Is A Non Negative Float 

function check_numeric(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;
}



/***********************************************
* Fixed ToolTip script- © Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/
var tipwidth='150px' //default tooltip width
var tipbgcolor='white'  //tooltip bgcolor
var disappeardelay=250  //tooltip disappear speed onMouseout (in miliseconds)
var vertical_offset="-20px" //horizontal offset of tooltip from anchor link
var horizontal_offset="163px" //horizontal offset of tooltip from anchor link

/////No further editting needed

var ie4=document.all
var ns6=document.getElementById&&!document.all

if (ie4||ns6)
document.write('<div id="fixedtipdiv" style="visibility:hidden;width:'+tipwidth+';background-color:'+tipbgcolor+'" ></div>')

function getposOffset(what, offsettype){
var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
var parentEl=what.offsetParent;
while (parentEl!=null){
totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
parentEl=parentEl.offsetParent;
}
return totaloffset;
}


function showhide(obj, e, visible, hidden, tipwidth){
if (ie4||ns6)
dropmenuobj.style.left=dropmenuobj.style.top=-500
if (tipwidth!=""){
dropmenuobj.widthobj=dropmenuobj.style
dropmenuobj.widthobj.width=tipwidth
}
if (e.type=="click" && obj.visibility==hidden || e.type=="mouseover")
obj.visibility=visible
else if (e.type=="click")
obj.visibility=hidden
}

function iecompattest(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function clearbrowseredge(obj, whichedge){
var edgeoffset=(whichedge=="rightedge")? parseInt(horizontal_offset)*-1 : parseInt(vertical_offset)*-1
if (whichedge=="rightedge"){
var windowedge=ie4 && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15
dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
edgeoffset=dropmenuobj.contentmeasure-obj.offsetWidth
}
else{
var windowedge=ie4 && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure)
edgeoffset=dropmenuobj.contentmeasure+obj.offsetHeight
}
return edgeoffset
}

function fixedtooltip(menucontents, obj, e, tipwidth){
if (window.event) event.cancelBubble=true
else if (e.stopPropagation) e.stopPropagation()
clearhidetip()
dropmenuobj=document.getElementById? document.getElementById("fixedtipdiv") : fixedtipdiv
dropmenuobj.innerHTML=menucontents

if (ie4||ns6){
showhide(dropmenuobj.style, e, "visible", "hidden", tipwidth)
dropmenuobj.x=getposOffset(obj, "left")
dropmenuobj.y=getposOffset(obj, "top")
dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+"px"
dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+obj.offsetHeight+"px"
}
}

function hidetip(e){
if (typeof dropmenuobj!="undefined"){
if (ie4||ns6)
dropmenuobj.style.visibility="hidden"
}
}

function delayhidetip(){
if (ie4||ns6)
delayhide=setTimeout("hidetip()",disappeardelay)
}

function clearhidetip(){
if (typeof delayhide!="undefined")
clearTimeout(delayhide)
}

/*-----function to compare the dates-------*/

function compareDates (value1, value2)
{
   var date1, date2;
   var month1, month2;
   var year1, year2;

   date1 = value1.substring (0, value1.indexOf ("-"));
   month1 = value1.substring (value1.indexOf ("-")+1, value1.lastIndexOf ("-"));
   year1 = value1.substring (value1.lastIndexOf ("-")+1, value1.length);

   date2 = value2.substring (0, value2.indexOf ("-"));
   month2 = value2.substring (value2.indexOf ("-")+1, value2.lastIndexOf ("-"));
   year2 = value2.substring (value2.lastIndexOf ("-")+1, value2.length);

   if (year1 > year2) return 1;
   else if (year1 < year2) return -1;
   else if (month1 > month2) return 1;
   else if (month1 < month2) return -1;
   else if (date1 > date2) return 1;
   else if (date1 < date2) return -1;
   else return 0;
} 

function validateQuantity(txtQty)
{
	var txtnumber=document.getElementById("Quantity_"+txtQty).value;
	
	if(!isNumeric(txtnumber)) 
	{
		alert("Please enter numeric value for quantity");
		return false;
	}
	else
	{
		return true;
	}
}

function checknum(evt) {

    evt = (evt) ? evt : window.event
    var charCode = (evt.which) ? evt.which : evt.keyCode
    if (charCode > 31 && (charCode < 48 || charCode > 57 ) ) {
        status = "This field accepts numbers only."
        return false
    }
	
    status = ""
    return true
}

function isNumeric(value) {
  if (value == null || !value.toString().match(/^[-]?\d*\.?\d*$/)) return false;
  return true;
}

function changeCollection(){
frm = document.frmSearchCollection;
frm.submit();
}

var menuids=["sidebarmenu1"] //Enter id(s) of each Side Bar Menu's main UL, separated by commas

function initsidebarmenu(){
for (var i=0; i<menuids.length; i++){
  var ultags=document.getElementById(menuids[i]).getElementsByTagName("ul")
    for (var t=0; t<ultags.length; t++){
    ultags[t].parentNode.getElementsByTagName("a")[0].className+=" subfolderstyle"
  if (ultags[t].parentNode.parentNode.id==menuids[i]) //if this is a first level submenu
   ultags[t].style.left=ultags[t].parentNode.offsetWidth+"px" //dynamically position first level submenus to be width of main menu item
  else //else if this is a sub level submenu (ul)
    ultags[t].style.left=ultags[t-1].getElementsByTagName("a")[0].offsetWidth+"px" //position menu to the right of menu item that activated it
    ultags[t].parentNode.onmouseover=function(){
    this.getElementsByTagName("ul")[0].style.display="block"
    }
    ultags[t].parentNode.onmouseout=function(){
    this.getElementsByTagName("ul")[0].style.display="none"
    }
    }
  for (var t=ultags.length-1; t>-1; t--){ //loop through all sub menus again, and use "display:none" to hide menus (to prevent possible page scrollbars
  ultags[t].style.visibility="visible"
  ultags[t].style.display="none"
  }
  }
}

if (window.addEventListener)
window.addEventListener("load", initsidebarmenu, false)
else if (window.attachEvent)
window.attachEvent("onload", initsidebarmenu)

var idstring
var xmlHttprefund

function showRefundAmount(str,shippingfee,vendorfee,adminfee,ids)
{
		
	 idstring=ids
	 
	if (str.length==0)
	{ 
		document.getElementById("txtRefundDisplayHint"+idstring).innerHTML=""
		return
	}
	
	xmlHttprefund=GetXmlHttpObject()
	
	if (xmlHttprefund==null)
	{
		alert ("Browser does not support HTTP Request")
		return
	} 
	
	var url="getrefunddetails.php"
	url=url+"?q="+str+"&shippingfee="+shippingfee+"&vendorfee="+vendorfee+"&adminfee="+adminfee
	url=url+"&sid="+Math.random()
	xmlHttprefund.onreadystatechange=stateChangedrefund
	xmlHttprefund.open("GET",url,true)
	xmlHttprefund.send(null)
	
}//end function 
function stateChangedrefund() 
{ 
	
	
	if (xmlHttprefund.readyState==4 || xmlHttprefund.readyState=="complete")
	{ 
		document.getElementById("txtRefundDisplayHint"+idstring).innerHTML=xmlHttprefund.responseText;
	}//end if 
}//end if


function GetXmlHttpObject()
{ 
	var objXMLHttp=null
	if (window.XMLHttpRequest)
	{
		objXMLHttp=new XMLHttpRequest()
	}//end if
	else if (window.ActiveXObject)
	{
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
	}//end else if
	return objXMLHttp
}//end function 

function validateZipCode(elementValue){
    var zipCodePattern = /^\d{5}$|^\d{5}-\d{4}$/;
     return zipCodePattern.test(elementValue);
}


function displayShippingPackets(str)
{
		
	 
	if (str.length==0)
	{ 
		document.getElementById("divPacketDisplay").innerHTML=""
		return
	}
	
	xmlHttpShipping=GetXmlHttpObject()
	
	if (xmlHttpShipping==null)
	{
		alert ("Browser does not support HTTP Request")
		return
	} 
	
	var url="shipping_ajax_options.php"
	url=url+"?shipmode="+str
	url=url+"&sid="+Math.random()
	xmlHttpShipping.onreadystatechange=stateChangedShipping
	xmlHttpShipping.open("GET",url,true)
	xmlHttpShipping.send(null)
	
}//end function 

function stateChangedShipping() 
{ 
	if (xmlHttpShipping.readyState==4 || xmlHttpShipping.readyState=="complete")
	{ 
		//Code Modified Author:Sreehari Date:2010/07/26 Purpose:To show Proceed button
		var buttons = xmlHttpShipping.responseText.split('||@||');
		document.getElementById("divPacketDisplay").innerHTML=buttons[0];
		document.getElementById("divProceedButton").innerHTML=buttons[1];
	}//end if 
	else
	{
		document.getElementById("divPacketDisplay").innerHTML ='<table width="100%" cellpadding="2" cellspacing="2" style="background-color:#FFFFFF;"><tr><td style="background-color:#FFFFFF;"><img src="'+subdomainUrl+'/js/images/ajax_loader.gif"><br><b>Please Wait ..Loading Shipping Rates ...</b></td></tr></table>';
	}
}//end if
