/// <reference path="jquery-vsdoc2.js" />
//onerror=handleErr;
function HttpRequestComplete()
{
	if (xmlhttp.readyState==4)
		if (xmlhttp.status==200 && xmlhttpDivId!='')
				document.getElementById(xmlhttpDivId).innerHTML=xmlhttp.responseText;
				
}

function HttpRequest(url)
{
	if (window.XMLHttpRequest)
    {
	    xmlhttp=new XMLHttpRequest()
		xmlhttp.open("GET",url,true)
		xmlhttp.send(null)
		xmlhttp.onreadystatechange = HttpRequestComplete;
    }	// code for IE
	else if (window.ActiveXObject)
	{
	    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		if (xmlhttp)
		{
			xmlhttp.onreadystatechange = HttpRequestComplete;
		    xmlhttp.open("GET",url,true);
			xmlhttp.send();
		}
	}
	return;
}
var xmlhttp;
var xmlhttpDivId;
var xmlhttpDivId1;
var xmlhttpDivId2;
var xmlhttpDivId2ShipId;
var xmlhttpDivId2ZipCode;

if(document.getElementById('divViewcart')!=null)
{
	xmlhttpDivId='divViewcart';
	HttpRequest('/ASPUTil.aspx?query=ItemInCart');
}
setInterval(function(){xmlhttpDivId='';HttpRequest('/ASPUTil.aspx?rand=' + Math.random())},600000);



function handleErr(msg,url,l)
{
	url='/javascripterrorreport.asp?msg=' + msg + '&url=' + url + '&line=' + l;
	xmlhttpDivId='';
	HttpRequest(url,'');
return true;
}

function ShowDiv(id,event)
{
	if (event && document.getElementById(id).style.display=='none')
		document.getElementById(id).style.left=event.clientX-Math.round(document.getElementById(id).style.width.replace('px','')/2);
	if (document.getElementById(id))
		document.getElementById(id).style.display='inline';
}
function HideDiv(id)
{
	if (document.getElementById(id))
		document.getElementById(id).style.display='none';
}

function MoreLessDiv(obj)
{
	tmpObj=obj.parentNode.parentNode.nextSibling;
	if(tmpObj.nodeName=="#text")
		tmpObj=tmpObj.nextSibling;
	if (tmpObj.style.display=='none')
	{
		tmpObj.style.display='';
		obj.className='Less';
	}
	else
	{
		tmpObj.style.display='none';
		obj.className='More';
	}
}

//function MoreLessDivCat(obj)
//{
//	tmpObj=obj.parentNode.parentNode.nextSibling;
//	if(tmpObj.nodeName=="#text")
//		tmpObj=tmpObj.nextSibling;
//	if (tmpObj.style.display=='none')
//	{
//		tmpObj.style.display='';
//		obj.className='Less';
//	}
//	else
//	{
//		tmpObj.style.display='none';
//		obj.className='More';
//	}
//}

