/* START OF MAXHEIGHT JAVASCRIPT */
/* START OF MAXHEIGHT JAVASCRIPT */
/* START OF MAXHEIGHT JAVASCRIPT */

var ElementMaxHeight = function() {
  this.initialize.apply(this, arguments);
}

ElementMaxHeight.prototype = {
  initialize: function(className) {
    this.elements = document.getElementsByClassName(className || 'maxheight');    
    this.textElement = document.createElement('span');
    this.textElement.appendChild(document.createTextNode('A'));
    this.textElement.style.display = 'block';
    this.textElement.style.position = 'absolute';
    this.textElement.style.fontSize = '1em';
    this.textElement.style.top = '-1000px';
    this.textElement.style.left = '-1000px';
    document.body.appendChild(this.textElement);
    this.textElementHeight = document.getDimensions(this.textElement).height;
    var __object = this;
    var __checkFontSize = this.checkFontSize;
    this.checkFontSizeInterval = window.setInterval(function() {return __checkFontSize.apply(__object)}, 500);

    this.expand();

    // Refresh elements height onResize event
    var __expand = this.expand;
    if (window.addEventListener) {
      window.addEventListener('resize', function(event) {return __expand.apply(__object, [( event || window.event)])}, false);
    } else if (window.attachEvent) {
      window.attachEvent('onresize', function(event) {return __expand.apply(__object, [( event || window.event)])});
    }
  },

  expand: function() {
    this.reset();
  	for (var i = 0; i < this.elements.length; i++) {  	
      this.elements[i].style.height = document.getDimensions(this.elements[i].parentNode).height + 'px';
  	}
  },

  reset: function() {
    for (var i = 0; i < this.elements.length; i++) {    
      this.elements[i].style.height = 'auto';
    }
  },

  checkFontSize: function() {
  	var height = document.getDimensions(this.textElement).height;
  	if(this.textElementHeight != height) {
  		this.textElementHeight = height;
  		this.expand();
  	}
  }  
}


