//uniformNZ Javascript
function lOn(id){
	document.getElementById('lcat'+id+'').style.visibility='visible';
	document.getElementById('mtp'+id+'').style.borderTop='1px solid #FF6600';
}//function
function lOff(id){
	document.getElementById('lcat'+id+'').style.visibility='hidden';
	document.getElementById('mtp'+id+'').style.borderTop='1px solid #1A1B1F';
}//function
function sCat(id){
	document.getElementById('listcat'+id+'').style.visibility='visible';
	document.getElementById('tt'+id+'').style.height='42px';
	document.getElementById('tt'+id+'').style.marginTop='105px';
	document.getElementById('ttp'+id+'').style.visibility='visible';
}//function
function hCat(id){
	document.getElementById('listcat'+id+'').style.visibility='hidden';
	document.getElementById('tt'+id+'').style.height='28px';
	document.getElementById('tt'+id+'').style.marginTop='119px';
	document.getElementById('ttp'+id+'').style.visibility='hidden';
}//function
var xmlHttp;var nocache=0;var fav_form='';var cart_form='';var scrollLocation=0;var oldScrollLocation=0;var hoveredSuggestion="";var newSuggestion="search-";var elementId="";var box_id="";var innerElementPrefix="search-";
function GetXmlHttpObject(){
	var xmlHttp=null;
	try{xmlHttp=new XMLHttpRequest();}
	catch(e){try{xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");}
	catch(e){xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");}}
	return xmlHttp;
}//function
function showResult(str,event,search_box,boxId){
	elementId=search_box;
	box_id=boxId;
	str=str.replace("&amp;", "");
	if(str.length==0){
		if(document.getElementById('livesearch')!=null && document.getElementById('livesearch').style.display=='block'){
		fade_el('livesearch');
		}
		else if(document.getElementById('livesearch_admin')!=null && document.getElementById('livesearch_admin').style.display=='block'){
		document.getElementById('livesearch_admin').style.display='none';
		document.getElementById('livesearch_admin').innerHTML='';
		}
		else if(document.getElementById('livesearch_matching')!=null && document.getElementById('livesearch_matching').style.display=='block'){
		document.getElementById('livesearch_matching').style.display='none';
		document.getElementById('livesearch_matching').innerHTML='';
		}
		return
	}//if
	else if((event.keyCode==40 || event.keyCode==38) && elementId!='livesearch_admin' && elementId!='livesearch_matching'){
		checkForScroll(event, elementId, innerElementPrefix);
	}//else
	else if(event.keyCode!=37 && event.keyCode!=39){
		hoveredSuggestion=str;
		document.getElementById(box_id).setAttribute("autocomplete","off");
		xmlHttp=GetXmlHttpObject();
		if(xmlHttp==null){
			alert ("Browser does not support HTTP Request");
			return
		}//if
		var url="/includes/"+elementId+".php";
		url=url+"?q="+str;
		url=url+"&box="+box_id;
		url=url+"&sid="+Math.random();
		xmlHttp.onreadystatechange=stateChanged;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
		scrollLocation=0;
		oldScrollLocation=0;
		if(elementId=='livesearch'){
			document.getElementById(elementId).style.display='block';
		}//if
		else{
			document.getElementById(elementId).style.display='block';
		}//else
	}//else
}//function
function stateChanged(){
	if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
		//document.getElementById(elementId).style.visibility='visible';
		document.getElementById(elementId).innerHTML=xmlHttp.responseText;
		hideTip();
	}//if
}//function
function checkForScroll(event, elementId, innerElementPrefix){
	var el=document.getElementById(elementId);
	if(!el){return;}
	if(event.keyCode==40){
		if(document.getElementById(innerElementPrefix+(scrollLocation+1))!=null){
			oldScrollLocation=scrollLocation;
			scrollLocation=scrollLocation+1;
			if(document.getElementById(innerElementPrefix+(oldScrollLocation))!=null){
			document.getElementById(innerElementPrefix+(oldScrollLocation)).className='';}
			document.getElementById(innerElementPrefix+(scrollLocation)).className='hovered';
			document.getElementById(box_id).value=document.getElementById(innerElementPrefix+(scrollLocation)).innerHTML;
		}//if
	}//if
	else if(event.keyCode==38 && (scrollLocation-1)==0){
		document.getElementById(box_id).value=hoveredSuggestion;
		document.getElementById(innerElementPrefix+(scrollLocation)).className='';
	}//else
	else if(event.keyCode==38){
		if(document.getElementById(innerElementPrefix+(scrollLocation-1))!=null){
		oldScrollLocation=scrollLocation;
		scrollLocation=scrollLocation-1;
		if(document.getElementById(innerElementPrefix+(oldScrollLocation))!=null){
		document.getElementById(innerElementPrefix+(oldScrollLocation)).className='';}
		document.getElementById(innerElementPrefix+(scrollLocation)).className='hovered';
		document.getElementById(box_id).value=document.getElementById(innerElementPrefix+(scrollLocation)).innerHTML;}
	}//else
}//function
function insert(prod_no,form_number){
	fav_form=form_number;
	xmlHttp=GetXmlHttpObject()
	nocache=Math.random();
	xmlHttp.open('get', '/includes/insert_fav.php?prod_no='+prod_no+'&nocache='+nocache);
	xmlHttp.onreadystatechange=insertReply;
	xmlHttp.send(null);
}//function
function insertReply(){
	if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
		document.getElementById(fav_form).innerHTML=xmlHttp.responseText;
		update_favbox();
	}//if
}//function
function insertCart(id,form_number){
	cart_form=form_number;
	xmlHttp=GetXmlHttpObject()
	nocache=Math.random();
	xmlHttp.open('get', '/includes/insert_cart.php?id='+id+'&nocache='+nocache);
	xmlHttp.onreadystatechange=insertCartReply;
	xmlHttp.send(null);
}//function
function insertCartReply(){
	if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
		document.getElementById(cart_form).innerHTML=xmlHttp.responseText;
		getCartInfo('single');
		update_orderbox();
	}//if
}//function
function update_orderbox(){
	xmlHttp=GetXmlHttpObject()
	nocache=Math.random();
	xmlHttp.open('get', '/includes/update_orderbox.php?nocache='+nocache);
	xmlHttp.onreadystatechange=insertReplyOB;
	xmlHttp.send(null);
}//function
function insertReplyOB(){
	if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
		document.getElementById('uorder').innerHTML=xmlHttp.responseText;
	}//if
}//function

