/* CSS Document */
var clipTallTop = 357;
var clipShortTop = 367;
var clipOpenTop = 151;
var clippingsOpen = false;
var aJax = false;

function addToClippings(sPath) {
	if (!clippingsOpen) {
		makeClippingsTall();
		makeClippingsShort();
	}
	addClipping(sPath);
}


function makeClippingsTall(){  $("#pdfTab").animate({"top":clipTallTop,"height":48},200);}
function makeClippingsShort(){ $("#pdfTab").animate({"top":clipShortTop,"height":38},200);}

function openClippings(){ 
	if (clippingsOpen) {
		clippingsOpen = false;
		$("#pdfTab").animate({"top":clipShortTop,"height":38},200, function() {$("#pdfBasket").css("display", "none");});
		$("#pdfTab").removeClass("clippingsOpen");
		$("#pdfTab").addClass("clippingsClosed");
	}
	else {
		$("#pdfTab").animate({"top":clipOpenTop,"height":273},200);
		$("#pdfTab").removeClass("clippingsClosed");
		$("#pdfTab").addClass("clippingsOpen");
		$("#pdfBasket").css("display", "");
		clippingsOpen = true;
	}
}


function addClipping(sPath){
	getAjaxConnection();
	if (aJax) {
		var url = "/includes/addClipping.asp?url=" + escape(sPath);
		aJax.open("GET", url, true);
		aJax.onreadystatechange = updateClippingCount;
		aJax.send();
	}
}

function removeClipping(i){
	getAjaxConnection();
	if (aJax) {
		var url = "/includes/addClipping.asp?rem=" + String(i) + "&d="+ escape(Date());
		aJax.open("GET", url, true);
		aJax.onreadystatechange = updateClippingCount;
		aJax.send();
	}
}

function updateClippingCount() {
	if (aJax.readyState == 4 ) {
		if (aJax.responseText != "" ) {
			var sText = aJax.responseText;
			var oTd = document.getElementById("clippingCount");
			var oPdf = document.getElementById("pdfBasket");
			if(oTd) oTd.innerHTML = sText.split("~")[0];
			if(oPdf) oPdf.innerHTML = sText.split("~")[1];
			$(".hoverOver[title]").tooltip({position: "bottom center"});
		}
		aJax = false;
	}
}

function getAjaxConnection() {
	try {
		aJax = new XMLHttpRequest();
	} catch (trymicrosoft) {
		try {
			aJax = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (othermicrosoft) {
			try {
				aJax = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (failed) {
				aJax = false;
			}  
		}
	}
	if (!aJax) alert("Error initializing AJAX");
}

function toggleBg() {
	if (document.body.bgColor=="#ffffff") document.body.bgColor="#c80207"; else document.body.bgColor="#ffffff";
}

function gURL() { //v3.0
  var i, args=gURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

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) { //v4.01
  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);
  if(!x && d.getElementById) x=d.getElementById(n); 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];}
}

function getFlashVersion(){ 
  // ie 
  try { 
    try { 
      // avoid fp6 minor version lookup issues 
      // see: http://blog.deconcept.com/2006/01/11/getvariable-setvariable-crash-internet-explorer-flash-6/ 
      var axo = new ActiveXObject('ShockwaveFlash.ShockwaveFlash.6'); 
      try { axo.AllowScriptAccess = 'always'; } 
      catch(e) { return '6,0,0'; } 
    } catch(e) {} 
    return new ActiveXObject('ShockwaveFlash.ShockwaveFlash').GetVariable('$version').replace(/\D+/g, ',').match(/^,?(.+),?$/)[1]; 
  // other browsers 
  } catch(e) { 
    try { 
      if(navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin){ 
        return (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]).description.replace(/\D+/g, ",").match(/^,?(.+),?$/)[1]; 
      } 
    } catch(e) {} 
  } 
  return '0,0,0'; 
} 

// JavaScript Document

