﻿function GetBase()
{
    var base = "http://www.beelocal.co.uk/";

    if(window.location.toString().indexOf(".co") == -1)
        base = "http://andypc2/H2Hbeelocal_v3/";
        
    if(window.location.toString().indexOf("https") != -1)
        base = base.replace("http", "https");                
        
    return base;
}

// function pageLoad()    {          
// var mpe = $find("MPE");          
// mpe.add_shown(onShown);      
// }         
// function onShown()    {          
// //add your code here          
// //$get("Panel1").style = "";      
// } 

function $a() {
  var elements = new Array();

  for (var i = 0; i < arguments.length; i++) {
    var element = arguments[i];
    if (typeof element == 'string')
      element = document.getElementById(element);

    if (arguments.length == 1)
      return element;

    elements.push(element);
  }

  return elements;
}

function ShowHomeLoginPasswordBox()
{
    $a('ctl00_ctl00_ContentPlaceHolder1_RightLoginBox1_txtPassword').style.display = 'none';
    $a('ctl00_ctl00_ContentPlaceHolder1_RightLoginBox1_txtPassword2').style.display = 'block';
    $a('ctl00_ctl00_ContentPlaceHolder1_RightLoginBox1_txtPassword2').focus();
}

function ShowPopUpNav(id)
{
    $a(id).style.display = 'block';
}
function HidePopUpNav(id)
{
    $a(id).style.display = 'none';
}


     
// *******************************************************************************************************
// JavaScript Document
// CSS Pop Ups
// AJH - 25/09/2006
// *******************************************************************************************************
/*
Simple Image Trail script- By JavaScriptKit.com
Edited by awestmoreland: http://www.sitepoint.com/forums/member.php?u=22198
*/
var offsetfrommouse = [15,15]; //image x,y offsets from cursor position in pixels. Enter 0,0 for no offset
var displayduration = 0; //duration in seconds image should remain visible. 0 for always.
var currentimageheight = 5;	// maximum image size.

if (document.getElementById || document.all){
	document.write('<div id="CssPopUp">');
	document.write('</div>');
}
function gettrailobj()
{
	if (document.getElementById)
		return document.getElementById("CssPopUp").style
	else if (document.all)
		return document.all.trailimagid.style
}

function gettrailobjnostyle()
{
	if (document.getElementById)
		return document.getElementById("CssPopUp")
	else if (document.all)
		return document.all.trailimagid
}
function truebody()
{
	return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}
function showtrail(title,description)
{
	document.onmousemove=followmouse;
	var newHTML = new StringBuilder();
	newHTML.append('<div class="CssRollOver">');
	newHTML.append('<b>' + title + '</b><br /><br />');
	newHTML.append(description + '<br />');
	newHTML.append('</div>');
	gettrailobjnostyle().innerHTML = newHTML.toString();
	gettrailobj().visibility="visible";
}
function showtrail2(title,image,description)
{
	document.onmousemove=followmouse;
	var newHTML = new StringBuilder();
	newHTML.append('<div class="ProductsPopUp">');
	newHTML.append('<img src="i/ProductPopUps/' + image + '" class="floatright" height="155" width="155" />');
	newHTML.append('<h4>' + title + '</h4>');
	newHTML.append(description);
	newHTML.append('<div class="clearer"></div>');
	newHTML.append('</div>');
	gettrailobjnostyle().innerHTML = newHTML.toString();
	gettrailobj().visibility="visible";
}
function hidetrail(){
	gettrailobj().visibility="hidden"
	document.onmousemove=""
	gettrailobj().left="-500px"
}
function followmouse(e){

	var xcoord=offsetfrommouse[0]
	var ycoord=offsetfrommouse[1]

	var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15
	var docheight=document.all? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(window.innerHeight)

	//if (document.all){
	//	gettrailobjnostyle().innerHTML = 'A = ' + truebody().scrollHeight + '<br>B = ' + truebody().clientHeight;
	//} else {
	//	gettrailobjnostyle().innerHTML = 'C = ' + document.body.offsetHeight + '<br>D = ' + window.innerHeight;
	//}

	if (typeof e != "undefined"){
		if (docwidth - e.pageX < 300){
			xcoord = e.pageX - xcoord - 286; // Move to the left side of the cursor
		} else {
			xcoord += e.pageX;
		}
		if (docheight - e.pageY < (currentimageheight + 110)){
			ycoord += e.pageY - Math.max(0,(110 + currentimageheight + e.pageY - docheight - truebody().scrollTop));
		} else {
			ycoord += e.pageY;
		}

	} else if (typeof window.event != "undefined"){

		if (docwidth - event.clientX < 300){
			xcoord = event.clientX + truebody().scrollLeft - xcoord - 286; // Move to the left side of the cursor
		} else {
			xcoord += truebody().scrollLeft+event.clientX
		}
		if (docheight - event.clientY < (currentimageheight + 110)){
			ycoord += event.clientY + truebody().scrollTop - Math.max(0,(110 + currentimageheight + event.clientY - docheight));
		} else {
			ycoord += truebody().scrollTop + event.clientY;
		}
	}

	var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15
	var docheight=document.all? Math.max(truebody().scrollHeight, truebody().clientHeight) : Math.max(document.body.offsetHeight, window.innerHeight)
	
	//alert(docheight + ' ' + ycoord);

	if(ycoord < 0) { ycoord = ycoord*-1; }
	gettrailobj().left=xcoord+"px"
	
	if((docheight-ycoord) < 150)
	{
	    gettrailobj().top=(ycoord-150)+"px";
	    }
	else
	{
	    gettrailobj().top=ycoord+"px";
	    }

}
/******************/
/* FUNCTIONS      */
/******************/
// Initializes a new instance of the StringBuilder class
// and appends the given value if supplied
function StringBuilder(value)
{
    this.strings = new Array("");
    this.append(value);
}
// Appends the given value to the end of this instance.
StringBuilder.prototype.append = function (value)
{
    if (value)
    {
        this.strings.push(value);
    }
}
// Clears the string buffer
StringBuilder.prototype.clear = function ()
{
    this.strings.length = 1;
}
// Converts this instance to a String.
StringBuilder.prototype.toString = function ()
{
    return this.strings.join("");
}

