// jellyegg javascript 

// --- Product page functions -----
 function rollout()
 {
 var img;
 img = document.getElementById('ctl00_ContentPlaceHolder_DefaultImage').value
 document.getElementById('ctl00_ContentPlaceHolder_BigImage').src = img
 }

 function showrolloverimage(imagenumber)
 {
 var img;
 img = document.getElementById('ctl00_ContentPlaceHolder_hidImage' + imagenumber).value;
 document.getElementById('ctl00_ContentPlaceHolder_BigImage').src = img;
 }

function swatchClick(id)
{
var drp=document.getElementById('ctl00_ContentPlaceHolder_opt1');
drp.selectedIndex = getOptionIndexFromValue( drp, id );
__doPostBack('ctl00$ContentPlaceHolder$opt1','');

return false;
}

function getOptionIndexFromValue(select, val) {
    for (var i = 0; i < select.options.length; i ++) {
        if (select.options[i].value == val) 
            return i;
    }
    return -1;
}
//------------

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

function getElementsByClassName(classname)
{
    var a = [];
    var re = new RegExp('\\b' + classname + '\\b');
    var els = document.getElementsByTagName("*");
    for(var i=0,j=els.length; i<j; i++)
        if(re.test(els[i].className))a.push(els[i]);
    return a;
}
/*addLoadEvent(alertish);
function alertish(){
	alert("load event working");
}*/

addLoadEvent(runBookmark);
function runBookmark(){
	var bookmark = document.getElementById("bookmark");
	if(!bookmark){ return true };
	var title = bookmark.getAttribute("title");
	bookmark.onclick = function(){
		return addBookmark(title, bookmark);
	}
}


addLoadEvent(openPopup);
function openPopup(){
	
	var popupLinks = getElementsByClassName("openPopup");
	
	for ( var i=0; i < popupLinks.length; i++ ){
		var trigger = popupLinks[i].getAttribute("className") || popupLinks[i].getAttribute("class");
		//alert(trigger);
		switch(trigger)
		{
		case "openPopup prodPopup":
			popupLinks[i].onclick = function(){
				return popup( this, "Product", "579", "692", "yes" );
			}
		break;
		case "openPopup emailPopup":
			popupLinks[i].onclick = function(){
				return popup( this, "EmailFriend", "649", "554", "" );
			}
		break;
		case "openPopup passPopup":
			popupLinks[i].onclick = function(){
				return popup( this, "Forgotten", "460", "270", "" );
			}
		break;
		case "openPopup securityCode":
			popupLinks[i].onclick = function(){
				return popup( this, "seccode", "460", "360", "" );
			}
		break;
		case "openPopup termsPopup":
			popupLinks[i].onclick = function(){
				return popup( this, "seccode", "649", "600", "yes" );
			}
		break;
		case "openPopup sizeGuide":
			popupLinks[i].onclick = function(){
				return popup( this, "seccode", "650", "600", "yes" );
			}
		break;
		}
	}
}

function popup( vURL, vWinName, vWidth, vHeight, vScrollbar)
//vWinName cannot contain spaces, leave vScrollbar blank for no scrollba
{
	if (! window.focus)return true;
	
	var vhref;
	var vSWidth = screen.width
	var vSHeight = screen.height
	
	if(vScrollbar == "yes")
	{
		vWidth = new Number(vWidth) + 16
	}
	
	var vleftPos = (vSWidth / 2) - (vWidth / 2)
	var vtopPos = (vSHeight / 2) - (vHeight / 2)
	
	if (typeof(vURL) == 'string')
	{
		vhref = vURL;
	} else {
		vhref = vURL.href;
	}
	window.open(vhref, vWinName, 'scrollbars=' + vScrollbar + ',statusbar=no,menubar=0,width=' + vWidth + ',height=' + vHeight + ',left=' + vleftPos + ',top=' + vtopPos);	
	return false;
}

function addBookmark(title,url) {
  if (window.sidebar) {
    window.sidebar.addPanel(title, url,"");
  } else if( document.all ) {
    window.external.AddFavorite( url, title);
  } else if( window.opera && window.print ) {
    return true;
  }
} 

/* function to reset all checkboxes to unchecked - pete b */
function historyBasketClearCheck()
{
var basket = document.getElementById("noteTable");
var checkBoxes = basket.getElementsByTagName("input");
var tds = basket.getElementsByTagName("td");

for ( var i=0; i<checkBoxes.length; i++ ) 
	{
	if ( checkBoxes.checked == true )
		{
		checkBoxes[i].checked = true;
		}
	else
		{
		checkBoxes[i].checked = false;
		}
	}
}

function insertAfter(newElement, targetElement){
	var parent = targetElement. parentNode;
	if (parent.lastChild == targetElement){
		parent.appendChild(newElement);
	} else {
		parent.insertBefore(newElement, targetElement.nextSibling);
	}
	
}

//addLoadEvent(breadIt);
function breadIt(){
	var breadcrumb = document.getElementById("breadCrumb");
	var list = breadcrumb.getElementsByTagName("ol");
	//var listItems = breadcrumb.list.getElementsByTagName("li");
	var links = breadcrumb.getElementsByTagName("a");
	var spacer = document.createElement("span");
	var spacerContent = document.createTextNode(" >");
	spacer.appendChild(spacerContent);
	
	//document.body.appendChild(spacer);
	breadcrumb.insertBefore(spacer, links);
	
}

addLoadEvent(faqClick);
function faqClick(){
	//loop through all question links in container and attach onclick to execute activateTip
	//pass question's id to function and append _a to get name of answer id
	if (!document.getElementById("questions")){ return false; }
	var QBox = document.getElementById("questions");
	var questionList = QBox.getElementsByTagName("a");
	if (questionList.length < 1) return false;
		for ( var i=0; i < questionList.length; i++){
			var thisq = i+1;
			//alert(which);
			questionList[i].onclick = function(){
				activateTip(this.id);
			return true;
			}
		}
}

//faqs
//declare the last var and set an initial state (to stop errors)
var last = 'q1';
function activateTip(which){
	//remove any existing highlight
	toTheTop();
	//apply the new highlight
	document.getElementById(which+'_a').className='question on';
	//set the last tag so we know which to remove next time
	last = which;
}

function toTheTop(){
//reset the background image
	document.getElementById(last+'_a').className="question";
//reset the text color
}

function ConfirmOrderEdit()
{
    var answer = confirm("Are you sure you wish to edit this order?\n---------------------------------------------------------------------\nThis order is currently in progress, and will be cancelled if you choose to edit it. Your products will be automatically added back to your basket, but you'll have to complete the checkout process again.\nAre you sure you want to edit this order?")
	return answer
}

function ValidateProductSelection(Item1, Item2)
{
    alert(Item2);
    if (Item2 == [object]) 
    {
      alert('True');  
    }
    else
    {
        alert('False');  
    } 
}