function setButton() {
	if (addedId!="") {
		swapImg(addedId, '', '<%= gsInBasketImg%>');
	}
}

function advsearch() {
	document.advsearchform.submit();
}

function invalidCaptcha() {
	document.getElementById("feedbackerr").style.display = "";
	document.getElementById("systheform").style.display = "";
	sysReloadCa();
}

function feedbackThanks() {
	document.getElementById("systhanks").innerHTML = "<b>Thank you for your feedback, it's much appreciated.</b>";
	document.getElementById("systheform").style.display="none";
	document.getElementById("feedbackerr").style.display="none";
}

function sysReloadCa() {
	document.getElementById('syscaimg').src='/includes/caimage.asp?' + Date();
}


function callBack(valid) {
	var tbl = document.getElementById("callbacktable");
	var spn = document.getElementById("callbackmessage");
	if (valid) {
		if (tbl && spn) {
			tbl.style.display="none";
			spn.innerHTML = "<p style='color:maroon;text-align:right;'>Thank you for your interest, we will contact you very soon</p>"
		}
	}
	else {
		if (tbl && spn) {
			tbl.style.display="";
			spn.innerHTML = "<p style='color:red;text-align:right;'>Please complete all fields marked with a red asterix <sup>*</sup></p>"
		}
	}	
}

function updateBasket(iQty) {
		var bskt = document.getElementById("basketatag");
		if (bskt) {
			basketitems = iQty;
			bskt.innerHTML = "(" + String(basketitems) + ")";
		}
}

function notAdded(sTxt) {
	alert(sTxt);
}

function popup(img) {
	result = window.open("/viewimage.asp?img=" + img, "prodimg", "height=350,width=350,scrollbars,resizable");
	var cr = String.fromCharCode(13);
	if (result == null) alert("You browser is currently blocking Popups." + cr + cr + "Please change your settings to allow popups on this site." + cr + "Alternatively just click on 'more details' to view the images.");
}

function sImgR() { //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 loadImg() { //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=loadImg.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 findObj(n, d) { //v4.01
  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=findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function swapImg() { //v3.0
  var i,j=0,x,a=swapImg.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function GetXmlHttpObject() {
	var xmlHttp=null;
	try {
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest(); }
	catch (e) {
		// Internet Explorer
		try {
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); }
		catch (e) {
			try {
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); }
			catch (e) {
				alert("Sorry, your browser does not support AJAX.");
				xmlHttp=null; }
		}
	}
	return xmlHttp;
}

function writeIn(pre, dom1, ext) {
	var lt = String.fromCharCode(60);
	var gt = String.fromCharCode(62);
	var at = String.fromCharCode(64);
	var qt = String.fromCharCode(34);
	var eq = String.fromCharCode(61);
	
	var act1 = String.fromCharCode(109) + "a";
	var act2 = "i" + String.fromCharCode(108);
	var act3 = "to";
	var act4 = String.fromCharCode(58);
	
	var lnk1 = lt + String.fromCharCode(97) + " " + String.fromCharCode(104) + String.fromCharCode(114) + String.fromCharCode(101) + String.fromCharCode(102) + eq + qt + act1 + act2 + act3 + act4;
	var lnk2 = lt + String.fromCharCode(47) + String.fromCharCode(97) + gt;
	
	var ad = lnk1 + pre + at + dom1 + ext + qt + gt + pre + at + dom1 + ext + lnk2;
	var ol = document.getElementById("kont");
	ol.innerHTML = ad;
}

/*==============================================================================

    Routines written by John Gardner - 2003 - 2005

    See www.braemoor.co.uk/software for information about more freeware
    available.

/*==============================================================================

Routine to write a session cookie

    Parameters:
        cookieName        Cookie name
        cookieValue       Cookie Value
    
    Return value:
        true              Session cookie written successfullly
        false             Failed - persistent cookies are not enabled

   e.g. if (writeSessionCookie("pans","drizzle") then
           alert ("Session cookie written");
        else
           alert ("Sorry - Session cookies not enabled");
*/

