 // JavaScript Document
function checkText(box, val){
	if(box.value == val)
		box.value = "";
	else if(box.value == "")
		box.value = val;
}

function show(div){
	if(!$("#"+div))
		return;
	$("#"+div).css('display', "block");	
}
function hide(div){
	if(!$("#"+div))
		return;
	$("#"+div).css('display', "none");	
}

function showhide(div){
	if(!$("#"+div).length)
		return;
	if($("#"+div).css('display')=="none" || $("#"+div).css('display')==""){
		show(div);
	} else
		hide(div);	
}

function loadPage(url,waitdiv,loaddiv,data, waiting){
	/*
	url = the pages to load, including any get variables i.e other_page.php?type=1
	waitdiv = the div that will display a message while loading
	loaddiv = (optional) this is the div that will display the result, if this is blank waitdiv is used
	data = (optional) post variables as a string i.e var1=data&var2=otherdata
	waiting = (optional) by default we display "Please wait" but you can optionally display something else if you want
	*/
	
	if(data==null)
		vartype='get';
	else
		vartype='post';
	
	if(waiting==null)
		waiting = '<p align="center"><span style="display:block; height:100%; vertical-align:middle;">Please wait:<br /><img src="/mainsite/images/loader.gif"></span></p>';
		
	if(waitdiv==null)
		waitdiv = 'content_div';
	if(loaddiv==null)
		loaddiv = waitdiv;
	if($(waitdiv)){
		$(waitdiv).html(waiting);	
	}
	
	//ELSE JQUERY
	if($("#"+loaddiv)){
		if(data == null){
			var bits = url.split("?");
			url = bits[0];
			data = bits[1];
		}
		
		$.ajax({
			type: vartype,
			dataType: 'html',
			url: url,
			data: data,
			success: function(msg){
				$("#"+loaddiv).html(msg);
			}
		});
	}
}

function FlexOpenURL( url, target ){
	try {
		var popup = window.open( url, target );
		if ( popup == null )
			return false;						
		if ( window.opera )								
			if (!popup.opera)
				return false;
	} catch(err) {
		return false;								
	}								
	return true;
}

function login(){
	post = "user="+$('#username').val();
	post += "&pass="+$('#pass').val();
	loadPage('/mainsite/login.html', 'login_message', 'login_message', post, 'Please wait...');	
}

function gup( name ){
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	var regexS = "[\\?&]"+name+"=([^&#]*)";
	var regex = new RegExp( regexS );
	var results = regex.exec( window.location.href );
	if( results == null )
		return "";
	else
		return results[1];
}

function updateHeader(){
	loadPage('/mainsite/header.php?view='+_currentPage,'','header_div');	
}

function passwordFocusIn(){
	$('#login_password_div').html('<input type="password" id="pass" name="pass" onBlur="passwordFocusOut()" />');
	$('#pass').focus();
}

function passwordFocusOut(){
	if($('#pass').val() == "")
		$('#login_password_div').html('<input type="text" value="PASSWORD" onFocus="passwordFocusIn()" />');
}

function usernameFocusIn(){
	if($('#username').val() == "USERNAME / EMAIL")
		$('#username').val("");
}

function usernameFocusOut(){
	if($('#username').val() == "")
		$('#username').val("USERNAME / EMAIL");
}

var currentShopNewInProductIndex = 1;

function productSlideShow() {
	//Set the opacity of all images to 0
	$('#gallery .shop_new_in_product').css({opacity: 0.0});
	
	//TRANSPARENCY AND IE AIN'T A GOOD COMBO
	if(navigator.userAgent.indexOf('MSIE') == -1)
		$('#gallery .shop_new_in_price_bg').css({opacity: 0.7});
	
	shopNewInGallery();
	
	setInterval('shopNewInGallery()',5000);
}

var shopNewInCurrentZIndex = 400;
function shopNewInGallery() {
	$('#shop_new_in_product_'+currentShopNewInProductIndex).animate({opacity:0}, 1500);
	
	currentShopNewInProductIndex ++;
	if(!$('#shop_new_in_product_'+currentShopNewInProductIndex).length)
		currentShopNewInProductIndex = 1;
	
	$('#shop_new_in_product_'+currentShopNewInProductIndex).animate({opacity:1}, 1500);
	$('#shop_new_in_product_'+currentShopNewInProductIndex).css('z-index', shopNewInCurrentZIndex);
	shopNewInCurrentZIndex++;
}

var currentBannerIndex = 1;
function addBannerSlideShow() {
	
	//Set the opacity of all images to 0
	$('.header_banner').css({opacity: 0.0});
	
	addBannerGallery();
	
	setInterval('addBannerGallery()',5000);
}

var addZIndex = 1000;
function addBannerGallery() {
	$('#header_banner_'+currentBannerIndex).animate({opacity:0}, 1500);
	
	currentBannerIndex ++;
	if(!$('#header_banner_'+currentBannerIndex).length)
		currentBannerIndex = 1;
	
	$('#header_banner_'+currentBannerIndex).animate({opacity:1}, 1500);
	$('#header_banner_'+currentBannerIndex).css('z-index', addZIndex);
	addZIndex ++;
}

function showStevieBOutfit(idx){
	loadPage("/mainsite/home_stevieboutfits.php?offset="+idx, 'stevie_b_outfits', 'stevie_b_outfits','','');
}

function displayModalBox(url, w, h, title){
	h = parseInt(h)+105;
	w = parseInt(w)+20;
	$("#modal_dialogue").html("");
	$("#modal_dialogue").load(url);
	$("#modal_dialogue").dialog({ 
	  modal:true,
	  title:title,
	  width:w,
	  height:h,
	  resizable:false,
	  buttons: { 
		"Close": function() { $(this).dialog("close"); $(this).html(""); } 
	  }
	}); 
}

function closeDialogueBox(){
	$("#modal_dialogue").dialog('close');
}

function gotoProductPage(rcode, productID){
	var url = "gotoPage.php?rcode="+rcode+"&type=product&productID="+productID;
	window.open(url, 'productpage');
}

function addToBasket(rcode, productID, size){
	var url = "gotoPage.php?rcode="+rcode+"&type=basket&productID="+productID+"&size="+size;
	window.open(url, 'productpage');
}

function gotoRetailerPage(rcode, url){
	var url = "gotoPage.php?rcode="+rcode+"&type=other&url="+escape(size);
	window.open(url, 'productpage');
}