/* Cookie Functions */
function setCookie (name, value, expires) {
	document.cookie = name + "=" + escape(value) + ((expires)? "; domain=http://www.magnums.net;path=/; expires=" + expires.toGMTString() : "");
}
function getCookie (name) {
	var x = document.cookie.split(';');
	for (var i=0; i < x.length; i++) {
		var j = x[i].indexOf(name+'=');
		if (j >= 0) return x[i].substring(name.length+j+1);
	}
}
function delCookie (name) {
	var d = new Date(0);
	setCookie (name, "", d);
}
/* Object Functions */
function getId (str) {
	if (typeof str == 'object') return str; // Already an object
	if (document.getElementById) return document.getElementById(str);
	if (document.all) return document.all[str];
  else if (document.layers) {return document.layers(str);}
	return null; // Not supporting older methods of getting ID
}
function popUp (obj) {
	var id = getId (obj);
	if (id) id.style.display= 'block';
}
function popDown (obj) {
	var id = getId (obj);
	if (id) id.style.display= 'none';
}

/* Menu functions */
function setCat (obj,str) {
	var els = obj.getElementsByTagName("DIV");
	for (var i = 0; i <els.length; i++) {
		if (els[i].className == "SubCatMenu") els[i].style.display = str;
	}
}
function setOn (obj) {
	if (Timeout) window.clearTimeout(Timeout);
	if (CurrCat && obj != CurrCat) setCat (CurrCat, 'none');
	setCat (CurrCat = obj, 'block');
}
function setOff (obj) {
	Timeout = window.setTimeout ("setCat(CurrCat,'none')",500);
}

/* product template functions */
var image_obj;
var attribs_obj;
var sizes_link = false;
function get_object_id (str) {
  if (document.getElementById) {return document.getElementById(str);}
  else if (document.all) {return document.all(str);}
  else if (document.layers) {return document.layers(str);}
}
function popup_img () {
  attribs_obj  = get_object_id ("attribs");
  image_obj = get_object_id ("div_popup_img");
  if (attribs_obj) {
    attribs_obj.style.visibility = 'hidden';
  }
  if (image_obj) {
    image_obj.style.display= 'block';
    image_obj.style.backgroundColor = 'white';
    image_obj.style.borderColor = 'black';
    image_obj.style.zIndex = 99;
  }
}
function popdown_img () {
  image_obj.style.display = 'none';
  attribs_obj.style.visibility = 'visible';
}
function show_tartans () {
  window.open('/include/barbour_tartan.html','popup',
    'height=700,width=550,resizeable=no,toolbar=no,location=no,status=no');
}
function show_sizes () {
  window.open('/include/barbour_sizes.html','popup',
    'height=700,width=550,resizeable=no,toolbar=no,location=no,status=no');
}
function show_shipping_map () {
  window.open('/include/shipping_map.html','popup',
    'height=450,width=600,resizeable=no,toolbar=no,location=no,status=no');
}
function show_return_policy () {
  window.open('/include/return_policy.html','popup',
    'height=250,width=400,resizeable=no,toolbar=no,location=no,status=no');
}
function show_holiday_policy () {
  window.open('/include/holiday_policy.html','popup',
    'height=450,width=500,resizeable=no,toolbar=no,location=no,status=no');
}
function show_email_a_friend (prod,cat) {
  window.open('/mm5/merchant.mvc?Screen=ADS_TAF&Product_Code='+prod+'&Category_Code='+cat,'popup',
    'height=580,width=500,resizeable=no,toolbar=no,location=no,status=no');
}

/* Validate email */
function validateEmail (f) {
  var email = f.your_email.value;
  if (!email.match('.?\@.?\..?')) {
    alert ("Please enter a valid email address");
    return false;
  }
  return true;
}
function addBookmark(title,url) {
  if (window.sidebar) { 
    window.sidebar.addPanel(title, url,""); 
 } else if(window.external) {
  window.external.AddFavorite( url, title);
 } else if( window.opera && window.print ) {
   return true;
 }
}