function writeSessionCookie (cookieName, cookieValue) {
  if (testSessionCookie()) {
    document.cookie = escape(cookieName) + "=" + escape(cookieValue) + "; path=/";
    return true;
  }
  else return false;
}

/*==============================================================================

Routine to get the current value of a cookie

    Parameters:
        cookieName        Cookie name
    
    Return value:
        false             Failed - no such cookie
        value             Value of the retrieved cookie

   e.g. if (!getCookieValue("pans") then  {
           cookieValue = getCoookieValue ("pans2);
        }
*/

function getCookieValue (cookieName) {
  var exp = new RegExp (escape(cookieName) + "=([^;]+)");
  if (exp.test (document.cookie + ";")) {
    exp.exec (document.cookie + ";");
    return unescape(RegExp.$1);
  }
  else return false;
}

/*==============================================================================

Routine to see if session cookies are enabled

    Parameters:
        None
    
    Return value:
        true              Session cookies are enabled
        false             Session cookies are not enabled

   e.g. if (testSessionCookie())
           alert ("Session coookies are enabled");
        else
           alert ("Session coookies are not enabled");
*/

function testSessionCookie () {
  document.cookie ="testSessionCookie=Enabled";
  if (getCookieValue ("testSessionCookie")=="Enabled")
    return true 
  else
    return false;
}

/*==============================================================================

Routine to see of persistent cookies are allowed:

    Parameters:
        None
    
    Return value:
        true              Session cookies are enabled
        false             Session cookies are not enabled

   e.g. if (testPersistentCookie()) then
           alert ("Persistent coookies are enabled");
        else
           alert ("Persistent coookies are not enabled");
*/

function testPersistentCookie () {
  writePersistentCookie ("testPersistentCookie", "Enabled", "minutes", 1);
  if (getCookieValue ("testPersistentCookie")=="Enabled")
    return true  
  else 
    return false;
}

/*==============================================================================

Routine to write a persistent cookie

    Parameters:
        CookieName        Cookie name
        CookieValue       Cookie Value
        periodType        "years","months","days","hours", "minutes"
        offset            Number of units specified in periodType
    
    Return value:
        true              Persistent cookie written successfullly
        false             Failed - persistent cookies are not enabled
    
    e.g. writePersistentCookie ("Session", id, "years", 1);
*/       

function writePersistentCookie (CookieName, CookieValue, periodType, offset) {

  var expireDate = new Date ();
  offset = offset / 1;
  
  var myPeriodType = periodType;
  switch (myPeriodType.toLowerCase()) {
    case "years":
      expireDate.setYear(expireDate.getFullYear()+offset);
      break;
    case "months":
      expireDate.setMonth(expireDate.getMonth()+offset);
      break;
    case "days":
      expireDate.setDate(expireDate.getDate()+offset);
      break;
    case "hours":
      expireDate.setHours(expireDate.getHours()+offset);
      break;
    case "minutes":
      expireDate.setMinutes(expireDate.getMinutes()+offset);
      break;
    default:
      alert ("Invalid periodType parameter for writePersistentCookie()");
      break;
  } 
  
  document.cookie = escape(CookieName ) + "=" + escape(CookieValue) + "; expires=" + expireDate.toGMTString() + "; path=/";
}  

/*==============================================================================

Routine to delete a persistent cookie

    Parameters:
        CookieName        Cookie name
    
    Return value:
        true              Persistent cookie marked for deletion
    
    e.g. deleteCookie ("Session");
*/    

function deleteCookie (cookieName) {

  if (getCookieValue (cookieName)) writePersistentCookie (cookieName,"Pending delete","years", -1);  
  return true;     
}

function IsNumeric(strString)
   //  check for valid numeric strings	
   {
   var strValidChars = "0123456789.-";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
   }

