﻿function showchilds(obj)
	{      
        divs=obj.getElementsByTagName("div");
        if (divs.length)
        {
            for (i=0;i<divs.length;i++)
            {
                if (divs[i].className.indexOf("child")!=-1)
                {
                    divs[i].style.display="block";
                }
                else
                {
                    if (divs[i].className.indexOf("parent_name")!=-1)
                    {
                        toggleMenuArrow(divs[i]);
                    }
                }
            }
        }        
	}

	function toggleMenuArrow(div)
	{
	    imgs=div.getElementsByTagName("img");
        if (imgs.length)
        {
            for (j=0;j<imgs.length;j++)
            {                
                if (imgs[j].style.display=="inline")
                {
                    imgs[j].style.display="none";
                }
                else
                {
                    imgs[j].style.display="inline";
                }
            }
        }
	}
	
	function hidechilds(obj)
	{
	    divs=obj.getElementsByTagName("div");
        if (divs.length)
        {
            for (i=0;i<divs.length;i++)
            {
                if (divs[i].className.indexOf("child")!=-1)
                {
                    divs[i].style.display="none";
                }
                else
                {
                    if (divs[i].className.indexOf("parent_name")!=-1)
                    {
                        toggleMenuArrow(divs[i]);
                    }
                }
            }
        }
	}
	
