function addToFavourites()
{
	title = document.title;
	url = location.href;

	if (window.sidebar)
	{
		// Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url,"");
	}
	else if( window.external )
	{
		// IE Favorite
		window.external.AddFavorite( url, title);
	}
	else if(window.opera && window.print)
	{
		// Opera Hotlist
		var link = document.createElement('a');
		link.setAttribute('rel','sidebar');
		link.setAttribute('href',url);
		link.setAttribute('title',title);
		link.click();
		// return true;
	} else {
                  // Safari and others
                  alert('This function is not supported in your web browser. Please press Ctrl-D/Command-D to bookmark this page.');
         }

}

function setLocation(myURL) {
         //Moves browser to new location
	document.location = myURL;
}

function encodeURL(myStr) {
         //Returns a suitable version of string that can be used as a parameter in URL
	var returnStr = escape(myStr);
	returnStr = replaceAll(returnStr, "+", "%2B");
	returnStr = replaceAll(returnStr, "/", "%2F");
	returnStr = replaceAll(returnStr, "'", "%27");  
	return returnStr;
}

function decodeURL(myStr) {
         //Returns a URL encoded string back to normal
	var returnStr = replaceAll(myStr, "%2F", "/"); 
	returnStr = replaceAll(returnStr, "%2B", "+");
	returnStr = replaceAll(returnStr, "%27", "'"); 
         returnStr = unescape(returnStr);
	return returnStr;
}

function setFormField(myFormFieldID, myStr) {
    //Sets a form element to be 
    var x = document.getElementById(myFormFieldID);
    x.value=decodeURL(myStr);
}

function setInnerHTML(myElementID, myStr) {
    //Sets a form element to be 
    var x = document.getElementById(myElementID);
    x.innerHTML = myStr;
}


function getQueryVariable(searchStr) {
    var qryStr = window.location.href.substr(window.location.href.indexOf('?')+1);
    var returnStr = '';
    if (searchStr != '') {
         returnStr = qryStr.substr(qryStr.indexOf(searchStr)+searchStr.length+1);
         //basic URL encoding clean up
         returnStr = decodeURL(returnStr);
    }
    return returnStr;
}


function replaceAll(myStr, searchStr, replaceStr) {
	//Replaces all instances of searchStr with replaceStr in myStr (ensure search/replace not the same)
	if (myStr.indexOf(searchStr) != -1 && searchStr != replaceStr) {
		//found, so replace and recurse to remove further instances
		return replaceAll(myStr.replace(searchStr, replaceStr), searchStr, replaceStr);
	} else {
		//not found, so just return original
		return myStr;
	}
}


// SEARCH BOX VALIDATION FUNCTIONS

function checkTextEnteredRight() {
 return checkTextEntered('right_search_box');
}

function checkTextEnteredTop() {
 return checkTextEntered('search_box');
}

function checkTextEntered(id) {
 var e  = document.getElementById(id);
 var result = true;
 
 if(e.value == '') {
  alert('Please enter a search keyword');
  e.focus();
  result = false;
 }
 return result;
}


// MAIN NAVIGATION FUNCTIONS

function highlightMainNavigation(maxItem) {

// JavaScript Document

var sectionid;
var styleObject;

if(document.getElementById('section') != null) {
	sectionid 		= parseInt(document.getElementById('section').value);
	
	// Get the child nodes of the menu
	var nav 		= document.getElementById('nav');
	
	if(sectionid > 0 && sectionid <= maxItem) {
		
                  // Go back one node
                  sectionid--;			
		
		styleObject = nav.childNodes[sectionid].childNodes[0].style;
		styleObject.background = 'url(http://preview-lg.pepperio.net/assets/css/lg_style/button_active.gif) no-repeat top right';
		styleObject.color	= '#4a9f0b';

                  // Make sure all ok for next node (important for Firefox/Safari)
                  styleObject_next = nav.childNodes[sectionid+1].childNodes[0].style;
                  styleObject_next.color	= '#333333';
                  styleObject_next.background = 'none';

	}

}

}




// ADJUST TEXT SIZE FUNCTIONS AND INITIALISATION

var SMALL_SHEET 	= 'screen_small.css';
var NORMAL_SHEET	= 'screen_normal.css';
var LARGE_SHEET		= 'screen_large.css';
var HUGE_SHEET		= 'screen_huge.css';

function initTextResize() {

// When the page loads, we need to check cookies to see if the user has changed the stylesheet
if(getCookieValue('adidas_stylesheet') == '') {
	// cookie doesn't exist so set to the default sheet
	setCookieValue('adidas_stylesheet', NORMAL_SHEET, 100);
} else {
	// Set the current stylesheet to the one in the cookie	
	var curSheetPath	= document.getElementById('textSize').href;
	var newSheet		= '';
	var index		= curSheetPath.lastIndexOf('/');
	
	if(index >= 0) {
		curSheetPath	= curSheetPath.slice(0,index+1);
	}
	
	newSheet 		= getCookieValue('adidas_stylesheet');
//alert(curSheetPath + newSheet);
	if(newSheet != '') {
		document.getElementById('textSize').href = curSheetPath + newSheet;
                  //Resize the page
//alert('loc:'+curLoc);
            //      resizePage(curLoc);	
         }
}
}

function changeTextSize(dir) {
	var curSheetOrig	= document.getElementById('textSize').href;
	var curSheet		= '';
	var curSheetPath	= '';
	var newSheet		= '';
	var index		= curSheetOrig.lastIndexOf('/');
	
	if(index >= 0) {
		curSheet	= curSheetOrig.slice(index+1);
		curSheetPath	= curSheetOrig.slice(0,index+1);
	}
		
	switch(curSheet) {
		case SMALL_SHEET:
			if(dir == 'up') newSheet = NORMAL_SHEET;
			break;
		case NORMAL_SHEET:
			if(dir == 'up') newSheet = LARGE_SHEET; else newSheet = SMALL_SHEET;
			break;
		case LARGE_SHEET:
			if(dir == 'up') newSheet = HUGE_SHEET; else newSheet = NORMAL_SHEET;
			break;
		case HUGE_SHEET:
			if(dir == 'down') newSheet = LARGE_SHEET;
			break;
		default:
			newSheet = NORMAL_SHEET;
			break;
	}
	
	if(newSheet != '') {
                  document.getElementById('textSize').href = curSheetPath + newSheet;
//alert('setting cookie:'+newSheet);		
		setCookieValue('adidas_stylesheet', newSheet, 100);

                  //Resize the page again
               //   resizePage(curLoc);
	}
}


// COOKIE HANDLING FUNCTIONS

function getCookieValue(c_name) {
	if (document.cookie.length>0) {
		c_start			= document.cookie.indexOf(c_name + "=");
		
		if (c_start!=-1) { 
			c_start		= c_start + c_name.length+1;
			c_end		= document.cookie.indexOf(";",c_start);
			
			if (c_end == -1) 
				c_end	= document.cookie.length;
			
			return unescape(document.cookie.substring(c_start,c_end));
		}
	}
	
	return ""
}

function setCookieValue(c_name, value, expiredays) {
	var exdate		= new Date();
	exdate.setDate(exdate.getDate() + expiredays);
	document.cookie	= c_name+ "=" + escape(value)+
		((expiredays==null) ? "" : ";expires=" + exdate.toUTCString());
}



















































































































































