function winPopUp(url,w,h) 
{
	win=window.open(url,'dolphinfitness','toolbar=0, location=0,directories=0,status=0,menubar=0,scrollbars=no,resizable=yes,top=100,left=100,width='+w+',height='+h);
}

function photoPopUp(src, desc)
{
	ShowLargeProductPicture (src);
}

function infoPopUp(secure, v)
{
	if (secure)
	{
		winPopUp('/fitness/info?' + v, 200, 200);
	}
	else
	{
		winPopUp('/info?' + v, 400, 400);
	}
}

function setCurrency (id, jump)
{
	document.location='/do/set-currency/' + id + '/?jump=' + jump; 
}

function setLanguage (id, jump)
{
	document.location='/do/set-language/' + id + '/?jump=' + jump; 
}


function ChangeInnerHTML(LayerName, TSV1) 
{
    if (document.layers) 
	{
		TP = document.layers[LayerName].document; TP.open(); TP.write(TSV1); TP.close();
	}
    else if (document.getElementById) 
	{
		document.getElementById(LayerName).innerHTML = TSV1;
	}
	else if (document.all) 
	{
		document.all[LayerName].innerHTML = TSV1;
	}
}


function AppendInnerHTML(LayerName, TSV1) 
{
    if (document.layers) 
	{
		TP = document.layers[LayerName].document; TP.open(); TP.write(TSV1); TP.close();

	}
    else if (document.getElementById) 
	{
		document.getElementById(LayerName).innerHTML += TSV1;
	}
	else if (document.all) 
	{
		document.all[LayerName].innerHTML += TSV1;
	}
}

function ChangeInnerText(LayerName, TSV1) 
{
    if (document.layers) 
	{
		TP = document.layers[LayerName].document; TP.open(); TP.write(TSV1); TP.close();
	}
    else if (document.getElementById) 
	{
		document.getElementById(LayerName).innerText = TSV1;
	}
	else if (document.all) 
	{
		document.all[LayerName].innerText = TSV1;
	}
}



function FocusOnSearch (obj)
{
	obj.innerText = '';
}

function ToggleTextSize ()
{
	var E = GetElement ("enlarge_text");
	var islarge = (E.innerText == "Reduce text size");

	if (islarge)
	{
	    E = GetElement ("content");
		E.style.fontSize = "100%";

		E = GetElement ("contents");
		E.style.fontSize = "100%";

		E = GetElement ("enlarge_text");
		E.innerText = "Enlarge text"; 
	}
	else
	{
	    E = GetElement ("content");
		E.style.fontSize = 10 + "pt";

		E = GetElement ("contents");
		E.style.fontSize = 9 + "pt";

		E = GetElement ("enlarge_text");
		E.innerText = "Reduce text size"; 
	}
}

function tab_menu_on (n)
{ 
	E = GetElement ("tab_menu_" + n);
	F = GetElement ("tab_menu_li_0");

	if ( (E != null) && (F != null) )
	{
		TV1 = F.offsetHeight;

		TV2 = 0;
		for (TV3 = 0 ; TV3 < n ; TV3 ++)
		{
			F = GetElement ("tab_menu_li_" + TV3);

			if ( F != null )
			{
				TV2 += parseInt (F.offsetWidth) + 2;
			}
		}
		E.style.position = "absolute";
		E.style.visibility = "visible"; 
		E.style.left = TV2 + "px";
		E.style.top = TV1 + "px";
	}
}

function setprodphoto (url)
{
	E = GetElement ("prodphoto");
	
	if ( E != null )
	{ 
		E.src = url; 
	}
}

function tab_menu_off (n)
{
	E = GetElement ("tab_menu_" + n);
	
	if ( E != null )
	{
		E.style.visibility = "hidden"; 
	}
}

function AddFavourite ()
{
   if (document.all)
   {
      window.external.AddFavorite ("http://www.dolphinfitness.co.uk","Dolphin Fitness");
   }
 }


function submit_payment (totalprice, deliveryoption)
{
	ChangeInnerText("totalprice", totalprice);
	
    E = GetElement ("delivery_option");
    
	  if ( E != null )
	  {
		 E.value = deliveryoption;  
	  }
	  
 	return true; 
}

