var isDOM = (document.getElementById ? true : false);
var isIE = (document.all ? true: false);
var isNS = (navigator.appName=='Netscape');
var isNS4 = (navigator.appName=='Netscape' && !isDOM ? true : false);
var isIE4 = ((isIE && !isDOM) ? true : false);
var isDyn = (isDOM || isIE4 || isNS4);
var isMO = (!document.all && document.getElementById);

///////////////////////////////////////////////////////////////
function checkEMail(emailadd) {
  var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
  if (filter.test(emailadd)) { return true; } else { return false; }
}


function emailfriend() {
  if (document.all || document.layers) {
    w = screen.availWidth;
    h = screen.availHeight;
  }

  var popW = 460, popH = 230;
  var leftPos = (w-popW)/2, topPos = (h-popH)/2;
  window.open("http://#URL_UserTemplate/1049", "EmailFriend", 'scrollbars=no,resizable=yes,width=' + popW + ',height=' + popH + ',top=' + topPos + ',left=' + leftPos)
}


function addBookmark() {
  var title = "Maximuscle - " + PageTitle ;
  if (URL_CurrentPage != "") {
  // Identify the page if, catalog or product, hot deals build correct link
  // Other wise add a link to the store home page.
  if (window.sidebar) {
    window.sidebar.addPanel(title, URL_CurrentPage(),"");
  } else if( document.all ) {
    window.external.AddFavorite(URL_CurrentPage(), title);
  } else if( window.opera && window.print ) {
    return true;
  }
  }
}

// this function gets the cookie, if it exists
function Get_Cookie( name ) {

	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) )
	{
		return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ";", len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}


function setCookie(name, value, expires, path, domain, secure) {
  var thisCookie = name + "=" + escape(value) +
  ((expires) ? "; expires=" + expires.toGMTString() : "") +
  ((path) ? "; path=" + path : "") +
  ((domain) ? "; domain=" + domain : "") +
  ((secure) ? "; secure" : "");
  document.cookie = thisCookie;
}

function printit(){
	if (window.print) {
	    window.print() ;
	} else {
	    var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
	    document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
	    WebBrowser1.ExecWB(6, 2);//Use a 1 vs. a 2 for a prompting dialog box    WebBrowser1.outerHTML = "";
	}
}


function NewWindow(mypage,myname,w,h,scroll) {
  var newwindow
  LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
  TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
  settings ='height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable';
  newwindow = window.open(mypage,'name',settings);
  if (!newwindow.opener) newwindow.opener = self;
  if (window.focus) { newwindow.focus() }
}

function add_via_popup(ProductID,w,h) {
  w=500;
  h=259;
  NewWindow(locUT + '1039?ProductID=' + ProductID,'AddToBasket',w,h,'No');
}


function add_deal_popup(ProductID,Qty,w,h) {
  w=500;
  h=325;
  NewWindow(locUT + '1042?ProductID=' + ProductID + '&Qty=1','AddToBasket',w,h,'No');
}



function MM_status()
{
void(0)
}


///////////////////////////////////////////////////////////////
// ********** Function to render the contents of the menus