var list_view="default";
var hide_text="";
var cancelled="no";
function update_listing(list_type,cat,subcat,order_by,filter_colour,filter_fabric,image_toggle){
	cancelled="no";
	document.getElementById('vl_loading').style.visibility='visible';
	hide_text = document.getElementById('hide_view').innerHTML;
	//alert(hide_text);
	$('#prod_wrapper').fadeTo(500, 0.05, function(){
		if(list_type=="default" && list_view=="default"){
			list_view="gallery";
		}//if
		else if(list_type=="detail"){
			list_view="detail";
		}//if
		else{
			list_view="gallery";
		}//else
		update_viewlisting(list_view,cat,subcat,order_by,filter_colour,filter_fabric,image_toggle,hide_text);
		xmlHttp=GetXmlHttpObject()
		nocache=Math.random();
		xmlHttp.open('get', '/includes/update_listing.php?list_type='+list_view+'&cat='+cat+'&subcat='+subcat+'&order_by='+order_by+'&filter_colour='+filter_colour+'&filter_fabric='+filter_fabric+'&image_toggle='+image_toggle+'&nocache='+nocache,true);
		xmlHttp.onreadystatechange=insertReplyUL;
		xmlHttp.send(null);
	});
}//function

function insertReplyUL(){
	if((xmlHttp.readyState==4 || xmlHttp.readyState=="complete") && cancelled=="no"){
		document.getElementById('prod_wrapper').innerHTML=xmlHttp.responseText;
		$('#prod_wrapper').fadeTo(500, 1, function(){
			document.getElementById('vl_loading').style.visibility='hidden';
		});
	}//if
}//function

function cancel_listing(){
	cancelled="yes";
	$('#prod_wrapper').fadeTo(500, 1, function(){
		document.getElementById('vl_loading').style.visibility='hidden';
	});
}//function