function setDeliveryOption (totalprice, deliveryrequest, deliveryband, deliveryrate)
{
	ChangeInnerText("totalprice", totalprice);
	
    E = GetElement ("delivery_option");
    
	  if ( E != null )
	  {
		 E.value = deliveryband;  
	  }
	  
    F = GetElement ("delivery_request");
    
	  if ( F != null )
	  {
		 F.value = deliveryrequest;
	  }

    G = GetElement ("delivery_rate");
    
	  if ( G != null )
	  {
		 G.value = deliveryrate;
	  }

 	return true; 
}

function ALTsetDeliveryOption (totalprice, deliveryrequest, deliveryband, deliveryrate)
{
	ALTChangeInnerText("totalprice", totalprice);
	
    E = GetElement ("delivery_option");
    
	  if ( E != null )
	  {
		 E.value = deliveryband;  
	  }
	  
    F = GetElement ("delivery_request");
    
	  if ( F != null )
	  {
		 F.value = deliveryrequest;
	  }

    G = GetElement ("delivery_rate");
    
	  if ( G != null )
	  {
		 G.value = deliveryrate;
	  }

 	return true; 
}

function ALTChangeInnerText(LayerName, TSV1) 
{
    if (document.layers) 
	{
		TP = document.layers[LayerName].document; TP.open(); TP.write(TSV1); TP.close();
	}
    else if (document.getElementById) 
	{
		document.getElementById(LayerName).innerText = TSV1;
	}
	else if (document.all) 
	{
		document.all[LayerName].innerText = TSV1;
	}
}


function update_basket (e)
{
   if ( e == null ) return true;
	
   ids = e.split(",");
   x = ids.length;
   y = 0;

   for (i=0; i <= x; i++)
   {	  
	  E = GetElement ("update_qty[" + ids[i] + "]");
	  F = GetElement ("v[update_new_qty_" + ids[i] + "]");
	
	  if ( (E != null) && (F != null) )
	  {
		 if ( F.value != E.value )
		 {
		 	F.value = E.value; 
		 	
		 	y ++;
		 }
	  }
   }
   
  if (y == 0) 
  {
  	alert ("Click 'checkout' to proceed");
  	
  	return false;
  }

  G = GetElement ("basket_update_submit");
  
  if (G != null)
  {
  	G.style.visibility = "hidden";
  	ChangeInnerHTML ("basket_update_loading", "Please Wait ...");
  }

   return true;
}

function submit_package (n)
{

	add_gift_pid (1);
	
   A = GetElement ("buyoptions");
   if (A == null) return false;

   B = GetElement ("package_id");
   if (B == null) return false;
   
   B.value = n;
   
   return A.submit();
}

function submit_order (a, b, c, d)
{
	add_so_buys(a);
	add_also_pids(b);
	add_gift_pid(c);

	add_multi_buys(d);
	
	return true;
}

function add_also_pids (n)
{
   A = GetElement ("also_pids");
   if (A == null) return true;
 
   v = "";
	
   for (i=1; i<=n; i++)
   {	  
	  E = GetElement ("also_pid[" + i + "]");
	  if ( (E != null) && (E.checked) )
	  {
		 v += E.value + ",";  
	  }
   }
   A.value = v;

   return true;
}

function add_multi_buys (n)
{
   A = GetElement ("multi_pids");
   if (A == null) return true;
   
 
   v = "";
   
   ids = n.split(",");
   x = ids.length;
 	
   for (i=0; i <= x; i++)
   {	  
	  E = GetElement ("multibuy_pid[" + ids[i] + "]");
	
	  if ( (E != null) )
	  {
		 v += ids[i] + "[" + E.value + "]";  
	  }
   }
   A.value = v;
   

   return true;
}

function add_so_buys (n)
{
   A = GetElement ("so_buys");
   if (A == null) return true;
 
   v = "";
	
   for (i=1; i<=n; i++)
   {	  
	  E = GetElement ("so_buy[" + i + "]");
	  if ( (E != null) && (E.checked) )
	  {
		 v += E.value + ",";  
	  }
   }
   A.value = v;

   return true;
}

