// JScript File

//global variable
    var mousex = 0;
    var mousey = 0;
    var algor = 0;
    var ie = (document.all) ? 1 : 0;
    
    var fadetimer;


function getPoe(val)
{
    var q = val.split('&');
    for(var i=0; i<q.length; i++)
    {
        var t=q[i].split('=');
        if (t[0].toLowerCase() == 'poe')
            return t[1];
    }
    return '';
}

function CreateClientForm(action, method, target, mapping)
{
    var oBody = document.body;
    var oForm = document.createElement("form");
    var oSource;
    var oInputHidden;
    var length;
    var i;    
    
    oForm.action = action;
    
    var uriSplit = unescape(window.location).split('?');
    if (uriSplit.length > 1)
    {
        var params = getPoe(uriSplit[1]);
        if (params != '')
        {       
            //if there is poe parameter
            oForm.action += "&poe=" + params;
        }
    }
    
    oForm.method = method;
    oForm.target = target;
    length = mapping.length;
    if(length %2 != 0) return false;
    for(i = 0; i < length; i += 2)
    {
        oInputHidden = document.createElement("input");
        oInputHidden.type = "hidden";
        oInputHidden.id = mapping[i + 1];
        oInputHidden.name = mapping[i + 1];
        oSource = document.getElementById(mapping[i]);
        if(oSource != null){
            if (oInputHidden.name == "__WWLBDSetAsDefaultLocation"){
                if (oSource.checked) 
                    oInputHidden.value = "true";
                else
                    oInputHidden.value = "false";
            } 
            else if (oInputHidden.name == "__WWLBDSearchBy"){
                oInputHidden.value = oSource.value;
                if (oInputHidden.value == "2")
                    oForm.action += "&sortBy=Relevance"; 
            } 
            else
                oInputHidden.value = oSource.value;
        }
        else
            oInputHidden.value = mapping[i];
            
        oForm.appendChild(oInputHidden);
        //alert(oInputHidden.name + " : " + oInputHidden.value)
    }
    oBody.appendChild(oForm);
    oForm.submit();
}


//this function is to position the flash object
function loadFlash() {
    var f = document.getElementById("flashContainer");
    if(f != null)
    {
        var m = document.getElementById("movableFlash");
        m.style.visibility = 'visible';
        var p = Point.prototype.GetAbsolutePosition(f);
        
        p.y += 2;
        setPosition(m, p, "left top");
    }
    else
    {
        var m = document.getElementById("movableFlash");
        m.style.visibility = 'hidden';
    }    
}


// methods to preload images on a webpage and swap them when needed
// ----------------- Start --------------
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_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) { //v3.0 
var p,i,x; 
if(!d) d=document; if((p=n.indexOf("?"))>0&&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); return x; } 

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];} } 
// ----------------- End ---------------


// methods for flipping images on Homepage
// ----------------- START --------------
    function StringArray (n) {
        this.length = n;
        for (var i = 0; i <= n; i++) {
	        this[i] = ' ';
        }
    }
    
    function widgetflipA() {
        return(imageMain[Maincore]);
    }
    function widgetflipB() {
        return(imageHomeGarden[HomeGardencore]);
    }
    function widgetflipC() {
        return(imageLivingWell[LivingWellcore]);
    }  
// ----------------- End --------------


function GetLink(strMRTextControlID, strValue)
{
    return "<a href='' onclick='javascript:document.getElementById(\"" + strMRTextControlID + "\").value=\"" + strValue + "\";this.parentNode.style.display=\"none\";return false;'>" + strValue + "</a>";
}

function DecodeCookieValue(strValue)
{
    return decodeURIComponent(strValue).replace("+", " ");
}

function DisplayMR(strCookieName, strMRLID, strTextBoxID, iSize, strPrefix)
{ 
    var objMR = document.getElementById(strMRLID);
    if(objMR == null) return; 
    if(objMR.style.display == "" || objMR.style.display == 'none') 
    {
        objMR.style.display = 'block';
    }
    else 
    {
        objMR.style.display = 'none';
        return;
    }      
    var oHotSpot = window.event.srcElement;
    objMR.style.postion = "absolute";
    objMR.style.left = "0px";
    objMR.style.top = (oHotSpot.height + 5) + "px";
    //objMR.style.width = "100%";
}  