/*Limit character count for gift wrap message*/
/**
 * DHTML textbox character counter script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */

maxL=250;
var bName = navigator.appName;
function taLimit(taObj) {
	if (taObj.value.length==maxL) return false;
	return true;
}

function taCount(taObj,Cnt) { 
	objCnt=createObject(Cnt);
	objVal=taObj.value;
	if (objVal.length>maxL) objVal=objVal.substring(0,maxL);
	if (objCnt) {
		if(bName == "Netscape"){	
			objCnt.textContent=maxL-objVal.length;}
		else{objCnt.innerText=maxL-objVal.length;}
	}
	return true;
}
function createObject(objId) {
	if (document.getElementById) return document.getElementById(objId);
	else if (document.layers) return eval("document." + objId);
	else if (document.all) return eval("document.all." + objId);
	else return eval("document." + objId);
}

/*Landing page change for specified searches*/

// Define a method that handles nothing but the actual
// form population. This helps us decouple the data
// insertion from the data retrieval.
function PopulateFields( strValue1, strValue2 ){
$( ".myScreen" ).val( strValue1 );
$( ".myCategory_Code" ).val( strValue2 );
}
 
 
// Take the given option selection and return the
// associated data.
function GetStaticValues( strOption ){

//Get the lowercase value of the input
var strOption = strOption.toLowerCase();

if (strOption == "longchamp"){
 
return({
Value1: "CTGY",
Value2: "Longchamp"
});
 
} else if (strOption == "barbour"){
 
return({
Value1: "CTGY",
Value2: "Barbour"
});

} else if (strOption == "le pliage"){
 
return({
Value1: "CTGY",
Value2: "Longchamp-Le-Pliage"
});

} else if (strOption == "house of harlow"){
 
return({
Value1: "CTGY",
Value2: "HouseofHarlow1960"
});

} else if (strOption == "longchamp le pliage"){
 
return({
Value1: "CTGY",
Value2: "Longchamp-Le-Pliage"
});

} else if (strOption == "planetes"){
 
return({
Value1: "CTGY",
Value2: "Longchamp-Planetes"
});

} else if (strOption == "tumi"){
 
return({
Value1: "CTGY",
Value2: "Tumi"
});

} else if (strOption == "pliage"){
 
return({
Value1: "CTGY",
Value2: "Longchamp-Le-Pliage"
});

} else if (strOption == "charriol"){
 
return({
Value1: "CTGY",
Value2: "Charriol"
});
 
} else {
 
// No matches, so return default value.
return({
Value1: "SRCH",
Value2: ""
});
 
}
}
 
 
// I handle the updating of the form fields based on the
// selected option of the combo box.
function UpdateFormFields(){
var jSelect = $( ".mySearchTerm" );
var objData = null;
 
 
// Make a local call to get the static data.
objData = GetStaticValues( jSelect.val() );
 
// Populate form fields.
PopulateFields( objData.Value1, objData.Value2 );
 
}
 
 
// When the DOM is ready to be interacted with, init.
$(function(){
var jSelect = $( ".mySearchTerm" );
 
// Bind the change event to the select box. We're
// just going to hand that control off to the
// handler method.
jSelect.change( UpdateFormFields );
});


/*Tabbed browsing on product page*/
function switch_tabs(tab) {
	var tabs = document.getElementById('tabs').getElementsByTagName('li').length;
	//switch off all tabs and content
	for (i=0; i < tabs; i++) {
		document.getElementById('tab'+(i+1)).className = '';
		document.getElementById('tab'+(i+1)+'_content').style.display = 'none';
	}
	//switch on the selected tab and content
	document.getElementById(tab).className = 'selected';
	document.getElementById(tab+'_content').style.display = 'block';
}

/*Image swap code*/
function HideDIV(d,delay) { 
	document.getElementById(d).style.display = "none"; 
}

function DisplayDIV(d,delay) { 
	document.getElementById(d).style.display = "block";
 }