function add_gift_pid (n)
{
   A = GetElement ("gift_pid");
   if (A == null) return true;

   B = GetElement ("select_gift_pid");
   if (B == null) return true;


   A.value = B.value;

   return true;
}


EnquiryHandler = '/do/register-enquiry';



function CreateMenu (TP1, TSV1) {
 var TV1, TV2, TP2, TP3, TSV2;

 TV1 = TSV1.split('_').length;
 TV2 = 0;

 for (TP2 in TP1) {

  TV2++;
  TSV2 = TSV1 + '_' + TV2;

  if ((typeof TP1[TP2]) == 'object') {

   document.write("<DIV id='Menu_" + TSV2 + "' class='MenuLevel" + TV1 + "' onmouseover='HandleOnMouseOver(\"" + TSV2 + "\", " + TV1 + ", true)' onmouseout='HandleOnMouseOut(\"" + TSV2 + "\", " + TV1 + ", true)'>");
    document.write(TP2);
    document.write("<DIV id='Menu_" + TSV2 + "L' style='VISIBILITY:hidden; POSITION:fixed; Z-INDEX:" + (TV1 * 10) + "'>");
     CreateMenu(TP1[TP2], TSV2);
    document.write("</DIV>");
   document.write("</DIV>");

  } else if (TP1[TP2] == '') {

   document.write(
    "<DIV id='Menu_" + TSV2 + "' class='MenuHeaderLevel" + TV1 + "'>"
   + TP2
  + "</DIV>"
   );

  } else {

   document.write(
    "<A href='" + TP1[TP2] + "' class='MenuLinkLevel" + TV1 + "'>"
   + "<DIV id='Menu_" + TSV2 + "' class='LinkMenuLevel" + TV1 + "' style='CURSOR:pointer' onmouseover='HandleOnMouseOver(\"" + TSV2 + "\", " + TV1 + ", false)' onmouseout='HandleOnMouseOut(\"" + TSV2 + "\", " + TV1 + ", false)'>"
    + TP2
   + "</DIV>"
  + "</A>"
   );

  }
 }
}


function ShowMenu (TSV1) {
	
	var TSV2, TV1, TV2, TV3, TV4, TA1, TA2, TA3, TP1, TP2, TP3;
	
	TA2 = TSV1.split('_');
	TSV2 = 'Menu_' + TA2[0] + '_' + TA2[1];
	TP2 = GetElement(TSV2);
	
	TA1 = FindPosition(TP2);

	TV3 = TA1['Left'] + TP2.offsetWidth;
	TV4 = TA1['Top'];

	TV1 = TA2.length;
	for (TV2 = 2; TV2 <= TV1 - 1; TV2++) {
	
		TSV2 += '_' + TA2[TV2];
		TP3 = GetElement(TSV2);
		TV3 += TP3.offsetWidth;
	
		TV4 += (parseInt(TA2[TV2]) - 1) * (TP3.offsetHeight - Menu_ReverseMargin);
 	}
 	
 	TP1 = GetElement('Menu_' + TSV1 + 'L');
 	TP1.style.visibility = 'visible';
 	
 	TA3 = GetScrollXY()
 	TP1.style.left = (TV3 - TA3[0] - ((TV1 - 1) * Menu_ReverseOffset)) + 'px';
 	TP1.style.top = (TV4 - TA3[1]) + 'px';
 	
 	return;
}

function HideMenu (TSV1) {
 GetElement('Menu_' + TSV1 + 'L').style.visibility = 'hidden';
}

function HandleOnMouseOut (TSV1, TV1, TBV1) {
 if (TBV1) {
  HideMenu(TSV1);
 }
 GetElement('Menu_' + TSV1).className = (TBV1 ? '' : 'Link') + 'MenuLevel' + TV1;
}

function HandleOnMouseOver (TSV1, TV1, TBV1) {
 if (TBV1) {
  ShowMenu(TSV1);
 }
 GetElement('Menu_' + TSV1).className = (TBV1 ? '' : 'Link') + 'MenuLevel' + TV1 + 'Over';
}