function loadmap(div,longitude,latitude) 
{
	if (GBrowserIsCompatible()) {
		var map = new GMap2(document.getElementById(div));
		map.addControl(new GSmallMapControl());
		map.addControl(new GMapTypeControl());
		map.setCenter(new GLatLng(longitude, latitude), 15);
		
		var point = new GLatLng(longitude,latitude);
		map.addOverlay(new GMarker(point));
	}
}

function ScrollToProducts() 
{
    window.scroll(0,findPosY($a('ProductsAName'))); // horizontal and vertical scroll increments
}

function findPosY(obj)
{
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
}

function ViewProducts(ShopID,ProductCategoryID,Item)
{   
	var url = GetBase() + 'ProductsWindow.aspx?ShopID=' + ShopID + '&ProductCategoryID=' + ProductCategoryID + '&Item=' + Item;
	zzz = window.open(url,'','width=600,height=600,resizable=yes,scrollbars=yes,left=100,top=100');
	zzz.focus();    
}

function reload()
{
    window.opener.document.forms[0].submit();
}

function ViewCollectionPoints()
{   
	var url = GetBase() + 'CollectionPointsWindow.aspx'
	zzz = window.open(url,'','width=600,height=660,scrollbars=yes,left=100,top=100');
	zzz.focus();    
}
function ViewTerms()
{   
	var url = GetBase() + 'TermsWindow.aspx'
	zzz = window.open(url,'','width=600,height=660,scrollbars=yes,left=100,top=100');
	zzz.focus();    
}


function AddToCart(ParentProductID, id)
{           
    id = id.replace("btnImage","");

    var hd = id + 'txtProductID';
    var qty = 1;    
    
    var ProductIDToAdd = $a(hd).value;
    
    if($a(hd) != null)
    {
        ProductIDToAdd = $a(hd).value;
    }

    var qty1 = id + 'txtQuantity';
    var qty2 = id + 'txtQuantity2';    
    if ($a(qty1) != null)
    {
        qty = $a(qty1).value;
    }
    else
    {
        qty = $a(qty2).value;
    }

    if(qty < 1 || !IsNumeric(qty))
    {
        alert("Please enter a valid quantity");
        if ($a(qty1) != null)
        {
            $a(qty1).value = "1";
        }
        else
        {
            $a(qty2).value = "1";
        }
    }
    else
    {
        var url = window.location.toString();
        
        if(window.location.toString().indexOf("https") != -1)
            url.replace("http:", "https:");
                  
        post_to_url(GetBase() + 'frmAddToCart.aspx',{'ParentProductID':ParentProductID,'ProductIDToAdd':ProductIDToAdd,'URL':url,'Quantity':Math.round(qty)},'post');
    }
//    alert("ProductID=" + productid);
//    alert("Qty=" + qty);        

}

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 post_to_url(path, params, method, returnparams) {
    method = method || "post"; // Set method to post by default, if not specified.

    // The rest of this code assumes you are not using a library.
    // It can be made less wordy if you use one.
    var form = document.createElement("form");
    form.setAttribute("method", method);
    form.setAttribute("action", path);

    for(var key in params) {
        var hiddenField = document.createElement("input");
        hiddenField.setAttribute("type", "hidden");
        hiddenField.setAttribute("name", key);
        hiddenField.setAttribute("value", params[key]);

        form.appendChild(hiddenField);
    }
    
    document.body.appendChild(form);    // Not entirely sure if this is necessary
    form.submit();
}


function myshow(header, image, paragraphText)
{    
    $a('popup').innerHTML = '<img src="i/ProductPopUps/' + image + '" class="floatright" height="155" width="155" /><h4>'+header+'</h4>'+paragraphText;
    $find('ModalPopupBehavior').show();
}
function hide(e) {  
    var e = window.event || e, relatedTarget = e.toElement || e.relatedTarget;  
    while (relatedTarget && relatedTarget != this)  
        relatedTarget = relatedTarget.parentNode;  
    if (!relatedTarget)  
        $find('ModalPopupBehavior').hide();     
}  
function fillInfo()
{
    document.getElementsByName('fillPopup').innerHTML = text;
    alert(text);
}

function ShowHint(id, searchID)
{
   if(document.getElementById(id).value = "what are you looking for?")
       document.getElementById(id).value = "";
   document.getElementById(searchID).style.display = "block";
}
function HideHint(id, searchID)
{   
   document.getElementById(searchID).style.display = "none";
}
function deliveryCollectPage(url)
{
   window.location = GetBase() + url;
}