function showAdsense() {
	var cl = document.getElementById("adsensediv").className;
	if (cl=="adsense") cl="showadsense"; else cl="adsense";
	document.getElementById("adsensediv").className=cl;
}

function checkCaps(oObj) {
	var val = new String(oObj.value), char, iasc;
	var sentence = new String(""), upperNext = true;
	var i, count=0, len=val.length, perc=0.5;
	
	for (i=0;i<len;i++) {
		char = val.charAt(i);
		iasc = val.charCodeAt(i);
		if (char==char.toUpperCase()) count++;
		if (char=="!" || char=="?" || char=="." || iasc==10 || iasc==13) upperNext=true;
		if ((iasc >= 65 && iasc <= 90) || (iasc >= 97 && iasc <= 122) || (iasc >= 48 && iasc <= 57)) {
			if (upperNext) {
				char= char.toUpperCase();
				upperNext = false;
			}
			else {
				char = char.toLowerCase();
			}
		}
		sentence = sentence + char;
	}
	
	if ((count/len) > perc) {
		// number of caps exceeds limit
		oObj.value = sentence;
		alert("Unfortunately you can't use excessive CAPITAL LETTERS in your advert" + String.fromCharCode(10) + "We have converted this for you so please check this before proceeding.");
		oObj.focus();
		return false;
	}
	else {
		return true;
	}
}

function toggleStockRegister(sObj) {
	var obj = document.getElementById(sObj);
	if (obj) {
		if (obj.style.display=="")
			obj.style.display="none";
		else
			obj.style.display="";
	}
}

function submitAlertRegistration(sPid) {
	var ofrm = document.getElementById("basketframe");
	var oeml = document.getElementById("alertemail");
	if (ofrm && oeml) ofrm.src = '/stockregister.asp?pid=' + sPid + '&eml=' + oeml.value;
}


function changeImg(src) {
	var spc = document.getElementById("productimgcvr");
	var img = document.getElementById("productimg")
	
	img.src = src;
	spc.height = img.height;
	spc.width = img.width;
}

function showDiv(sDiv) {
	var div = document.getElementById(sDiv);
	var downarrow = document.getElementById("downarrow_" + sDiv);
	var uparrow = document.getElementById("uparrow_" + sDiv);
	
	if(div) {
		if(div.style.display == "none") {
			div.style.display = "block";
			if(downarrow && uparrow) {
				downarrow.style.display = "none";
				uparrow.style.display = "block";
			}
		}
		else {
			div.style.display = "none";	
			if(downarrow && uparrow) {
				downarrow.style.display = "block";
				uparrow.style.display = "none";
			}
		}
	}
	
}


function clearClippings(){						   
	getAjaxConnection();
	if (aJax) {
		var url = "/includes/addclipping.asp?clear=y";
		aJax.open("GET", url, true);
		aJax.onreadystatechange = updateClippingCount;
		aJax.send();
		$(".tooltip").hide()
	}
}


/*!
 * jQuery Tools v1.2.5 - The missing UI library for the Web
 * 
 * tooltip/tooltip.js
 * 
 * NO COPYRIGHTS OR LICENSES. DO WHAT YOU LIKE.
 * 
 * http://flowplayer.org/tools/
 * 
 */