function ReplaceAll (TSV1, TSV2, TSV3) {
 if (TSV2 != TSV3) {
  while (TSV1.indexOf(TSV2) != -1) {
   TSV1 = TSV1.replace(TSV2, TSV3);
  }
 }
 return TSV1;
}

function FindPosition (TP1) {
 var TA1 = {
  'Left':0,
  'Top':0
 };

 if (TP1.offsetParent) {
  do {
   TA1['Left'] += TP1.offsetLeft;
   TA1['Top'] += TP1.offsetTop;

  } while ((TP1.style.position != 'fixed') && (TP1 = TP1.offsetParent));
 }

 return TA1;
}

function GetScrollXY () {
 var scrOfX = 0, scrOfY = 0;

 if (typeof(window.pageYOffset) == 'number') {
  scrOfY = window.pageYOffset;
  scrOfX = window.pageXOffset;
 } else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
  scrOfY = document.body.scrollTop;
  scrOfX = document.body.scrollLeft;
 } else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
  scrOfY = document.documentElement.scrollTop;
  scrOfX = document.documentElement.scrollLeft;
 }

 return [scrOfX, scrOfY];
}

function GetElement (TSV1) 
{
  if (document.getElementById) 
  {
    if (document.getElementById(TSV1) != null) 
    {
   	   return document.getElementById(TSV1);
    }
  }
  
  if (document.all)
  {
  	return document.all[TSV1];
  }
  return null;
}

function ReplaceAll (TSV1, TSV2, TSV3) {
 if (TSV2 != TSV3) {
  while (TSV1.indexOf(TSV2) != -1) {
   TSV1 = TSV1.replace(TSV2, TSV3);
  }
 }
 return TSV1;
}

function win_center(e)
{
  var box = GetElement(e);
  
  boxw = 1000;

  var TA1 = GetWindowDimensions ();

  var x = (TA1[0] / 2) - (boxw / 2) - 10;
  

  box.style.left = x + "px";
  box.style.display = "block";
 }
 
function GetWindowDimensions () {
                var myWidth = 0, myHeight = 0;
 
                if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
                                myWidth = document.body.clientWidth;
                                myHeight = document.body.clientHeight;
                } else if (typeof(window.innerWidth) == 'number') {
                                myWidth = window.innerWidth;
                                myHeight = window.innerHeight;
                } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
                                myWidth = document.documentElement.clientWidth;
                                myHeight = document.documentElement.clientHeight;
                }
 
                return [myWidth, myHeight];
}

function SetElementOpacity (TSV1, TSV2) {
	var TP1;

	TP1 = GetElement(TSV1).style;
	TP1.filter = (TSV2 != '' ? 'alpha(opacity=' + (TSV2 * 100) + ')' : '');
	if (TP1.setProperty) {
		TP1.setProperty('opacity', TSV2, '');
		TP1.setProperty('-moz-opacity', TSV2, '');
		TP1.setProperty('-khtml-opacity', TSV2, '');
	}
}

function MoveLargeProductPictureLayer () {
	var TA1, TA2;

	TA1 = GetWindowDimensions();
	TA2 = GetScrollXY();
	GetElement('HiddenLayer').style.left = ((TA1[0] - GetElement('ProductLargePicture').width) / 2) + "px";
	GetElement('HiddenLayer').style.top = (TA2[1] + 60) + "px";

}

function ShowLargeProductPicture (id) {
	var TSV1, TP1;

	TSV1 = "<TABLE cellpadding='1' cellspacing='0' style='BORDER: 1px solid #000'>"
	      + "<TR style='BACKGROUND:#f0f7ff'>"
	       + "<TD style='TEXT-ALIGN:right; PADDING-RIGHT:5px'>"
	        + "<A href='javascript:HideLargeProductPicture()'><IMG src='/u/001-close.gif' alt='Close'></A>"
	       + "</TD>"
	       + "</TR>"
	       + "<TR>"
	        + "<TD style='BACKGROUND:#E0E7F0'>"
	         + "<IMG id='ProductLargePicture' src='/rs/pictures/" + "tn1_" + id + ".jpg' onclick='HideLargeProductPicture()'>"
	        + "</TD>"
	       + "</TR>"
	      + "</TABLE>";
	ChangeInnerHTML('HiddenLayer', TSV1);

	SetElementOpacity('outline', '0.25');

	GetElement('HiddenLayer').style.visibility = 'visible';

	GetElement('ProductLargePicture').onload = MoveLargeProductPictureLayer;
}