function Initialize()
{
    try
    {
        req=new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch(e)
    {
        try
        {
	        req=new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch(oc)
        {
	        req=null;
        }
    }
    if(!req&&typeof XMLHttpRequest!="undefined")
    {
        req=new XMLHttpRequest();
    }
}

function SendQuery(Like)
{
    if (document.getElementById("kwd").value.length >= 3)
    {
        Initialize();
        
        var url=siteRoot+"/shop/Async/get_dictionary.aspx?Like="+Like;
    	
        if(req!=null)
        {
            req.onreadystatechange = Process;
            req.open("GET", url, true);
            req.send(null);
        }
    }
    else
    {
        HideDiv("autocomplete");
    }
}

// Function to procee the request
function Process()
{
    if (req.readyState == 4) 
        {
        // only if "OK"
	        if (req.status == 200) 
	        {   			            
		        if(req.responseText=="")
			        HideDiv("autocomplete");
		        else
		        {
		            var result = req.responseText.split("||");
			        ShowDiv("autocomplete", result);
		        }
	        }
	        else 
	        {
		        document.getElementById("autocomplete").innerHTML="There was a problem retrieving data:"+req.statusText;
	        }
        }
}

function ShowDiv(divid, result) 
{
    document.getElementById(divid).style.display="block";  
    document.getElementById(divid).style.visibility="visible";  
   
    document.getElementById(divid).innerHTML = "";
  
    var newDiv = "";
    count = 0;
    for (var i=0; i < result.length;i++)
    {
        if (result[i] != "")
        {
            count++;
            newDiv += "<div id='div" + i + "' width='200px' style='border-bottom:solid 1px #000;' onmouseover=\"this.style.backgroundColor = '#CCCCCC';\" onmouseout=\"this.style.backgroundColor = '#FFFFFF';\" onclick=\"document.getElementById('kwd').value = this.innerHTML;document.getElementById('autocomplete').style.display='none';\">";
                newDiv += result[i];
            newDiv += "</div>";
        }
    }                   
    document.getElementById(divid).innerHTML += newDiv;     
}

function HideDiv(divid) 
{
   if (document.layers) 
        document.layers[divid].visibility="hidden";
   else 
        document.getElementById(divid).style.visibility="hidden";
}

function BodyLoad()
{
    HideDiv("autocomplete");
    document.form1.address.focus();
}

//now create the event handler function to process the event
function alertkey(e) {
  if( !e ) {
    //if the browser did not pass the event information to the
    //function, we will have to obtain it from the event register
    if( window.event ) {
      //Internet Explorer
      e = window.event;
    } else {
      //total failure, we have no way of referencing the event
      return;
    }
  }
  
  if( typeof( e.keyCode ) == 'number'  ) {
    //DOM
    e = e.keyCode;
  } else if( typeof( e.which ) == 'number' ) {
    //NS 4 compatible
    e = e.which;
  } else if( typeof( e.charCode ) == 'number'  ) {
    //also NS 6+, Mozilla 0.9+
    e = e.charCode;
  } else {
    //total failure, we have no way of obtaining the key code
    return;
  }
  
  if (document.getElementById("autocomplete") && document.getElementById("testFocus"))
  {
  if (document.getElementById("autocomplete").style.display == "block" && document.getElementById("autocomplete").style.visibility == "visible")
  {
        if ( document.getElementById("testFocus").value == "1")
        {
            switch(e)
              {
                case 38:
                    if (cursorPos == -1)
                    {
                        cursorPos = count - 1;
                    }
                    else
                        if (cursorPos > -1)
                        {
                            if (cursorPos > 0)
                            {
                                cursorPos -= 1;
                            }
                            else
                            {
                                cursorPos = count - 1;
                            }
                        }
                    
                    document.getElementById("div" + cursorPos).style.backgroundColor = "#CCCCCC";
                     
                    break;
                case 40:
                    if (cursorPos == -1)
                    {
                        cursorPos = 0;
                    }
                    else
                        if (cursorPos > -1)
                        {
                            if (cursorPos < count - 1)
                            {
                                cursorPos += 1;
                            }
                            else
                            {
                                cursorPos = 0;
                            }
                        }
                    
                    document.getElementById("div" + cursorPos).style.backgroundColor = "#CCCCCC";
                
                    break;
                case 27:
                    if (document.getElementById("autocomplete"))
                    {
                        document.getElementById("autocomplete").style.display = "none";
                    }
                    break;
                case 13:
                    if (document.getElementById("div" + cursorPos))
                    {
                        document.getElementById("kwd").value = document.getElementById("div" + cursorPos).innerHTML;
                    }
                
                    document.getElementById("autocomplete").style.display = "none";
                    break;
                default:break;
            }
         }
     }
     }
}    

function ChangeFocus(test)
{
    if (test == "1")
        document.getElementById("testFocus").value = "1"
    else
    {
        document.getElementById("testFocus").value = "0";
    }
}

function CheckPost()
{
    if (document.getElementById("autocomplete") && document.getElementById("testFocus"))
    {
        if (document.getElementById("autocomplete").style.display == "block" && document.getElementById("autocomplete").style.visibility == "visible")
        {
            if ( document.getElementById("testFocus").value == "1")
            {
                return false;
            }
        }  
        
        return true;
     }
     
     return true;
} 


function validateKwdBox()
{
    errors = new Array();
    errorFields = new Array();     

    ValidateData("REQUIRED", "kwd", "Search Term");
    ValidateData("MINLENGTH="+keywordMinimumLength, "kwd", "Search Term");
            
    return BuildAlertWindow();
}
        
function addFav() 
{    
	if (window.sidebar) 
	{ 
	    // Mozilla Firefox Bookmark
	    window.sidebar.addPanel(bookmarkTitle, bookmarkUrl,"");
	} else if( window.external ) 
	    { 
	        // IE Favorite
	        window.external.AddFavorite(bookmarkUrl, bookmarkTitle); 
        }
    else if(window.opera && window.print) 
    {   
           // Opera Hotlist
        return true; 
    }
}

function internetExplorerMenuHookup() 
	{
	
    if (document.all&&document.getElementById) {    				
	
        navRoot = document.getElementById("nav");
        for (i=0; i<navRoot.childNodes.length; i++)
        {   
            node = navRoot.childNodes[i];
            if (node.nodeName=="LI") {
                  node.onmouseover=function() {
                    this.className+=" over";
                    if (navigator.appName == "Microsoft Internet Explorer" && (navigator.appVersion.toLowerCase().indexOf("msie 6.0")!= -1 || navigator.appVersion.toLowerCase().indexOf("msie 5.0")!= -1))
                    {hideOverlappingElements();}
                   
                }
                node.onmouseout=function() {
                    this.className=this.className.replace(" over", "");
                    if (navigator.appName == "Microsoft Internet Explorer" && (navigator.appVersion.toLowerCase().indexOf("msie 6.0")!= -1 || navigator.appVersion.toLowerCase().indexOf("msie 5.0")!= -1))
                    {showOverlappingElements();}                    
                }
            }           
        }
    }
    }
function hideOverlappingElements()
{
        for (var j=0; j<document.forms.length; j++) 
        {
            var f = document.forms[j];
            for (var i=0; i<f.elements.length; i++) 
            {
                  if(f.elements[i].tagName.toUpperCase() == "SELECT")
                    f.elements[i].style.visibility = "hidden"; 
            }
        }    
}

function showOverlappingElements()
{
       for (var j=0; j<document.forms.length; j++) 
       {
            var f = document.forms[j];
            for (var i=0; i<f.elements.length; i++) 
            {
                if(f.elements[i].tagName.toUpperCase() == "SELECT")
                    f.elements[i].style.visibility = "visible";
   
                       
            }
        }
} 

function openBigPicture(p_ImgSource,p_width, p_height, p_name){
	var winl;
	var wint;
	
	if(screen.width){
		winl = (screen.width-p_width)/2;
		wint = (screen.height-p_height)/2;
	}
	else{winl = 0;wint =0;}
	
	var strFeatures;
	strFeatures = "status=no,toolbar=no,menubar=no,location=no,scrollbars=no,resizable=no,width="+p_width+",height="+p_height+",top="+wint+",left="+winl+"";
	oWindow = window.open('',p_name, strFeatures);
	oWindow.document.open();  
	oWindow.document.write('<style> body{margin:0;} </style>');
	oWindow.document.write('<a href="JavaScript:window.close();"><img src="'+p_ImgSource+'" width='+p_width+' height='+p_height+' border="0"></a>'); 
	oWindow.document.close();
	oWindow.focus();
}

function PF(p_ImgSource,p_width, p_height, p_name){
    var winl;
	var wint;
		
	if(screen.width){
		winl = (screen.width-p_width)/2;
		wint = (screen.height-p_height)/2;
	}
	else{winl = 0;wint =0;}
  
  var strFeatures;
  strFeatures = "status=no,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=no,width=" + p_width + ",height=" + p_height+",top="+wint+",left="+winl+"";
  oWindow = window.open(p_ImgSource, p_name, strFeatures);
  oWindow.focus();			
}

function openPopup(p_strPage, name){
  var strFeatures;
  var p_strPage;
  strFeatures = "status=no,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=no,width=417,height=400";
  oWindow = window.open(p_strPage, name, strFeatures);
  oWindow.focus();
}

function submitForm(form, action)
{
    document.forms[form].hdnAction.value = action;
}

function writeRatings(rating, width, starSize, imagePath)
{
    var divRatings = "";
    var background = "";
    var foreground = "";
    var foregroundWidth = "";
    
    if (starSize == "1")
    {
        background = "icon_stars_none_small.gif";
        foreground = "icon_stars_gold_small.gif";
    }
    if (starSize == "2")
    {
        background = "icon_stars_none.gif";
        foreground = "icon_stars_gold.gif";
    }
    
    foregroundWidth = Math.round((parseFloat(width) * parseFloat(rating)) / parseFloat(5.00));
    
    divRatings = "<div style='width:" + width + "px; background: url(" + imagePath + "/" + background + ") top left no-repeat;'><div style='width:" + foregroundWidth + "px;overflow:hidden;'><img src='" + imagePath + "/" + foreground + "' title='Rating' alt='Rating' style='margin:0;padding:0;' /></div></div>";
    
    document.write(divRatings);
}