
var dayarray=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
var montharray=new Array("Jan","Feb","March","Apr","May","June","July","Aug","Sep","Oct","Nov","Dec")

function swapimage(imagenumber) {
	document.getElementById('productlargeimage').src = document.getElementById('hidden'+imagenumber).value;
	document.getElementById('viewlargelink').href = document.getElementById('thumbnailimagenumber'+imagenumber).value;	
}

function showHideToggleRow(grpId,blExpand){
	
	var objTable = document.getElementById('grp_'+grpId);
	if (blExpand == 'true')	{
		for (var i=0;i<objTable.rows.length;i++){
			if (i>0){
				objTable.rows[i].style.display = '';		
			}
		}			
		document.getElementById('anc_'+grpId).className = 'toggleCollapse';
	} else {
		if (document.getElementById('anc_'+grpId).className == 'toggleExpand')	{
			for (var i=0;i<objTable.rows.length;i++){
				if (i>0){
					objTable.rows[i].style.display = '';		
				}
			}			
			document.getElementById('anc_'+grpId).className = 'toggleCollapse';
		} else {
			for (var i=0;i<objTable.rows.length;i++){
				if (i>0){
					objTable.rows[i].style.display = 'none';
				}
			}			
			document.getElementById('anc_'+grpId).className = 'toggleExpand';				
		}
	}
}


function showHideDiv(postid,blShow) {
	var whichpost = document.getElementById(postid);
	if (blShow == 1){
		whichpost.className="expandRow";
	} else {		
		whichpost.className="collapseRow";
	}                       
}



function getthedate() {
	var mydate = new Date();
	var year = mydate.getYear();
	if (year < 1000) year += 1900;
	var day = mydate.getDay();
	var month = mydate.getMonth();
	var daym = mydate.getDate();
	if (daym < 10) daym = "0" + daym;

	var cdate=dayarray[day] + " " + daym + " " + montharray[month] + " " + year;
}

if (!document.all && !document.getElementById) getthedate();

function goforit() {
	if (document.all||document.getElementById) getthedate();
}


function poptastic(url,ht,wd)
{
	var newwindow;
	newwindow=window.open(url,'name','height='+ht+',width='+wd);
	if (window.focus) {newwindow.focus()}
}

function copy(text2copy) {
	if (window.clipboardData) {
		window.clipboardData.setData("Text",text2copy);
	} else {
		var flashcopier = 'flashcopier';
		if(!document.getElementById(flashcopier)) {
			var divholder = document.createElement('div');
			divholder.id = flashcopier;
			document.body.appendChild(divholder);
		}
		document.getElementById(flashcopier).innerHTML = '';
		var divinfo = '<embed src="'+sSiteUrl+'_clipboard.swf" FlashVars="clipboard='+escape(text2copy)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';
		document.getElementById(flashcopier).innerHTML = divinfo;
	}
}

function fn_chk_sys_passwd(username, passwd) { 
	if ((passwd.length < 5) || (passwd.length > 14)) 
	return false; 
	if (passwd.length >= username.length) { 
		if (passwd.indexOf(username, 0) != -1) 
		return false; 
	} 
	if ((passwd.indexOf('\'') != -1) || (passwd.indexOf(' ') != -1)) 
		return false; 
		for (i = passwd.length; i-- > 0;) { 
			if (passwd.charCodeAt(i) > 127) return false; 
		} 
	return true; 
} 


function fn_chk_login(login) { 
	re = /^[a-zA-Z0-9]{1}[A-Za-z0-9_.-]{0,19}$/; 
	return login.search(re) != -1; 
} 

function hideMessage(divId){
//	if(document.getElementById(divId)) {
		document.getElementById(divId).style.display = 'none';
//	}
}

function formatCurrency(num) {

	if(isNaN(num)) {
		return false;
	}	
	
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();

	if(cents<10)
		cents = "0" + cents;

	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
		num = num.substring(0,num.length-(4*i+3))+','+
		
	num.substring(num.length-(4*i+3));
	
	priceVal = ((sign)?'':'-') + num + '.' + cents;
	return true;
}

function disableDrop(selecteddrop){
	if (selecteddrop == 'alphasort')
	{
	document.getElementById('sortbyprice').selectedIndex=0;
	}
	
	if(selecteddrop == 'sortbyprice')  
	{
	document.getElementById('alphasort').selectedIndex=0;
	}
}

// execute your scripts when the DOM is ready. this is a good habit 
$(function() { 
 
    // initialize scrollable
	$("div.scrollable").scrollable({
		size: 4,
		speed: 350,
		keyboard: true
	});

/* FIX - stop scrolling past the end */
	if ($("div.scrollable").length > 0) {
		var scrollable = $("div.scrollable").data("scrollable");
		var size = 3;
		scrollable.onSeek(function(event, index) {
			if (this.getIndex() >= this.getSize() - size) {
				$("a.next").addClass("disabled");
			}
		});
		scrollable.onBeforeSeek(function(event, index) {
			if (this.getIndex() >= this.getSize() - size) {
				if (index > this.getIndex()) {
					return false;
				}
			}
		});
	}
/* End fix */

/* FIX - don't show arrows if one img */
	if ($('.items').length > 0 && $('.items > *').length == 1) $('a.next, a.prev').addClass('disabled');
/* End fix */

	if ($("div.scrollable2").length > 0) {
		$("div.scrollable2").scrollable({
			size: 1,
			speed: 350,
			keyboard: true,
			api: true
		});
		$("div.scrollable2").data("scrollable").onSeek(function() {
			if (this.getIndex() != 0) {
				$('.zoomCaption').fadeOut();
			} else {
				$('.zoomCaption').fadeIn();
			}
		});
	}
 
 	var regions =
	$("div.scrollable3").scrollable({
		size: 1,
		speed: 350,
		keyboard: true,
		clickable:false,
		api:true
	});
   
   	$('.regionMenu li').bind("click",function(e){
		index = $(this).attr('id');
		regions.seekTo(index);
	});

	$('.fader img:gt(0)').hide();
	setInterval(function(){
		$('.fader :first-child').fadeOut(3000).next('img').fadeIn(3000).end().appendTo('.fader');
	}, 6000);
		
	// Set the department page title for the view product page.
	if ($('#breadcrumbs a').length > 2) {
		$('#pageTitle').text($('#breadcrumbs a:nth-child(3)').text());
	}
	
	// Uppercase only for the personalisation field.
	var personalisedText = $('.persfield[type="text"]');
	if (personalisedText.length > 0) {
		personalisedText.keyup(function() {
			var that = $(this);
			that.val(that.val().toUpperCase());
		});	
	}
	
$(function() {
	$('.zoomCaption a').lightBox();
});
	
	// Display colour options
	if ($('label:contains("Colour")').length > 0) {
		$('#' + $('label:contains("Colour")').attr('for') + ' option').each(function() {
			$('#js_colour_options').append(
				'<div>' +
					'<img src="../../images/colouroptions/' + $(this).text().toLowerCase().replace(/\s/, '-') + '.png" width="75" height="75" alt="' + $(this).text() + '" />' +
					'<p>' + $(this).text() + '</p>' +
				'</div>'
			);
		});
	}
});