function EstimateArrivalWindow(MfrId,ShipId,Zip,Height,Width)
{
	if (Zip.length==0)
	{
		alert("Please Enter Shipping ZipCode.");
		return;
	}
	else
	{
		QStr="zip=" + Zip;
		
		if (MfrId.length>0)
			QStr=QStr + "&MfrId="+MfrId;
		if (ShipId.length>0)
			QStr=QStr + "&ShipId="+ShipId;
			  			
		window.open('ExpectedArrivalDate.aspx?'+QStr,'EAT' ,'width=' + Width + ',height=' + Height + ',top=50,left=50,scrollbars=yes')
		return;
	}
}
//str='';
//str=str + '<table cellspacing="0" cellpadding="0">';
//str=str + '<tr bgcolor="#FFFFFF">';
//str=str + '<td width="50" align="center"><img src="Images/login.gif" width="34" height="32"></td>';
//str=str + '<td width="211"><a href="login.asp?logout=&logintry=1" class="ClsListItem">Login (required for Order<br>tracking, Returns &amp; Exchanges)</a></td>';
//str=str + '<td width="16" rowspan="4" align="center"><img src="Images/Vline.gif" width="16" height="150"></td>';
//str=str + '<td width="50" align="center"><img src="Images/return.gif" width="34" height="32"></td>';
//str=str + '<td width="219"><a href="cservice.asp#Return%20And%20Exchanges:" class="ClsListItem">Returns &amp; Exchanges </a></td>';
//str=str + ' </tr>';
//str=str + '<tr bgcolor="#FFFFFF">';
//str=str + '<td width="50" align="center"><img src="Images/order.gif" width="34" height="32"></td>';
//str=str + '<td><a href="cservice.asp#How%20To%20Order" class="ClsListItem">How To Order</a></td>';
//str=str + '<td width="50" align="center"><img src="Images/shipping.gif" width="34" height="32"></td>';
//str=str + '<td><a href="cservice.asp#ShippingInformationRates" class="ClsListItem">Shipping Information and Rates</a></td>';
//str=str + '</tr>';
//str=str + '<tr bgcolor="#FFFFFF">';
//str=str + '<td width="50" align="center"><img src="Images/price.gif" width="34" height="32"></td>';
//str=str + '<td><a href="cservice.asp#Low%20Price%20guarantee:" class="ClsListItem">Our Low Price Guarantee</a></td>';
//str=str + '<td width="50" align="center"><img src="Images/ppolicy.gif" width="34" height="32"></td>';
//str=str + '<td><a href="cservice.asp#OurPrivacyPolicy" class="ClsListItem">Our Privacy Policy</a></td>';
//str=str + '</tr>';
//str=str + '<tr bgcolor="#FFFFFF">';
//str=str + '<td width="50" align="center"><img src="Images/cancellation.gif" width="34" height="32"></td>';
//str=str + '<td><a href="cservice.asp#Cancellations:" class="ClsListItem">Cancellations</a></td>';
//str=str + '<td width="50" align="center"><img src="Images/contactus1.gif" width="34" height="32"></td>';
//str=str + '<td><a href="ContactUs.asp" class="ClsListItem">Contact Us</a></td>';
//str=str + '</tr>';
//str=str + '</table>';

//if (document.getElementById('CustomerServiceDiv'))
//	document.getElementById('CustomerServiceDiv').innerHTML=str;


function informmepopup(frurl)
{
var hwnd;
hwnd=window.open("informme.aspx?"+frurl,null,"width=450,height=310,resizable=no,location=no,toolbar=no,status=no,menubar=no");
}

function emailCheck (emailStr) 
{
    var checkTLD=1;
    var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
    var emailPat=/^(.+)@(.+)$/;
    var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
    var validChars="\[^\\s" + specialChars + "\]";
    var quotedUser="(\"[^\"]*\")";
    var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
    var atom=validChars + '+';
    var word="(" + atom + "|" + quotedUser + ")";
    var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
    var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
    var matchArray=emailStr.match(emailPat);
    if (matchArray==null) 
    {
        alert("Email address seems incorrect (check @ and .'s)");
        return false;
    }
    var user=matchArray[1];
    var domain=matchArray[2];

    for (i=0; i<user.length; i++) 
    {
        if (user.charCodeAt(i)>127) 
        {
            alert("The username contains invalid characters.");
            return false;
        }
    }

    for (i=0; i<domain.length; i++) 
    {
        if (domain.charCodeAt(i)>127) 
        {
            alert("The domain name contains invalid characters.");
        return false;
        }
    }


    if (user.match(userPat)==null) 
    {
        alert("The username doesn't seem to be valid.");
        return false;
    }

    var IPArray=domain.match(ipDomainPat);
    if (IPArray!=null) {
    for (var i=1;i<=4;i++) {
    if (IPArray[i]>255) {
    alert("Destination IP address is invalid!");
    return false;
       }
    }
    return true;
    }


    var atomPat=new RegExp("^" + atom + "$");
    var domArr=domain.split(".");
    var len=domArr.length;
    for (i=0;i<len;i++) {
    if (domArr[i].search(atomPat)==-1) {
    alert("The domain name does not seem to be valid.");
    return false;
       }
    }


    if (checkTLD && domArr[domArr.length-1].length!=2 && 
    domArr[domArr.length-1].search(knownDomsPat)==-1) {
    alert("The address must end in a well-known domain or two letter " + "country.");
    return false;
    }


    if (len<2) {
    alert("This address is missing a hostname!");
    return false;
    }


    window.location='SaveEmail.aspx?txtEmail=' + emailStr;
    return false;
}   

