/* On load functions */

/* Yahoo Analytics */
var ywaDocumentGroup='';
var ywaAction='';
var ywaSKU='';

// Boot up the shadowbox plug in to display all out media. Yum!
Shadowbox.init({
	players:  ['img', 'iframe'],
	overlayOpacity: [0.4]
});

function onLoadFunctions()
	{
		/* Checks URL to find out the source, then sets a cookie */
		URLcheck();
		
		/* For product on load */
		try
			{
			showStockSingle();
			showStockMultiple();
			// ShowReviewsFrame();
			}
		catch(err)
			{
			}
		
	}

/************************************************************************/

function showContent(contentToShow) {
	document.getElementById(contentToShow).style.display = "block";
	} 

function hideContent(contentToHide) {
	document.getElementById(contentToHide).style.display = "none";
}

/************************************************************************/

// View brands drop-down menu code

function MM_jumpMenu(targ,selObj,restore){ //v3.0
	  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
	  if (restore) selObj.selectedIndex=0;
	}

/************************************************************************/

function bookmarksite(title, url){
if (document.all)
window.external.AddFavorite(url, title);
else if (window.sidebar)
window.sidebar.addPanel(title, url, "")
}

/************************************************************************/

function submitform() {
	if(document.input.SearchText.value != "" && document.input.SearchText.value != " Search our shop...") {
		$('#input').submit();
	} else {
		alert('Woah there! You have to enter a search term... \n\n(Don\'t worry, we won\'t tell anyone!)');		
	}
}
	
/************************************************************************/
function URLcheck() {
	
	var URLString = window.location.href.toLowerCase();

	if (URLString.indexOf("webgains") > 0 == true) 
		{
		javascript:createCookie('source','webgains','30');
		}
	else if (URLString.indexOf("affiliatefuture") > 0 == true) 
		{
		javascript:createCookie('source','affiliatefuture','30');
		}
	else if (URLString.indexOf("source=kelkoo") > 0 == true) 
		{
		javascript:createCookie('source','kelkoo','30');
		}
	else if (URLString.indexOf("source=shopzilla") > 0 == true) 
		{
		javascript:createCookie('source','shopzilla','30');
		}
	else if (URLString.indexOf("source=froogle") > 0 == true) 
		{
		javascript:createCookie('source','froogle','30');
		}
	else if (URLString.indexOf("gclid=") > 0 == true) 
		{
		javascript:createCookie('source','adwords','30');
		}
	else if (URLString.indexOf("source=pricegrabber") > 0 == true) 
		{
		javascript:createCookie('source','pricegrabber','30');
		}
	else if (URLString.indexOf("source=shopping") > 0 == true) 
		{
		javascript:createCookie('source','shopping','30');
		}
	else if (URLString.indexOf("source=test") > 0 == true) 
		{
		javascript:createCookie('source','test','365');
		}
	else
		{
		}
		
}

/************************************************************************/

function createCookie(name,value,days) {

	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
	
}

/************************************************************************/

function ReadCookie(cookieName) {
 var theCookie=""+document.cookie;
 var ind=theCookie.indexOf(cookieName);
 if (ind==-1 || cookieName=="") return ""; 
 var ind1=theCookie.indexOf(';',ind);
 if (ind1==-1) ind1=theCookie.length; 
 return unescape(theCookie.substring(ind+cookieName.length+1,ind1));
}

/************************************************************************/

function validate(form_id,email) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   var address = document.forms[form_id].elements[email].value;
   if(reg.test(address) == false) {
	  alert('Invalid E-mail Address');
	  return false;
   }
}

/************************************************************************/

function clear1()
{
	if(document.subscribe.email.value == "Your e-mail address" || document.subscribe.email.value == "email address")
		{
		document.subscribe.email.value = "";
		}
}

function clear2()
{
	if(document.input.SearchText.value == "Search PackYourBags" || document.input.SearchText.value == " Search our shop...")
		{
		document.input.SearchText.value = "";
		}
}

/************************************************************************/

function FeedbackPopUp()

  	{  
	window.open('http://shop.packyourbags.com/feedback/feedback-pop-up.aspx', 'Feedback', 'width=500' + ',height=440' + ',resizable=1,scrollbars=1');
	}
	
/************************************************************************/

function ShippingPopUp()

  	{  
	window.open('http://shop.packyourbags.com/content/shipping-pop-up.aspx', 'Shipping', 'width=705' + ',height=615' + ',resizable=1,scrollbars=1');
	}
	
/************************************************************************/

function ReturnsPopUp()

  	{  
	window.open('http://shop.packyourbags.com/content/returns-pop-up.aspx', 'Returns', 'width=705' + ',height=615' + ',resizable=1,scrollbars=1');
	}
	
/************************************************************************/

function ServicePopUp()

  	{  
	window.open('http://shop.packyourbags.com/content/service-pop-up.aspx', 'Service', 'width=500' + ',height=450' + ',resizable=1,scrollbars=1');
	}
	
/************************************************************************/