function HideLargeProductPicture () {
	var TP1;

	GetElement('HiddenLayer').style.visibility = 'hidden';

	SetElementOpacity('outline', '');
}

function ShowPromoInfo () {
	var TSV1, TP1;

	TSV1 = "<TABLE cellpadding='1' cellspacing='0' style='BORDER: 1px solid #000; width: 300px;'>"
	      + "<TR style='BACKGROUND:#f0f7ff'>"
	       + "<TD style='TEXT-ALIGN:right; PADDING-RIGHT:5px'>"
	        + "<A href='javascript:HideLargeProductPicture()'><IMG src='/u/001-close.gif' alt='Close'></A>"
	       + "</TD>"
	       + "</TR>"
	       + "<TR style='BACKGROUND:#fff;'>"
	        + "<TD style='BACKGROUND:#fff; padding: 10px 10px 20px 10px; text-align: justify'>"
	         + promo
	         + "<br /><br /><a href='/en/promotions'>Click here to see other promotions</a>"
	        + "</TD>"
	       + "</TR>"
	      + "</TABLE>";
	ChangeInnerHTML('HiddenLayer', TSV1);

	SetElementOpacity('outline', '0.25');

	GetElement('HiddenLayer').style.visibility = 'visible';

	TA1 = GetWindowDimensions();
	TA2 = GetScrollXY();
	GetElement('HiddenLayer').style.left = ((TA1[0] - 300) / 2) + "px";
	GetElement('HiddenLayer').style.top = (TA2[1] + 60) + "px";
}


function doPromotion (x, exec) {
	var TSV1, TSV2, TP1;

	if ( exec == 1 )
	{
		TSV2 = "<iframe src='/do/promotion/id/" + x + "' scrolling='no' frameborder='0' width='100%' height='6px'></iframe>"
			 + promoWhatNow;
	}
	else
	{
		TSV2 = promoWhatNow;
	}

	TSV1 = "<TABLE cellpadding='1' cellspacing='0' style='BORDER: 1px solid #000; width: 460px;'>"
	      + "<TR style='BACKGROUND:#f0f7ff'>"
	       + "<TD style='TEXT-ALIGN:right; PADDING-RIGHT:5px'>"
	        + "<A href='javascript:HideLargeProductPicture()'><IMG src='/u/001-close.gif' alt='Close'></A>"
	       + "</TD>"
	       + "</TR>"
	       + "<TR style='BACKGROUND:#fff;'>"
	        + "<TD style='BACKGROUND:#fff; padding: 10px 10px 20px 10px; text-align: justify'>"
	         + "<h3>" + promoArray[x].t + "</h3>"
	         + "<img src='" + promoArray[x].i + "' style='float:right;border:1px solid #c0d0e0;margin: 0 0 10px 10px'>"
	         + promoArray[x].n
	         + "<div style='width:100%;clear:both;border-top:1px solid #c0d0e0;padding:6px 0 6px 0;margin: 6px 0 0 0;'>"
	         + TSV2
	         + "</div>"
	        + "</TD>"
	       + "</TR>"
	      + "</TABLE>";
	ChangeInnerHTML('HiddenLayer', TSV1);

	SetElementOpacity('outline', '0.25');

	GetElement('HiddenLayer').style.visibility = 'visible';

	TA1 = GetWindowDimensions();
	TA2 = GetScrollXY();
	GetElement('HiddenLayer').style.left = ((TA1[0] - 460) / 2) + "px";
	GetElement('HiddenLayer').style.top = (TA2[1] + 60) + "px";
	
	if (exec == 1) GetElement('promo_hlink').href = promoArray[x].h;
}