// Functions related to getting the mouse pointer co-ordinates

    function getMouseXY(e) // works on IE6,FF,Moz,Opera7
    { 
        if (!e) e = window.event; // works on IE, but not NS (we rely on NS passing us the event)

        if (e)
        { 
            if (e.pageX || e.pageY)
            { // this doesn't work on IE6!! (works on FF,Moz,Opera7)
                mousex = e.pageX;
                mousey = e.pageY;
                algor = '[e.pageX]';
                if (e.clientX || e.clientY) algor += ' [e.clientX] '

                //alert('page works: ' + mousex + ', ' + mousey);
                // For Mozilla
                // XY value modified acc to app req
                mousex = mousex - 10;
                mousey = mousey - 100;                     
                
            }
            else if (e.clientX || e.clientY)
            { // works on IE6,FF,Moz,Opera7
                mousex = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
                mousey = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
                algor = '[e.clientX]';
                if (e.pageX || e.pageY) algor += ' [e.pageX] '
                
                //alert('client works: ' + mousex + ', ' + mousey);
                // For IE 6+
                // XY value modified acc to app req
                mousex = mousex - 10;
                mousey = mousey - 110;                
            }  
        }
    }

// End of functions related to getting the mouse pointer co-ordinates

function fadeout(objID, transparency, transparencystep, fadetimer) {
	if (transparency>0){
		transparency-=transparencystep
		if (ie) {
		    //alert(transparency);
		    var filter = "alpha(opacity=" + transparency + ")";
			document.getElementById(objID).style.filter = filter;
		}
		if (ie == 0) {
			document.getElementById(objID).style.MozOpacity=transparency/100
		}
		var functioncall = "fadeout('" + objID + "'," + transparency + "," + transparencystep + "," + fadetimer + ")";
		//alert('functioncall');
		fadetimer=setTimeout(functioncall, 40)
	}
	else {
		clearTimeout(fadetimer)
		pause = true;
	    setTimeout("pause=false",1);
	}
}

// Firefox requires that the event be passed along to find the event type afterwards. 
// This is compulsory for Firefox.
function DisplaySpecialOffer(ObjID, e)
{ 
    getMouseXY(e);
    
    //alert(mousex + ", " + mousey)    
    document.getElementById(ObjID).style.left = mousex.toString(10) + 'px'; //mousex - 10;
    document.getElementById(ObjID).style.top = mousey.toString(10) + 'px'; //mousey + 10;
    document.getElementById(ObjID).style.visibility = 'visible';
}

function HideSpecialOffer(objID, e)
{
    document.getElementById(objID).style.visibility = 'hidden';
}


// Functions to implement Business Review Rating
    function getRating(obj)
    {
        if (obj > chk)
	        for (var i=1; i<=obj; i++)
		        document.getElementById(i).src = "images/star_on.gif";
		      
		else if (obj == chk)
		        document.getElementById(chk).src = "images/star_on.gif";	
		        
		else if (obj < chk) {
		    src = (obj * 1) + 1;
   	        for (var i=src; i<=chk; i++)
		        document.getElementById(i).src = "images/star_off.gif";
		}
    		
        document.getElementById('myRate').innerHTML=ratings[obj];
    }

    function setDefault(obj)
    {	    	    
	    for (var i=1; i<=5; i++)
		    if (i > chk || chk == 0)
	    	    document.getElementById(i).src = "images/star_off.gif";
	    	else if (i <= chk)
	    	    document.getElementById(i).src = "images/star_on.gif";	    	    
    	
    	document.getElementById('myRate').innerHTML=ratings[chk];
    }

    function setRating(obj)
    {
	    for (var i=1; i<=5; i++)
		    document.getElementById(i).src = "images/star_off.gif";

	    for (i=1; i<=obj; i++)
		    document.getElementById(i).src = "images/star_on.gif";		

        document.getElementById('myRate').innerHTML=ratings[obj];
        chk = obj;
    }
    
// -----End of Business Review Rating Functions