function setupDDMenus() {
	ChangeLayerContent('shopMenu',"<A class=menuItem onmouseover=\"menuItemMouseover(event, 'shopMenuAllProd');\" onclick=\"return false;\" href=\"#\"><SPAN class=menuItemText>View & Buy All Products </SPAN><SPAN class=menuItemArrow>&nbsp;&nbsp;&gt;</SPAN></A><A class=menuItem href=\"javascript:goUrl(locPBL)\">View My Previous Orders</A><A class=menuItem href=\"javascript:goUrl(locCC+'1016')\">Latest Special Offers</A><A class=menuItem href=\"javascript:goUrl(locSUT+'8')\">Your 'No Hassle' Guarantee</A><A class=menuItem href=\"javascript:goUrl(locSUT+'9')\">Postage, Packing & Refunds</A><A class=menuItem href=\"javascript:goUrl(locSUT+'10')\">Shop Locator\"</A><A class=menuItem href=\"javascript:goUrl(locSUT+'11')\">Payment Security</A><A class=menuItem href=\"javascript:goUrl(locSUT+'20')\">Get Your Maximuscle Credit Card</A><A class=menuItem href=\"javascript:goUrl(locSUT+'24')\">Free Products (Z&middot;Cards)</A><A class=menuItem href=\"javascript:goUrl(locSUT+'25')\">Drug Free Statement</A><A class=menuItem href=\"javascript:goUrl(locSUT+'35' )\">Earn £££'s By Referring A Friend</A>");
	ChangeLayerContent('shopMenuAllProd',"<A class=menuItem href=\"javascript:goUrl(locUT+'649')\">View All Supplements</A><A class=menuItem href=\"javascript:goUrl(locUT+'646')\">View All Training items</A><A class=menuItem href=\"javascript:goUrl(locUT+'645')\">View All Clothes </A><A class=menuItem href=\"javascript:goUrl(locUT+'679')\">New 2003/04 Products</A><A class=menuItem href=\"javascript:goUrl(locCC+'1001')\">High Protein</A><A class=menuItem href=\"javascript:goUrl(locCC+'1002')\">Meal Replacements</A><A class=menuItem href=\"javascript:goUrl(locCC+'1003')\">Muscle & Size</A><A class=menuItem href=\"javascript:goUrl(locCC+'1004')\">Muscle & Strength</A><A class=menuItem href=\"javascript:goUrl(locCC+'1005')\">Creatine</A><A class=menuItem href=\"javascript:goUrl(locCC+'1006')\">Cutting Edge</A><A class=menuItem href=\"javascript:goUrl(locCC+'1007')\">Well Being</A><A class=menuItem href=\"javascript:goUrl(locCC+'1008')\">Energy, Endurance & Stamina</A><A class=menuItem href=\"javascript:goUrl(locCC+'1009')\">Fat Burning</A><A class=menuItem href=\"javascript:goUrl(locUT+'647')\">Maximuscle Publications</A>");
	ChangeLayerContent('readMenu',"<A class=menuItem href=\"javascript:goUrl()\" onmouseover=\"menuItemMouseover(event, 'readMenuRSupp');\" onclick=\"return false;\" ><SPAN class=menuItemText>Choosing Right Supplements</SPAN><SPAN class=menuItemArrow>&nbsp;&gt;</SPAN></A><A class=menuItem href=\"javascript:goUrl()\" onmouseover=\"menuItemMouseover(event, 'readMenuNut');\" onclick=\"return false;\" ><SPAN class=menuItemText>Learn About Nutrition</SPAN><SPAN class=menuItemArrow>&nbsp;&gt;</SPAN></A><A class=menuItem href=\"javascript:goUrl(locUT+'437')\">You’ve Heard The Rumours</A><A class=menuItem href=\"javascript:goUrl(locUT+'62')\">Articles</A><A class=menuItem href=\"javascript:goUrl(locUT+'1028')\">Product Endorsements</A><A class=menuItem href=\"javascript:goUrl(locUT+'184?184')\">Lose Body Fat</A><A class=menuItem href=\"javascript:goUrl(locUT+'185?185')\">Gain Muscle & Strength</A><A class=menuItem href=\"javascript:goUrl(locUT+'186?186')\">Increase Endurance & Stamina</A><A class=menuItem href=\"javascript:goUrl(locUT+'188')\">Indepth Supplement Research</A><A class=menuItem href=\"javascript:goUrl(locUT+'584?584')\">Daily Meal Planner</A><A class=menuItem href=\"javascript:goUrl(locUT+'216?216')\">Nutrition Planner</A><A class=menuItem href=\"javascript:goUrl(locUT+'224?224')\">Training Tips</A><A class=menuItem href=\"javascript:goUrl(locUT+'262?262')\">Training Routines & Video Demo's</A><A class=menuItem href=\"javascript:goUrl(locUT+'519?519')\">Read Latest MP Bulletin</A><A class=menuItem href=\"javascript:goUrl(locUT+'137')\">Readers Recipes</A><A class=menuItem href=\"javascript:goUrl(locUT+'917')\">Screensavers</A><A class=menuItem href=\"javascript:goUrl(locUT+'145')\">Quick Questionnaire Results</A>");
	ChangeLayerContent('readMenuRSupp',"<A class=menuItem href=\"javascript:goUrl(locUT+'43')\">If You're A Bodybuilder</A><A class=menuItem href=\"javascript:goUrl(locUT+'44')\">If You're A Powerlifter</A><A class=menuItem href=\"javascript:goUrl(locUT+'45')\">If You Play Rugby</A><A class=menuItem href=\"javascript:goUrl(locUT+'46')\">If You Play Football</A><A class=menuItem href=\"javascript:goUrl(locUT+'47')\">If You're A Boxer</A><A class=menuItem href=\"javascript:goUrl(locUT+'48')\">If You're In The Military</A><A class=menuItem href=\"javascript:goUrl(locUT+'49')\">If You're A Long Distance Runner</A><A class=menuItem href=\"javascript:goUrl(locUT+'50')\">If You're A Sprinter</A><A class=menuItem href=\"javascript:goUrl(locUT+'51')\">If You're A Cyclist</A><A class=menuItem href=\"javascript:goUrl(locUT+'52')\">If You're A Martial Artist</A><A class=menuItem href=\"javascript:goUrl(locUT+'53')\">If You're A Swimmer</A>");
	ChangeLayerContent('readMenuNut',"<A class=menuItem href=\"javascript:goUrl(locUT+'57')\">Protein</A><A class=menuItem href=\"javascript:goUrl(locUT+'58')\">Creatine</A><A class=menuItem href=\"javascript:goUrl(locUT+'59')\">Carbohydrate</A><A class=menuItem href=\"javascript:goUrl(locUT+'60')\">Fat</A><A class=menuItem href=\"javascript:goUrl(locUT+'61')\">Health</A>");
	ChangeLayerContent('contactMenu',"<A class=menuItem href=\"javascript:goUrl(locUT+'735')\">Welcome Note</A><A class=menuItem href=\"javascript:goUrl(locUT+'926')\">You’ve Heard The Rumours</A><A class=menuItem href=\"javascript:goUrl(locUT+'382')\">Contact Us</A><A class=menuItem href=\"javascript:goUrl(locUT+'384')\">Events We Sponsor</A><A class=menuItem href=\"javascript:goUrl(locUT+'153')\">Who We Sponsor</A><A class=menuItem href=\"javascript:goUrl(locUT+'736')\">How To Apply For Sponsorship</A><A class=menuItem href=\"javascript:goUrl(locUT+'325')\">Media Profile</A><A class=menuItem href=\"javascript:goUrl(locUT+'764')\">Vacancies</A>");
	ChangeLayerContent('suppMenu',"<A class=menuItem href=\"javascript:goUrl(locUT+'378')\">Combining & Stacks</A><A class=menuItem href=\"javascript:goUrl(locUT+'379')\">Lose Body Fat</A><A class=menuItem href=\"javascript:goUrl(locUT+'380')\">Gain Muscle & Strength</A><A class=menuItem href=\"javascript:goUrl(locUT+'381')\">Increase Endurance & Stamina</A>");
	ChangeLayerContent('testMenu',"<A class=menuItem href=\"javascript:goUrl(locUT+'326')\">Life-Changing Stories</A><A class=menuItem href=\"javascript:goUrl(locUT+'955')\">Testimonials</A>")
	ChangeLayerContent('downMenu',"<A class=menuItem href=\"javascript:goUrl(locUT+'136')\">MP Bulletin</A>")
}