function update_viewlisting(list_view,cat,subcat,order_by,filter_colour,filter_fabric,image_toggle,hide_text){
	xmlHttp1=GetXmlHttpObject()
	nocache=Math.random();
	xmlHttp1.open('get', '/includes/update_vl.php?list_type='+list_view+'&cat='+cat+'&subcat='+subcat+'&order_by='+order_by+'&filter_colour='+filter_colour+'&filter_fabric='+filter_fabric+'&image_toggle='+image_toggle+'&hide_text='+hide_text+'&nocache='+nocache);
	xmlHttp1.onreadystatechange=insertReplyVL;
	xmlHttp1.send(null);
}//function

function insertReplyVL(){
	if(xmlHttp1.readyState==4 || xmlHttp1.readyState=="complete"){ 
		document.getElementById('view_options').innerHTML=xmlHttp1.responseText;
		if(document.getElementById('view_options').style.width=='920px'){
			document.getElementById('uni_colours').style.width='400px';
			document.getElementById('toggle_arrow').src='/images/layout/ddown_arr.png';
		}//if
	}//if
}//function

u_qtyoq=0;
u_qtylogo=0;
new_height=0;
function setCartInfo(oq,logo){
	u_qtyoq=oq;
	u_qtylogo=logo;
}//function
function getCartInfo(type){
	if(type='single'){u_qtyoq++;}
	document.getElementById('qtyoq').innerHTML=u_qtyoq;
	document.getElementById('qtylogo').innerHTML=u_qtylogo;
	if(document.getElementById('cart_info').style.display=='none'){document.getElementById('cart_info').style.display='block';}
}//function

function removeFav(id){
	xmlHttp=GetXmlHttpObject()
	// Set the random number to add to URL request
	nocache = Math.random();
	// Pass the login variables like URL variable
	xmlHttp.open('get', '/includes/remove_fav.php?id='+id+'&nocache='+nocache);
	xmlHttp.send(null);
	fade_el(id);
}//function

//Product Finder
var nocache=0;
var forms;
var style;
style="all";
var fabric;
fabric="all";
function u_update(element,cat,page,form){
	document.getElementById('loader').style.visibility='visible';
	document.getElementById('u_colour').disabled=true;
	document.getElementById('u_style').disabled=true;
	document.getElementById('filter_fabric').disabled=true;
	document.getElementById('submit_button').disabled=true;
	forms=form;
	if(page=="update_finder_2"){
		style = element.value;
	}//if
	if(page=="update_finder_3"){
		fabric = element.value;
	}//if
	xmlHttp=GetXmlHttpObject();
	nocache=Math.random();
	xmlHttp.open('get', '/includes/update_finder.php?element='+element.value+'&cat='+cat+'&style='+style+'&page='+page+'&fabric='+fabric+'&nocache='+nocache);
	xmlHttp.onreadystatechange=insertReplys;
	xmlHttp.send(null);
}//function

function insertReplys(){
	if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
		document.getElementById(forms).innerHTML=xmlHttp.responseText;
		en();
	}//if
}//function

function en(){
	document.getElementById('u_colour').disabled=false
	document.getElementById('u_style').disabled=false
	document.getElementById('filter_fabric').disabled=false;
	document.getElementById('submit_button').disabled=false;
	document.getElementById('loader').style.visibility='hidden';
}//function

//Top Viewed Uniforms
function update_tvu(tvu_cat){
	xmlHttp=GetXmlHttpObject();
	nocache=Math.random();
	xmlHttp.open('get', '/includes/update_tvu.php?tvu_cat='+tvu_cat+'&nocache='+nocache);
	$('#tvu').fadeTo('slow', 0.1, function() {
		xmlHttp.onreadystatechange=insertReplyTVU;
		xmlHttp.send(null);
	}).delay(500).fadeTo(500,1);
}//function
function insertReplyTVU(){
	if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
		document.getElementById('tvu').innerHTML=xmlHttp.responseText;
	}//if
}//function

function tvu_selected(obj){
	obj.style.backgroundImage='url(/images/layout/menu_hover.jpg)';
	if(document.getElementById('tvu_select')){
		document.getElementById('tvu_select').removeAttribute('style','');
		document.getElementById('tvu_select').id='';
	}//if
	obj.id='tvu_select';
}//function