//------------------------------

/////////
//HideInternvalId=0;
isSuggestionOn='true';
SuggestArrayLength=0;
function SearchKeyPress(obj,e)
{
    if(e.keyCode==13) return goSearch(obj);
}
function SearchOnFocus(obj)
{
    if(obj.value=='Type in your keyword(s) or Style Number')obj.value='';
    
    if(isSuggestionOn=='false')
        document.getElementById('tblShowSuggestion').style.visibility='visible';
}
function SearchOnKeyUp(obj,e)
{   
    if(obj.value.length >= 3)
    {
        if(isSuggestionOn=='true')
        {
            setSuggestion(e,obj.value,document.getElementById('ctl00_SearchTopStrip_Store').value);
        }
    }
}
function ShowSuggetionsOnClick(e)
{
    document.getElementById('tblShowSuggestion').style.visibility='hidden';
    isSuggestionOn='true';
    setSuggestion(e,document.getElementById('ctl00_SearchTopStrip_SearchString').value,document.getElementById('ctl00_SearchTopStrip_Store').value);
    document.getElementById('ctl00_SearchTopStrip_SearchString').focus();
}

function SearchOnBlur()
{
    //HideInternvalId=setInterval("document.getElementById('tblQuickSearch').style.visibility='hidden';ClearSuggestHideInterval();",500);
    //alert('blur');
    if(isSuggestionOn=='true')
        setTimeout("document.getElementById('tblQuickSearch').style.visibility='hidden';",150);
    else
        setTimeout("document.getElementById('tblShowSuggestion').style.visibility='hidden'",150);
}

function HideSuggetionsClick()
{
    isSuggestionOn='false';
    tbl=document.getElementById('tblQuickSearch');
    if(tbl.rows.length-2>CurrentTableRow)
    {
        for(i=0;i<tbl.rows.length-2;i++)
            tbl.deleteRow(i);
    }
    //SearchOnBlur();
    document.getElementById('tblQuickSearch').style.visibility='hidden';
    document.getElementById('ctl00_SearchTopStrip_SearchString').focus();
}
function ClearRowSelection()
{
    tbl=document.getElementById('tblQuickSearch');
        for(i=0;i<tbl.rows.length-2;i++)
            tbl.rows[i].className='';
}


CurrentTableRow=-1;

//return goFreeTextSearch(this.value,false);
function goSearch(obj)
{
    tbl=document.getElementById('tblQuickSearch');
    for(i=0;i<tbl.rows.length-2;i++)
    {
        if(tbl.rows[i].className=='txtSuggestTableSelected')
        {
            obj.value=tbl.rows[i].childNodes[3].value;
            return goFreeTextSearch(tbl.rows[i].childNodes[3].value,false);
        }
        
    }    
    return goFreeTextSearch(obj.value,false);
}
SearchTxt='';
DisplayEvent=null;
function setSuggestion(event,txt,store)
{
//alert(document.getElementById('tblShowSuggestion').style.visibility);
    
    if(document.getElementById('tblShowSuggestion').style.visibility=='hidden')
    {
        SearchTxt=txt;
        if(event.keyCode==38)
        {        
            tbl=document.getElementById('tblQuickSearch');
            for(i=0;i<tbl.rows.length;i++)
                tbl.rows[i].className='';
            if(CurrentTableRow>0)
            {
                tbl.rows[--CurrentTableRow].className='txtSuggestTableSelected';
            }        
        }
        else if(event.keyCode==40 && SuggestArrayLength>1)
        {        
            tbl=document.getElementById('tblQuickSearch');
            if(tbl.rows.length-3>CurrentTableRow)
            {
                for(i=0;i<tbl.rows.length;i++)
                    tbl.rows[i].className='';
                tbl.rows[++CurrentTableRow].className='txtSuggestTableSelected';
            }
        }
        else
        {
            CurrentTableRow=-1;
            if(document.getElementById('tblQuickSearch'))
            {
                xmlhttpDivId1="tblQuickSearch";
                if(txt!="")
                {
                    HttpRequest1("/ASPUTil.aspx?query=Suggestion&TextSuggest=" + txt + "&Store=" + store);
                    DisplayEvent=event;
                //document.getElementById('tblQuickSearch').style.visibility='visible';
                }
                else
                {
                    document.getElementById('tblQuickSearch').style.visibility='hidden';
                }
            }
        }
   }       
}