function ChangeLayerContent(id, str) {
  if (isIE) {
    document.all[id].innerHTML = str;
  }
  if (isNS || isNS4) {
    document.layers[id].document.open();
    document.layers[id].document.write(str);
    document.layers[id].document.close();
  }
  if (isMO) {
    document.getElementById(id).innerHTML = str;
  }
}


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_findObj(n, d) { //v4.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);
  if(!x && document.getElementById) x=document.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 jump_dse(url){
    window.location.href = "http://store.maximuscle.com/cgi-bin/maximuscle.storefront/ES/" + url;
}

function add_to_basket(prod){
   var qty = parseInt(document.forms["productForm"].Qty.value);
   if (isNaN(qty)){
      alert("Quantity is not a number");
   }else{
      window.location.href = "http://#URL_Store/Offer/AddProduct/" + prod + "/" + qty;
   }
}

function submit_offer(prod){
   var qty = parseInt(document.forms["offer"].Qty.value);
   if (isNaN(qty)){
         alert("Quantity is not a number");
         return false;
   }

   if (document.forms["offer"].variants.value == 0){
         window.location.href="http://#URL_Store/Offer/AddProduct/" + prod + "/" + qty;
         return false;
   }else{
     //offer has variants so use normal variant submission URL
     return true;
   }
//end function
}

function SwapImage(imgNum,imgSrc)
{document.images[imgNum].src = imgSrc;}

function roundOff(value, precision)
{
        value = "" + value //convert value to string
        precision = parseInt(precision);

        var whole = "" + Math.round(value * Math.pow(10, precision));

        var decPoint = whole.length - precision;

        if(decPoint != 0)
        {
                result = whole.substring(0, decPoint);
                result += ".";
                result += whole.substring(decPoint, whole.length);
        }
        else
        {
                result = whole;
        }
        return result;
}

function set_visibility(elementID,vis){

var obj = null;
  if ((isIE)){
     //alert("I is IE!");
     obj = document.all[elementID];
  }

  if ((isDOM) && !(isIE)){
     //alert("I is DOM!");
     obj = document.getElementById(elementID);
  }

  if (isNS4){
     obj = document.layers[elementID];
  }

  if (obj != null){
     if (isIE || isDOM){
       obj.style.visibility = vis;
       //alert(obj.style.visibility);
     }else{
       if (vis == "visible"){
          obj.visibility = "show";
       }else{
          obj.visibility = "hide";
       }
     }
  }

}

//////////////////////////////////////
// homepage
// Fat Burning Products / Discontinued Product Template
function getCookieData(label) {
  var labelLen = label.length
  var cLen = document.cookie.length
  var i = 0
   while (i < cLen) {
    var j = i + labelLen
     if (document.cookie.substring(i,j) == label) {
     var cEnd = document.cookie.indexOf(";",j)
      if (cEnd == -1) {
      cEnd = document.cookie.length
      }
     return unescape(document.cookie.substring(j+1,cEnd))
     }
   i++
  }
  return ""
 }

pu=0;
function openNL(url) {
gispopup=url;
tid = setTimeout("openNL(gispopup)",7000);
 if (pu==1){
 window.open(url,"Newsletter","scrollbars=no,resizable=yes,width=460,height=355,topmargin=0,leftmargin=0")
 }
pu+=1;
if (pu >= 2){clearTimeout(tid);}
}

 if ('#ProductNo' == 'MHCR-1'){
  if (getCookieData("subscribed") != '1') {
  openNL('http://www.maximuscle.com/popup.html');
  }
 }
////////////////////////////////////////////////////////////
// function showquestions(){
//  if (getCookieData("questionnaire") != '6') {
//    self.name='mainWin';
//  window.open('http://www.maximuscle.com/quick_questionaire.html','Questionnaire','scrollbars=no,resizable=yes,width=505,height=315,topmargin=0,leftmargin=0')
//  }
// }
//////////////////////////////////////

// Catalog Templates / Category, special offers
/*
function jump_template(str){
    window.location.href = "http://#URL_Store/UserTemplate/" + str;
}
*/

//////////////////////////////////////

function goUrl(url) {
	window.location.href = url;
}

function popwindow(url){
   window.open('http://#URL_Store/UserTemplate/21?target='+url,'popwin','width=620,height=400,toolbar=no, menubar=no, scrollbars=auto, resizable=no,location=no, directories=no, status=no');
}

function popmagoffer(){
   window.open('http://#URL_Store/UserTemplate/214?ProductNo=150SUB','popwin','width=620,height=690,toolbar=no, menubar=no, scrollbars=yes, resizable=no,location=no, directories=no, status=no');
}

function popwindow(url){
   window.open('http://#URL_Store/UserTemplate/21?target='+url,'popwin','width=620,height=400,toolbar=no, menubar=no, scrollbars=auto, resizable=no,location=no, directories=no, status=no');
}

 // homepage
 function openPlanner(){
 window.open('/nutritionplan.html','nutritionplan','scrollbars=yes,resizable=yes,width=590,height=480,topmargin=0,leftmargin=0');
 }

// homepage
function openefriend() {
window.open("http://www.maximuscle.co.uk/cgi-bin/maxiboard/send/efriend.pl?t="+document.title+"&u="+document.URL,"EmailAFriend","scrollbars=no,resizable=yes,width=320,height=270,topmargin=0,leftmargin=0");
}

// homepage
function popupbase() {
 Newsletter = open("http://www.maximuscle.com/popup.html","Newsletter","scrollbars=yes,resizable=no,width=400,height=400,topmargin=0,leftmargin=0");
 Newsletter.focus();
}

function siteseal(url) {
sealWin=window.open(url,"win",'toolbar=0,location=0,directories=0, status=1,menubar=1,scrollbars=1,resizable=1,WIDTH=500,height=450');
self.name = "mainWin";
}
///////////////////////////////////////

function mmBlink()
{
	if (!document.all) return;
	else
		{
		for(i=0;i<document.all.tags('blink').length;i++){
		s=document.all.tags('blink')[i];
		s.style.visibility=(s.style.visibility=='visible')?'hidden':'visible';
		}
	}
}
setInterval('mmBlink()',800)

///////////////////////////////////////
// function to open a window with its contents // Naveed
var mmWindow = null;
function mmWin(Wurl,Wname,Ww,Wh,Wbars,Wpos)
{
if(Wbars=="yes") wBars='scrollbars=yes,location=yes,directories=yes,status=yes,menubar=yes,toolbar=yes,resizable=yes';
if(Wbars=="no") wBars='scrollbars=no,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
if(Wbars=="auto") wBars='scrollbars=yes,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=yes';
if(Wbars=="fixed") wBars='scrollbars=yes,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';

if(Wpos=="middle")
{WLPos=(screen.width)?(screen.width-Ww)/2:100; WTPos=(screen.height)?(screen.height-Wh)/2:100;}//it means if screen.width property exists, else its 100
if(Wpos=="corner")
{WLPos=0; WTPos=0;}
if(Wpos=="random")
{WLPos=(screen.width)?Math.floor(Math.random()*(screen.width-Ww)):100; WTPos=(screen.height)?Math.floor(Math.random()*((screen.height-Wh)-75)):100;}
if(Wpos!=("middle" && "corner" && "random"))
{WLPos=Wpos; WTPos=Wpos;}

wFeatures='width='+Ww+',height='+Wh+',top='+WTPos+',left='+WLPos+','+wBars;
mmWindow=window.open(Wurl,Wname,wFeatures);
mmWindow.focus();
}
///////////////////////////////////////


function nutriline(pageSource)
{
nutrilineWin=window.open()
nutrilineWin.document.write('<frameset framespacing="0" border="0" rows="75,*" frameborder="0">'

+'<frame name="top" src="http://www.nutriline.org/mus/top.html" scrolling="no" noresize marginwidth="0" marginheight="0">'

+'<frameset cols="80%,20%">'
+'<frame name="content" src="http://www.nutriline.org/mus/'+pageSource+'" marginwidth="0" marginheight="0" scrolling="yes">'
+'<frame name="navigation" src="http://www.nutriline.org/mus/navigation.html" target="content" marginwidth="5" marginheight="5" scrolling="auto" noresize>'
+'</frameset>'

+'<noframes>'
+'<body><p>This page uses frames but your browser does not support them.</p></body>'
+'</noframes>'

+'</frameset>');
}

///////////////////////////////////////

function mmAddFav()  {
netscape="First push OK and then hit CTRL+D to add a bookmark to this site."
if (navigator.appName=='Microsoft Internet Explorer')
{
window.external.AddFavorite("http://www.maximuscle.com","Maximuscle - sports nutrition at its best");
} else if (navigator.appName=='Netscape')
{
alert(netscape);
}
}

function opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
}

function shiftOpacity(id, millisec) {
    //if an element is invisible, make it visible, else make it ivisible
    if(document.getElementById(id).style.opacity == 0) {
        opacity(id, 0, 100, millisec);
    } else {
        opacity(id, 100, 0, millisec);
    }
}