//Select Colours in cart
var SCspan;
var form_number1;
var form_colour1;
var cart_opt_no1;
var prod_no1;
var cart_colour1;
var selected_colour1;
var form_size1;
var cart_size1;
var cartId1;
function selectColours(form_number,form_colour,cart_opt_no,prod_no,selected_colour,cart_colour,form_size,cart_size,cartId){
	SCspan='colour_set_'+form_number;
	document.getElementById(SCspan).innerHTML='&nbsp;&nbsp;<img src=/images/layout/loader.gif width=16 height=16 />&nbsp;&nbsp;';
	form_number1=form_number;
	form_colour1=form_colour;
	selected_colour1=selected_colour.value.replace(/, /i ,',%20');
	cart_colour1=cart_colour;
	cart_opt_no1=cart_opt_no;
	prod_no1=prod_no;
	form_size1=form_size;
	cart_size1=cart_size;
	cartId1=cartId;
	xmlHttp=GetXmlHttpObject();
	nocache=Math.random();
	xmlHttp.open('get', '/includes/select_colours.php?form_number='+form_number+'&form_colour='+form_colour+'&cart_opt_no='+cart_opt_no+'&prod_no='+prod_no+'&selected_colour='+selected_colour1+'&cart_colour='+cart_colour1+'&form_size='+form_size+'&cart_size='+cart_size+'&cartId='+cartId+'&nocache='+nocache);
	xmlHttp.onreadystatechange=insertReplySC;
	xmlHttp.send(null);
}//function
function insertReplySC(){
	if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
		document.getElementById(SCspan).innerHTML=xmlHttp.responseText;
		selectSizes(form_number1,form_colour1,cart_opt_no1,prod_no1,selected_colour1,form_size1,cart_size1,cartId1);
	}//if
}//function

//Select Sizes in cart
var SSspan;
function selectSizes(form_number,form_colour,cart_opt_no,prod_no,cart_colour,form_size,cart_size,cartId){
	SSspan='size_set_'+form_number;
	form_number1=form_number;
	form_colour1=form_colour;
	cartId1=cartId;
	cart_colour=document.getElementById('colour'+form_number+'').value.replace(/, /i ,',%20');
	document.getElementById(SSspan).innerHTML='&nbsp;&nbsp;<img src=/images/layout/loader.gif width=16 height=16 />&nbsp;&nbsp;';
	xmlHttp=GetXmlHttpObject();
	nocache=Math.random();
	xmlHttp.open('get', '/includes/select_sizes.php?form_number='+form_number+'&form_colour='+form_colour+'&cart_opt_no='+cart_opt_no+'&prod_no='+prod_no+'&cart_colour='+cart_colour+'&form_size='+form_size+'&cart_size='+cart_size+'&cartId='+cartId+'&nocache='+nocache);
	xmlHttp.onreadystatechange=insertReplySS;
	xmlHttp.send(null);
}
function insertReplySS(){
	if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
		document.getElementById(SSspan).innerHTML=xmlHttp.responseText;
		update_cart(form_number1,cartId1,form_colour1);
	}//if
}//function

function update_cart(form_number,cartId,form_colour){
	cart_opt_no=document.getElementById('opt'+form_number+'').value;
	cart_colour=document.getElementById('colour'+form_number+'').value.replace(/, /i ,',%20');
	cart_size=document.getElementById('size'+form_number+'').value.replace(/, /i ,',%20');
	xmlHttp=GetXmlHttpObject();
	nocache=Math.random();
	xmlHttp.open('get', '/includes/update_cart.php?cart_opt_no='+cart_opt_no+'&cart_colour='+cart_colour+'&cart_size='+cart_size+'&cartId='+cartId+'&nocache='+nocache);
	xmlHttp.send(null);
	if(document.getElementById('colour'+form_number+'').value){
		document.getElementById('colour'+form_number+'').style.backgroundColor='#fff';
	}//if
	else{
		document.getElementById('colour'+form_number+'').style.backgroundColor='#'+form_colour;
	}//else
	if(document.getElementById('size'+form_number+'').value){
		document.getElementById('size'+form_number+'').style.backgroundColor='#fff';
	}//if
	else{
		document.getElementById('size'+form_number+'').style.backgroundColor='#'+form_colour;
	}//else
}//function

