function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}


function zoomthis(styleno) {

	var is_zoom_on = getCookie("zoom");
	var current_colour = getCookie("colour");
	if (is_zoom_on == 'on') {
		window.open('zoom.html?image=' + styleno +'&dir=item_back_zoom','window'+styleno+'','width=450,height=650');
	}
	if (is_zoom_on == 'off') {
		window.open('zoom.html?image=' + current_colour +'&dir=zoom','window'+styleno+'','width=450,height=650');
	}
	else {
		window.open('zoom.html?image=' + styleno +'&dir=item_back_zoom','window'+styleno+'','width=450,height=650');
	}
}

function newzoomthis(styleno) {

	var is_zoom_on = getCookie("zoom");
	var current_colour = getCookie("colour");
	if (is_zoom_on == 'on') {
		window.open('zoom.html?image=' + styleno +'&dir=item_back_zoom','window'+styleno+'','width=450,height=650');
	}
	if (is_zoom_on == 'off') {
		window.open('zoom.html?image=' + current_colour +'&dir=zoom','window'+styleno+'','width=450,height=650');
	}
	else {
		window.open('zoom.html?image=' + styleno +'&dir=item_back_zoom','window'+styleno+'','width=450,height=650');
	}
}



function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_changeProp(objName,x,theProp,theValue) { //v6.0
  var obj = MM_findObj(objName);
  if (obj && (theProp.indexOf("style.")==-1 || obj.style)){
    if (theValue == true || theValue == false)
      eval("obj."+theProp+"="+theValue);
    else eval("obj."+theProp+"='"+theValue+"'");
  }
}
 

function swapOptions(the_array_name)
{
	MM_swapImage('mainpic','','images/items/detail/' + the_array_name + '.html',1);
	SetCookie('colour', the_array_name ,'1');
}

function colourchecker(the_array_name)
{
	var numbers_select = window.document.the_form.colour;
	var the_array2 = eval(the_array_name);
	setOptionText(window.document.the_form.colour, the_array2);
}

function setOptionText(the_select, the_array2)
{

MM_changeProp('colour','','options.length',((the_array2.length/2)-1),'SELECT');
		the_select.options.length = ((the_array2.length/2)-1);

	for (i=0; i < ((the_array2.length/2)-1); i++)
	{
		if (i>0){
		the_select.options[i].value = the_array2[(2*i)];
		the_select.options[i].text = the_array2[(2*i)+1];
		}
		else {
		the_select.options[0].value = the_array2[i];
		the_select.options[0].text = the_array2[i+1];
		}
	}
	MM_swapImage('mainpic','','images/items/detail/' + the_array2[0] + '.html',1);
	SetCookie('colour', the_array2[0] ,'1');
	SetCookie('zoom', 'off' ,'1');
	
}

function mynewfunction() {

setTimeout("swapOptions(window.document.the_form.colour.options[selectedIndex].value)", 1000);

}

function JumpToIt1(){
	window.location.href=form1.menu1.options[form1.menu1.options.selectedIndex].value;
}
function JumpToIt2(){
	window.location.href=form2.menu2.options[form2.menu2.options.selectedIndex].value;
}
function JumpToIt3(){
	window.location.href=form3.menu3.options[form3.menu3.options.selectedIndex].value;
}

function SetCookie(cookieName,cookieValue,nDays) {
 var today = new Date();
 var expire = new Date();
 if (nDays==null || nDays==0) nDays=1;
 expire.setTime(today.getTime() + 3600000*24*nDays);
 document.cookie = cookieName+"="+escape(cookieValue)
                 + ";expires="+expire.toGMTString();
}


function quantity_check(theurltohit,colour,size){
//	var quantity_window = window.location=theurltohit +'&chosencolour='+ colour +'&chosensize='+ size;

}


function qw_alert(requested,actual){

	alert ("You have requested " +requested+ " items.\n\nUnfortunately, we only have "+actual+" of that size and colour in stock.\n\nPlease call the store for more details.");
}

function blockerchecker(requested,actual){

var mine = window.open('','','width=1,height=1,scrollbars=no');

	if(mine){
	 	 var popUpsBlocked = false;
	 	 mine.close();
	}
	else{
	 	 var popUpsBlocked = true;
	qw_alert(requested,actual);
	}


}

function getCookie(name)
{
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1)
    {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    }
    else
    {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1)
    {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

function showback(styleno) {

	if (window.showbackcounter) {
		showbackcounter++;
		}
	else {
		showbackcounter = 1;
		}
	
	var current_colour = getCookie("colour");
	if (showbackcounter % 2){
		MM_swapImage('mainpic','','images/items/item_back/' + styleno + '.jpg',1);
		SetCookie('zoom', 'on' ,'1');
		}
	else {
		MM_swapImage('mainpic','','images/items/detail/' + current_colour + '.jpg',1);
		SetCookie('zoom', 'off' ,'1');
	}


}

function wincon(productname){
	var wcstatus = window.confirm("Are you sure you want to delete " + productname +"?");
	if (wcstatus){
    	document.submit();
 	}
}

function checkpasswordsmatch(){
	if ((window.document.registerform.RQPassword.value == window.document.registerform.RQConfirm_Password.value)&&(window.document.registerform.RQPassword.value!='')){
		return true;
	}
	else {
	
	alert('Your passwords do not match. Please check and try again.')
	return false;
	}
}

function getShortcut(whattoplaywith){
	 function filterNum(str) {
          re = /\$|,| |\/|@|#|~|`|\%|\*|\^|\&|\(|\)|\+|\=|\[|\-|\_|\]|\[|\}|\{|\;|\:|\'|\"|\<|\>|\?|\||\\|\!|\$|\./g;
          // remove special characters like "$" and "," etc...
          return str.replace(re, "");
     }
    newvalue = filterNum(whattoplaywith.value);
   window.document.affiliatesform.shortcuthidden.value = newvalue;
	window.document.affiliatesform.shortcut.value="http://www.sheactive.co.uk/"+newvalue;
}	