function HttpRequest1(url)
{
	if (window.XMLHttpRequest)
    {
	    xmlhttp=new XMLHttpRequest();
		
		xmlhttp.onreadystatechange = HttpRequestComplete1;
		xmlhttp.open("GET",url,true);
		xmlhttp.send(null);
    }	// code for IE
	else if (window.ActiveXObject)
	{
	    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		if (xmlhttp)
		{
			xmlhttp.onreadystatechange = HttpRequestComplete1;
		    xmlhttp.open("GET",url,true);
			xmlhttp.send();
		}
	}

	return;
}
function HttpRequestComplete1()
{
	if (xmlhttp.readyState==4)
	{
		if (xmlhttp.status==200)
		{

			if (xmlhttpDivId1=='tblQuickSearch')
			{

			    var txtArr=xmlhttp.responseText.split("|");
			    SuggestArrayLength=txtArr.length;
//			    
//                var temp="";			   
//			    for(i=0;i<txtArr.length-1;i+=2)
//			    {
//			        temp+='<tr onclick="temp(this.value);"><td align="left">'+txtArr[i]+'</td><td align="right">'+txtArr[i+1]+'</td></tr>';   
//			        document.getElementById(xmlhttpDivId1).innerHTML=temp;
//			    }
			    var tbl = document.getElementById(xmlhttpDivId1);
			    for(i=tbl.rows.length-1;i>=0;i--)
			        tbl.deleteRow(i);
			    
			    for(i=0;i<txtArr.length-1;i+=2)
                {
                    var lastRow = tbl.rows.length;
                    var row = tbl.insertRow(lastRow);
                      
                    var cellLeft = row.insertCell(0);
                    cellLeft.align="left";
                    cellLeft.className="txtSuggestLeftfont";                    
                    var re = new RegExp('[ ]*' +SearchTxt,"gi");                    
                    var str=txtArr[i].replace(re," <b>"+ SearchTxt +"</b>");                   
                    cellLeft.innerHTML=str;
                    cellLeft.onclick=function(){
                        document.getElementById("ctl00_SearchTopStrip_SearchString").value=this.parentNode.childNodes[3].value;
                        return goFreeTextSearch(this.parentNode.childNodes[3].value,false);
                        };
                    
                    
                    var cellRight = row.insertCell(1);
                    cellRight.align="right";
                    cellRight.className="txtSuggestRightfont";
                    var textNode2 = document.createTextNode(txtArr[i+1] + " results");
                    cellRight.appendChild(textNode2);
                    cellRight.onclick=function(){
                        document.getElementById("ctl00_SearchTopStrip_SearchString").value=this.parentNode.childNodes[3].value;
                        return goFreeTextSearch(this.parentNode.childNodes[3].value,false);
                        };
                    

                    
                    var count=row.insertCell(2);
                    var c=document.createComment('input');
                    count.type='hidden';
                    if(window.ActiveXObject)    // for IE
                        count.style.setAttribute("padding","0px");
                    else if(window.XMLHttpRequest)  //  for Firefox  
                        count.setAttribute("style","padding:0px");  
                    count.visible='false';
                    count.value=i/2;
                    count.appendChild(c);
                    row.onmouseover=function(){CurrentTableRow=this.childNodes[2].value;ClearRowSelection();this.className='txtSuggestTableSelected';};
                    row.onmouseout=function(){this.className='';};
                    
                    
                    
                    var SearchText=row.insertCell(3);
                    var sT=document.createComment('input');
                    if(window.ActiveXObject)    // for IE
                        SearchText.style.setAttribute("padding","0px");
                    else if(window.XMLHttpRequest)  //  for Firefox  
                        SearchText.setAttribute("style","padding:0px");                      
                    SearchText.type='hidden';                    
                    count.visible='false';
                    SearchText.value=txtArr[i];
                    SearchText.appendChild(sT);
                    
                    //row.onclick=function(){
                    //    document.getElementById("ctl00_SearchTopStrip_SearchString").value=this.childNodes[3].value;
                    //    return goFreeTextSearch(this.childNodes[3].value,false);
                    //    };
                    
            
                }
                if(txtArr.length<=1)
                {
                    var row3=tbl.insertRow(tbl.rows.length);
                    var NoSuggetion=row3.insertCell(0);
                    NoSuggetion.setAttribute("colSpan","4");
                    NoSuggetion.align="right";
                    var textnode3=document.createTextNode("No suggestions");
                    NoSuggetion.appendChild(textnode3);
                }
               // alert(DisplayEvent=="[object MouseEvent]");
                if(txtArr.length<=1 & DisplayEvent!="[object MouseEvent]")
                {
                    //alert('hello');
                    tbl.style.visibility='hidden';
                    //document.getElementById('tblShowSuggestion').style.visibility='hidden';
                    
                    }
                else
                {
                    tbl.style.visibility='visible';    
                   
                var row1 = tbl.insertRow(tbl.rows.length);
                var a=row1.insertCell(0);
                a.setAttribute("colSpan","4");
                var b=document.createElement('hr');
                
                if(window.ActiveXObject)    // for IE
                    b.setAttribute("className","fontColorLabel");
                else if(window.XMLHttpRequest)  //  for Firefox  
                {
                    b.setAttribute("style","height=0px;border:0px;border-top: 2px solid;");
                    //b.setAttribute("class","tblBgcolor");
                    b.setAttribute("class","fontColorLabel");
                }
                a.appendChild(b);
                
                var row2=tbl.insertRow(tbl.rows.length);
                var HideSuggetion=row2.insertCell(0);
                
                HideSuggetion.align="right";
                if(window.ActiveXObject)    // for IE
                {
                    HideSuggetion.setAttribute("className","PageContentLink");
                    HideSuggetion.style.setAttribute("font-size","11px");
                }
                else if(window.XMLHttpRequest)  //  for Firefox  
                {
                    HideSuggetion.setAttribute("class","PageContentLink");  
                    HideSuggetion.setAttribute("style","font-size:11px");
                }
                   
                
                
                var hideLink=document.createElement('a');
                hideLink.innerHTML="Hide Suggestions";
                if(window.ActiveXObject)    // for IE
                    hideLink.style.setAttribute("cursor","pointer");
                else if(window.XMLHttpRequest)  //  for Firefox  
                    hideLink.setAttribute("style","cursor:pointer");  
                   
                
                //hideLink.href="javascript:;";
                hideLink.onclick=HideSuggetionsClick;
                HideSuggetion.setAttribute("colSpan","4");
                HideSuggetion.appendChild(hideLink); 
                
                
                
                if(tbl.rows.length==0)
                    tbl.style.visibility='hidden';
                else
                    tbl.style.visibility='visible';
 //               alert(document.getElementById(xmlhttpDivId1).innerHTML);
                }
			}
			
		}
	}
}