if (!!document.evaluate) {
  document._getElementsByXPath = function(expression, parentElement) {
    var results = [];
    var query = document.evaluate(expression, parentElement || document,
      null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
    for (var i = 0, length = query.snapshotLength; i < length; i++)
      results.push(query.snapshotItem(i));
    return results;
  }
}

document.getElementsByClassName = function(className, parentElement) {
  if (!!document.evaluate) {
    var q = ".//*[contains(concat(' ', @class, ' '), ' " + className + " ')]";
    return document._getElementsByXPath(q, parentElement);
  } else {
    var children = (parentElement || document.body).getElementsByTagName('*');
    var elements = [], child;
    for (var i = 0, length = children.length; i < length; i++) {
      child = children[i];
      if (child.className.length != 0 &&
          (child.className == className ||
           child.className.match(new RegExp("(^|\\s)" + className + "(\\s|$)")))) {      
        elements.push(child);
      }
    }
    return elements;
  }
}

document.getDimensions = function (element) {
  var display = element.style.display;
  if (display != 'none' && display != null) { // Safari bug
    return {width: element.offsetWidth, height: element.offsetHeight};
  }

  return {width: originalWidth, height: originalHeight};
}

/* END OF MAXHEIGHT JAVASCRIPT */
/* END OF MAXHEIGHT JAVASCRIPT */
/* END OF MAXHEIGHT JAVASCRIPT */



        function EmailSignUp() {
            document.location.href="EmailSignUp.aspx?email="+document.getElementById("ctl00_txtEmail").value;
        }

		function PleaseWait() {
			//document.getElementById("divMain").style.visibility='hidden';
			if (document.getElementById("ctl00_c_dgResults")!=null)
				document.getElementById("ctl00_c_dgResults").style.visibility="hidden";
			if (document.getElementById("ctl00_c_divLatestUpdatesTitle")!=null)
				document.getElementById("ctl00_c_divLatestUpdatesTitle").style.visibility="hidden";
			document.getElementById("ctl00_c_PleaseWait").innerHTML='Please wait, loading...';
		}


		function IgnoreSingleQuotes(event) {
			var keyCode=event.keyCode;
			if (keyCode==0)  // returns 0 on Firefox, Netscape etc
				keyCode=event.which;
			if (keyCode==39 || keyCode==96) // single quote - keyCode on IE, which on Netscape
			{
				event.returnValue = false;
				event.cancelBubble = true;
				return false;
			}
			return true;
		}
	
		function NotSure() {
			alert('PriceDash is best suited to searching for a particular model of product, e.g. a Sony "DSC-W12" digital camera.\r\n\r\nIn order to find a model that suits your needs, use the categories on the following window (when you click OK) to narrow down on one, but dont use the search box.\r\n\r\nRemember to return to this window in order to do a FULL price comparison containing 5 times as many suppliers.\r\n\r\nNote, the window will not appear if you have any pop-up blocking software running.');
			window.open('http://clkuk.tradedoubler.com/click?p=3431&a=1021836&g=17632','','height=540,width=720,top=50,left=50,scrollbars=yes,resizable=yes');
		}
		
		function Trim(TRIM_VALUE){
		if(TRIM_VALUE.length < 1){
		return"";
		}
		TRIM_VALUE = RTrim(TRIM_VALUE);
		TRIM_VALUE = LTrim(TRIM_VALUE);
		if(TRIM_VALUE==""){
		return "";
		}
		else{
		return TRIM_VALUE;
		}
		} //End Function

		function RTrim(VALUE){
		var w_space = String.fromCharCode(32);
		var v_length = VALUE.length;
		var strTemp = "";
		if(v_length < 0){
		return"";
		}
		var iTemp = v_length -1;

		while(iTemp > -1){
		if(VALUE.charAt(iTemp) == w_space){
		}
		else{
		strTemp = VALUE.substring(0,iTemp +1);
		break;
		}
		iTemp = iTemp-1;

		} //End While
		return strTemp;

		} //End Function

		function LTrim(VALUE){
		var w_space = String.fromCharCode(32);
		if(v_length < 1){
		return"";
		}
		var v_length = VALUE.length;
		var strTemp = "";

		var iTemp = 0;

		while(iTemp < v_length){
		if(VALUE.charAt(iTemp) == w_space){
		}
		else{
		strTemp = VALUE.substring(iTemp,v_length);
		break;
		}
		iTemp = iTemp + 1;
		} //End While
		return strTemp;
		} //End Function

		

		// this version works in Firefox as well as IE
		function BookmarkUs(){
			if (document.all)
			window.external.AddFavorite(document.location, 'PriceDash - The Money Saver');
			else if (window.sidebar)
			window.sidebar.addPanel('PriceDash - The Money Saver', document.location, "")
		}
	
		function BookmarkUs1() {
			var ver = navigator.appName
			var num = parseInt(navigator.appVersion)
			if ((ver == "Microsoft Internet Explorer")&&(num >= 4))
				window.external.AddFavorite(document.location.href,'PriceDash - The Money Saver');
		}
			
		// used by the latest news scroller
		function PDOpenWindow(url) {
			window.open(url,'');
			return false
		}	
		
        function AvoidEnterKeyBeingPressed(event) {
		        var keyCode=event.keyCode;
		        if (keyCode==0)  // returns 0 on Firefox, Netscape etc
			        keyCode=event.which;
		        if (keyCode==13 || keyCode==13) // enter key
		        {
			        return false;
		        }
		        return true;
        }
        
        function DoBargainProblem(problem,index)
       {
         wsPriceDash.BargainProblem(problem);
         document.getElementById("spanProblem"+index).innerHTML='Thank you for reporting this - we shall investigate and correct this item ASAP.';
         document.getElementById("spanProblem"+index).style.color='blue';
       }
       
       function SendBargain()
       {
         var Description = document.getElementById("ctl00_c_txtSendBargainDescription").value.replace("'","\'");
         document.getElementById("SendBargainResult").innerHTML='';
         wsPriceDash.SendBargain(Description,OnSendBargainRequestComplete);
       }

       function OnSendBargainRequestComplete(result)
       {
         var RsltElem = document.getElementById("SendBargainResult");
         RsltElem.innerHTML = result;
       }
       
        function DoMobileProblem(problem,index)
       {
         wsPriceDash.MobileProblem(problem);
         document.getElementById("spanProblem"+index).innerHTML='Thank you for reporting this - we shall investigate and correct this item ASAP.';
         document.getElementById("spanProblem"+index).style.color='blue';
       }

	    function RetailerDiscounts(shop) {
		    window.open('mobileretailer.aspx?RID='+shop,'','height=400,width=720,top=50,left=50,scrollbars=yes,resizable=yes');
	    }
	    
	   function DoSaleProblem(problem,index)
       {
         wsPriceDash.SaleProblem(problem);
         document.getElementById("spanProblem"+index).innerHTML='Thank you for reporting this - we shall investigate and correct this item ASAP.';
         document.getElementById("spanProblem"+index).style.color='blue';
       }
       
       function SendSale()
       {
         var Description = document.getElementById("ctl00_c_txtSendSaleDescription").value.replace("'","\'");
         document.getElementById("SendSaleResult").innerHTML='';
         wsPriceDash.SendSale(Description,OnSendSaleRequestComplete);
       }

       function OnSendSaleRequestComplete(result)
       {
         var RsltElem = document.getElementById("SendSaleResult");
         RsltElem.innerHTML = result;
       } 
        