function change_fav(image_el,image_name,prod_no){
	document.getElementById(image_el).src='/images/'+image_name+'.jpg';
	xmlHttp=GetXmlHttpObject();
	nocache=Math.random();
	xmlHttp.open('get', '/includes/change_fav.php?image_name='+image_name+'&prod_no='+prod_no+'&nocache='+nocache);
	xmlHttp.send(null);
}//function

function toggle_gst(gst_value){
	xmlHttp=GetXmlHttpObject();
	nocache=Math.random();
	xmlHttp.open('get', '/includes/setGST.php?gst_value='+gst_value+'&nocache='+nocache);
	xmlHttp.send(null);
	setTimeout("location.reload(true);",500);
}//function

var toggled="hidden";
var first_toggle="no";
function toggle(){
	if(toggled=="hidden"){
		if(first_toggle=="yes"){
			document.getElementById('side_menu').style.display='block';
			first_toggle="no";
		}//if
		document.getElementById('side_menu').style.display='block';
		toggled="visible";
		document.getElementById('content').style.width='760px';
		document.getElementById('content').style.cssFloat='left';
		document.getElementById('content').style.styleFloat='left';
		if(document.getElementById('view_options')){
			document.getElementById('view_options').style.width='730px';
			document.getElementById('uni_colours').style.width='240px';
		}//if
		if(document.getElementById('prod_desc')){
			if(document.getElementById('matches')){
				document.getElementById('prod_desc').style.width='300px';
			}//if
			else{
				document.getElementById('prod_desc').style.width='450px';
			}//else
		}//if
		document.getElementById('toggle_arrow').src='/images/layout/up_arr.png';
		if(document.getElementById('hide_view')){
			document.getElementById('hide_view').style.marginLeft='212px';
		}//if
		if(document.getElementById('prod_wrapper')){
			document.getElementById('prod_wrapper').style.width='760px';
		}//if
		if(document.getElementById('twitter')){
			document.getElementById('twitter').style.marginLeft='500px';
		}//if
	}//if
	else{
		toggled="hidden";
		document.getElementById('content').style.width='944px';
		document.getElementById('content').style.cssFloat='no';
		document.getElementById('content').style.stlyeFloat='no';
		if(document.getElementById('view_options')){
			document.getElementById('view_options').style.width='920px';
			if(document.getElementById('uni_colours')){
				document.getElementById('uni_colours').style.width='400px';
			}//if
		}//if
		if(document.getElementById('prod_desc')){
			document.getElementById('prod_desc').style.width='450px';
		}//if
		document.getElementById('toggle_arrow').src='/images/layout/ddown_arr.png';
		if(document.getElementById('hide_view')){
			document.getElementById('hide_view').style.marginLeft='402px';
		}//if
		if(document.getElementById('prod_wrapper')){
			document.getElementById('prod_wrapper').style.width='910px';
		}//if
		if(document.getElementById('twitter')){
			document.getElementById('twitter').style.marginLeft='680px';
		}//if
	}//else
}//function

function toggle_viewopt(){
	if(disabled=='no'){
		document.getElementById('view_options').style.position='absolute';
		document.getElementById('view_options').style.top='';
		document.getElementById('view_options').style.display='block';
		document.getElementById('hide_view').innerHTML='show';
		disabled='yes';
	}//if
	else{
		if(window.pageYOffset>152 || document.documentElement.scrollTop>152){
			document.getElementById('view_options').style.position='fixed';
			document.getElementById('view_options').style.top='0';
		}//if
		document.getElementById('hide_view').innerHTML='hide';
		disabled='no';
	}//else
}//function

function fade_el(to_hide){
	if(to_hide != 'side_menu' || (to_hide=='side_menu' && toggled=='visible')){
	$('#'+to_hide+'').fadeOut('slow', function() {
		if(to_hide=='side_menu'){
			toggle();
		}//if
	});
	}//if
	else if(to_hide=='side_menu'){
		toggle();
	}//else
}//function

function fadeto_el(to_hide){
	$('#'+to_hide+'').fadeTo('slow', 0.1, function() {
		if(to_hide=='view_options'){
			toggle_viewopt();
		}//if
	});
	if(to_hide=='view_options'){
		$('#'+to_hide+'').fadeTo('slow', 1, function() {
		
		});
	}//if
}//function