////////


/////////  Shipping Information //////

function HttpRequest2(url)
{
	if (window.XMLHttpRequest)
    {
	    xmlhttp=new XMLHttpRequest();
		
		xmlhttp.onreadystatechange = HttpRequestComplete2;
		xmlhttp.open("GET",url,true);
		xmlhttp.send(null);
    }	// code for IE
	else if (window.ActiveXObject)
	{
	    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		if (xmlhttp)
		{
			xmlhttp.onreadystatechange = HttpRequestComplete2;
		    xmlhttp.open("GET",url,true);
			xmlhttp.send();
		}
	}

	return;
}
function CheckZipCode(obj)
{
    var regExpZip=/^\d{5}(-\d{4})?$/;
    if(obj.value.search(regExpZip)==-1)
    {
        alert('Please enter 5 digit US Zip Code for shipping information');
        return false;
    }
    else 
        return true;
}
function HttpRequestComplete2()
{
	if (xmlhttp.readyState==4)
	{
		if (xmlhttp.status==200)
		{
		    //if (xmlhttpDivId2=='divShipInfo1')
		    //{
		        
			    document.getElementById(xmlhttpDivId2).innerHTML=xmlhttp.responseText;
			    
			    document.getElementById("tdClose").onclick=function(){this.parentNode.parentNode.style.display='none'};
			    document.getElementById("txtZipCode").value=xmlhttpDivId2ZipCode;
			    document.getElementById("btnCalculate").onclick=function()
			    {
			        if(CheckZipCode(document.getElementById("txtZipCode")))
			        {
			            var zip=document.getElementById("txtZipCode").value;
			            document.getElementById(xmlhttpDivId2).innerHTML="<div class=\"ShipInfoTblTD1\" style=\"font-family:arial;font-size:11px;color:#000000;padding:10px;border:solid 1px #EB4D00\" width=\"150px\"><b>Loadding......</b></div>";
			            setShipInfo(document.getElementById(xmlhttpDivId2),zip,xmlhttpDivId2ShipId);
			        }
			        else
			            return false;
			    };
			    
			//}
			//else if (xmlhttpDivId2=='divShipInfo2')
			//    document.getElementById(xmlhttpDivId2).innerHTML=xmlhttp.responseText;
			    
		}
	}
}
function setShipInfo(divShipInfo,zipCode,ShipId)
{   
    if(divShipInfo.id)
    {
        divShipInfo.innerHTML="<div class=\"ShipInfoTblTD1\" style=\"font-family:arial;font-size:11px;color:#000000;padding:10px;border:solid 1px #EB4D00\" width=\"150px\"><b>Loadding......</b></div>";
        //alert("ASPUTil.aspx?Query=ShipInfo&ZipCode=" + zipCode + "&ShipId=" + ShipId);
        xmlhttpDivId2=divShipInfo.id;
        xmlhttpDivId2ShipId=ShipId;
        xmlhttpDivId2ZipCode=zipCode;
        HttpRequest2("/ASPUTil.aspx?Query=ShipInfo&ZipCode=" + zipCode + "&ShipId=" + ShipId);
    }    
}
////////
function Login(RedirectType,OrderNumber, SZip, EMail, Password) {
    if (OrderNumber == undefined)
        OrderNumber = "";
    if (SZip == undefined)
        SZip = "";
    if (EMail == undefined)
        EMail = "";
    if (Password == undefined)
        Password = "";
    if (RedirectType == undefined)
        RedirectType = "";

    $.ajax({
        type: "POST",
        url: "ASPUtil.aspx",
        data: "Query=Login&OrderNumber=" + OrderNumber + "&SZip=" + SZip + "&Email=" + EMail + "&Password=" + Password + "&RedirectType=" + RedirectType,
        success: function(msg) {
            if (msg.toString().substr(0, 7) == "SUCCESS")
                document.location = msg.toString().substr(8);
            else {
                $('#dvLogin').show();
                $('#dvLogin').html(msg);
            }
        }
    });
    
}

function ForgotPassword(Action,EMail) {
    if (EMail == undefined)
        EMail = "";
    else
        EMail = $.trim(EMail);

    if(Action=='Validate' && EMail=='')
        alert('Please enter Email Address.');
    else
        $.ajax({
            type: "POST",
            url: "ASPUtil.aspx",
            data: "Query=ForgotPassword&Email=" + EMail,
            success: function(msg) {
                $('#dvLogin').show();
                $('#dvLogin').html(msg);
            }
        });
}

function OrderNumberLogin(RedirectType, OrderNumber, ZipCode) {
    OrderNumber = $.trim(OrderNumber);
    ZipCode = $.trim(ZipCode);
    
    if (OrderNumber == '') {
        alert('Please enter Order number');
    }
    else if (ZipCode == '') {
        alert('Please enter Zip Code');
    }
    else {
        Login(RedirectType,OrderNumber,ZipCode)
    }    
}

function EMailLogin(RedirectType, Email, Password) {
    Email = $.trim(Email);
    Password = $.trim(Password);
    if (Email == '') {
        alert('Please enter Email Address');
    }
    else if (Password == '') {
        alert('Please enter Password');
    }
    else
        Login(RedirectType,'','',Email,Password);
}
