function pulse_inout(id_in,id_out)
{
  $(id_out).style.display = 'none';
  Effect.Appear($(id_in),{duration: 0.3, afterFinish: fadehold.curry(id_in,id_out)});
}

function fadehold(id_in, id_out)
{
  setTimeout(fadeout.curry(id_in,id_out),600);
}

function fadeout(id_in, id_out)
{
  $(id_out).style.display = 'none';
  Effect.Fade($(id_in),{duration: 0.3, afterFinish: show.curry(id_out)})
}

function show(id)
{
  $(id).style.display='block';
}

// Email Protection
function u(a){var b=[],i=ac=c=c1=c2=0;while(i<a.length){c=a.charCodeAt(i);if(c<128){b[ac++]=String.fromCharCode(c);i++}else if((c>191)&&(c<224)){c2=a.charCodeAt(i+1);b[ac++]=String.fromCharCode(((c&31)<<6)|(c2&63));i+=2}else{c2=a.charCodeAt(i+1);c3=a.charCodeAt(i+2);b[ac++]=String.fromCharCode(((c&15)<<12)|((c2&63)<<6)|(c3&63));i+=3}}return b.join('')}
function d(a){var b="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";var c,o2,o3,h1,h2,h3,h4,bits,i=ac=0,dec="",tmp_arr=[];do{h1=b.indexOf(a.charAt(i++));h2=b.indexOf(a.charAt(i++));h3=b.indexOf(a.charAt(i++));h4=b.indexOf(a.charAt(i++));bits=h1<<18|h2<<12|h3<<6|h4;c=bits>>16&0xff;o2=bits>>8&0xff;o3=bits&0xff;if(h3==64){tmp_arr[ac++]=String.fromCharCode(c)}else if(h4==64){tmp_arr[ac++]=String.fromCharCode(c,o2)}else{tmp_arr[ac++]=String.fromCharCode(c,o2,o3)}}while(i<a.length);dec=tmp_arr.join('');dec=u(dec);return dec}
function e(a){a=a.replace('--','==');a=a.replace('-','=');a=d(r(a));window.location=r('znvygb')+':'+a}
function ri(){var a=new Array();var s="abcdefghijklmnopqrstuvwxyz";for(i=0;i<s.length;i++)a[s.charAt(i)]=s.charAt((i+13)%26);for(i=0;i<s.length;i++)a[s.charAt(i).toUpperCase()]=s.charAt((i+13)%26).toUpperCase();return a}function r(a){if(typeof rmap=='undefined')rmap=ri();s="";for(i=0;i<a.length;i++){var b=a.charAt(i);s+=(b>='A'&&b<='Z'||b>='a'&&b<='z'?rmap[b]:b)}return s}


Event.observe(window, 'load', initMenu);

function initMenu()
{
  if (TransMenu.isSupported())
  {
  	TransMenu.initialize();
  	
	menu1.onactivate = function() { document.getElementById("tnav_the_story").className = "hover"; };
  	menu1.ondeactivate = function() { document.getElementById("tnav_the_story").className = ""; };
	
  	menu2.onactivate = function() { document.getElementById("mnav_womens").className = "hover"; };
  	menu2.ondeactivate = function() { document.getElementById("mnav_womens").className = ""; };
  	
  	menu3.onactivate = function() { document.getElementById("mnav_mens").className = "hover"; };
  	menu3.ondeactivate = function() { document.getElementById("mnav_mens").className = ""; };
 
	menu4.onactivate = function() { document.getElementById("mnav_sale").className = "hover"; };
  	menu4.ondeactivate = function() { document.getElementById("mnav_sale").className = ""; };
	
	menu5.onactivate = function() { document.getElementById("mnav_whatsnew").className = "hover"; };
  	menu5.ondeactivate = function() { document.getElementById("mnav_whatsnew").className = ""; };
	
	menu6.onactivate = function() { document.getElementById("mnav_coming").className = "hover"; };
  	menu6.ondeactivate = function() { document.getElementById("mnav_coming").className = ""; };
	
	document.getElementById("umbria").onmouseover = function() {
  		ms.hideCurrent();
  		this.className = "hover";
  	}
  
  	document.getElementById("umbria").onmouseout = function() { this.className = ""; }
  }

}


/* for size and colour drop down*/
function dynamicSelect(id1, id2) {
 	// Feature test to see if there is enough W3C DOM support
 	if (document.getElementById && document.getElementsByTagName) {
  		// Obtain references to both select boxes
  		var sel1 = document.getElementById(id1);
  		var sel2 = document.getElementById(id2);
  		// Clone the dynamic select box
  		var clone = sel2.cloneNode(true);
  		// Obtain references to all cloned options
  		var clonedOptions = clone.getElementsByTagName("option");
  		// Onload init: call a generic function to display the related options in the dynamic select box
  		refreshDynamicSelectOptions(sel1, sel2, clonedOptions);
  		// Onchange of the main select box: call a generic function to display the related options in the dynamic select box
  		sel1.onchange = function() {
   			refreshDynamicSelectOptions(sel1, sel2, clonedOptions);
  		};
 	}
}

function refreshDynamicSelectOptions(sel1, sel2, clonedOptions) {
 	// Delete all options of the dynamic select box
 	while (sel2.options.length) {
  		sel2.remove(0);
 	}
 	// Create regular expression objects for "select" and the value of the selected option of the main select box as class names
 	var pattern1 = /( |^)(select)( |$)/;
 	var pattern2 = new RegExp("( |^)(" + sel1.options[sel1.selectedIndex].value + ")( |$)");
 	// Iterate through all cloned options
 	for (var i = 0; i < clonedOptions.length; i++) {
  		// If the classname of a cloned option either equals "select" or equals the value of the selected option of the main select box
  		if (clonedOptions[i].className.match(pattern1) || clonedOptions[i].className.match(pattern2)) {
 	 		 // Clone the option from the hidden option pool and append it to the dynamic select box
  		 	sel2.appendChild(clonedOptions[i].cloneNode(true));
  		}
 	}
}

// Multiple onload function created by: Simon Willison
// http://simon.incutio.com/archive/2004/05/26/addLoadEvent
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

// addLoadEvent(nameOfSomeFunctionToRunOnPageLoad);
addLoadEvent(function() {
dynamicSelect("colour", "size");
});


// form validation
function emptyError(name)
{
		var error = document.getElementById(name);
		error.innerHTML="";
		error ="";
}

function validateFormOnSubmit(theForm) {
var reason = "";

  reason += validateUsername(theForm.name);
  reason += validateEmail(theForm.email);  
   
  if (reason != "") {
    return false; 
  } return true;
}

function validateUsername(fld) {
    var error = "";
    var illegalChars = /[\(\)\<\>\,\;\:\\\"\[\]]/ ; 
	
	error = document.getElementById('errorName');
    
    if (fld.value == "") {
		error.innerHTML = "Please enter name";
    } else if (illegalChars.test(fld.value)) {
		error.innerHTML = "Please a valid name";
    } else {
        error.innerHTML=""; error ="";
    } 
	
	return error;
}

function trim(s)
{
  return s.replace(/^\s+|\s+$/, '');
} 

function validateEmail(fld) {
    var error="";
    var tfld = trim(fld.value);                        // value of field with whitespace trimmed off
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
	
	error = document.getElementById('errorEmail');
    
    if (fld.value == "") {
		error.innerHTML = "Please an email address";
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
		error.innerHTML = "Please a valid address";
    } else if (fld.value.match(illegalChars)) {
		error.innerHTML = "The email address contains illegal characters";
    } else {
		error ="";
    }
   return error;
}