(function(a){a.tools=a.tools||{version:"v1.2.5"},a.tools.tooltip={conf:{effect:"toggle",fadeOutSpeed:"fast",predelay:0,delay:30,opacity:1,tip:0,position:["top","center"],offset:[0,0],relative:!1,cancelDefault:!0,events:{def:"mouseenter,mouseleave",input:"focus,blur",widget:"focus mouseenter,blur mouseleave",tooltip:"mouseenter,mouseleave"},layout:"<div/>",tipClass:"tooltip"},addEffect:function(a,c,d){b[a]=[c,d]}};var b={toggle:[function(a){var b=this.getConf(),c=this.getTip(),d=b.opacity;d<1&&c.css({opacity:d}),c.show(),a.call()},function(a){this.getTip().hide(),a.call()}],fade:[function(a){var b=this.getConf();this.getTip().fadeTo(b.fadeInSpeed,b.opacity,a)},function(a){this.getTip().fadeOut(this.getConf().fadeOutSpeed,a)}]};function c(b,c,d){var e=d.relative?b.position().top:b.offset().top,f=d.relative?b.position().left:b.offset().left,g=d.position[0];e-=c.outerHeight()-d.offset[0],f+=b.outerWidth()+d.offset[1],/iPad/i.test(navigator.userAgent)&&(e-=a(window).scrollTop());var h=c.outerHeight()+b.outerHeight();g=="center"&&(e+=h/2),g=="bottom"&&(e+=h),g=d.position[1];var i=c.outerWidth()+b.outerWidth();g=="center"&&(f-=i/2),g=="left"&&(f-=i);return{top:e,left:f}}function d(d,e){var f=this,g=d.add(f),h,i=0,j=0,k=d.attr("title"),l=d.attr("data-tooltip"),m=b[e.effect],n,o=d.is(":input"),p=o&&d.is(":checkbox, :radio, select, :button, :submit"),q=d.attr("type"),r=e.events[q]||e.events[o?p?"widget":"input":"def"];if(!m)throw"Nonexistent effect \""+e.effect+"\"";r=r.split(/,\s*/);if(r.length!=2)throw"Tooltip: bad events configuration for "+q;d.bind(r[0],function(a){clearTimeout(i),e.predelay?j=setTimeout(function(){f.show(a)},e.predelay):f.show(a)}).bind(r[1],function(a){clearTimeout(j),e.delay?i=setTimeout(function(){f.hide(a)},e.delay):f.hide(a)}),k&&e.cancelDefault&&(d.removeAttr("title"),d.data("title",k)),a.extend(f,{show:function(b){if(!h){l?h=a(l):e.tip?h=a(e.tip).eq(0):k?h=a(e.layout).addClass(e.tipClass).appendTo(document.body).hide().append(k):(h=d.next(),h.length||(h=d.parent().next()));if(!h.length)throw"Cannot find tooltip for "+d}if(f.isShown())return f;h.stop(!0,!0);var o=c(d,h,e);e.tip&&h.html(d.data("title")),b=b||a.Event(),b.type="onBeforeShow",g.trigger(b,[o]);if(b.isDefaultPrevented())return f;o=c(d,h,e),h.css({position:"absolute",top:o.top,left:o.left}),n=!0,m[0].call(f,function(){b.type="onShow",n="full",g.trigger(b)});var p=e.events.tooltip.split(/,\s*/);h.data("__set")||(h.bind(p[0],function(){clearTimeout(i),clearTimeout(j)}),p[1]&&!d.is("input:not(:checkbox, :radio), textarea")&&h.bind(p[1],function(a){a.relatedTarget!=d[0]&&d.trigger(r[1].split(" ")[0])}),h.data("__set",!0));return f},hide:function(c){if(!h||!f.isShown())return f;c=c||a.Event(),c.type="onBeforeHide",g.trigger(c);if(!c.isDefaultPrevented()){n=!1,b[e.effect][1].call(f,function(){c.type="onHide",g.trigger(c)});return f}},isShown:function(a){return a?n=="full":n},getConf:function(){return e},getTip:function(){return h},getTrigger:function(){return d}}),a.each("onHide,onBeforeShow,onShow,onBeforeHide".split(","),function(b,c){a.isFunction(e[c])&&a(f).bind(c,e[c]),f[c]=function(b){b&&a(f).bind(c,b);return f}})}a.fn.tooltip=function(b){var c=this.data("tooltip");if(c)return c;b=a.extend(!0,{},a.tools.tooltip.conf,b),typeof b.position=="string"&&(b.position=b.position.split(/,?\s/)),this.each(function(){c=new d(a(this),b),a(this).data("tooltip",c)});return b.api?c:this}})(jQuery);

