//<![CDATA[

// Build Input element
function addInput(target_id,typ,name,val,onevnt,func){
	var el=document.createElement('input');
	el.type=typ;
	el.name=name;
	if(val)el.value=val;
	if(onevnt)el[onevnt]=func;
	document.getElementById(target_id).appendChild(el);
}

// Add the prefered account to WorldPay Purchase Transaction form
function worldpayAccount()
{
	var strPage = window.location.pathname;
	strPage = strPage.substring(0, strPage.indexOf("_1.aspx"));
	if(strPage.indexOf("checkout") == 1) {	
		if (document.getElementById("basket_info") != null) {
			addInput('basket_info','hidden','accId1','66327523');
		}
	}
}


// Open new window
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

// Contiune Basket
function doContinue(){
	if (document.getElementById('basketContinueButton') != null ) {	
	window.location = document.getElementById('basketContinueButton').href;
	}
}


// Check the upload file type
function TestFileType( fileObj, fileTypes ) {
	
	file = document.getElementById(fileObj)
	
	fileName = file.value
	
	if (!fileName) return;

	formatName = fileName.toLowerCase();
	
	dots = formatName.split(".")
	//get the part AFTER the LAST period.
	fileType = "." + dots[dots.length-1];
	
	var bfound = false;
	
	for (i = 0; i < fileTypes.length; i++){
		
		if ('.' + fileTypes[i] == fileType) {
			bfound = true;
		}
	}
	
	if (bfound == false){
		 alert("Please only upload files that end in types: \n\n." + (fileTypes.join(" .")) + "\n\nPlease select a new file and try again.");
		 file.focus();
	}
	
	
	
}

//rotate header

//Specify background images to rotate
var bgslides=new Array();
bgslides[0]="assets/images/header_img_1.jpg";
bgslides[1]="assets/images/header_img_2.jpg";
bgslides[2]="assets/images/header_img_3.jpg";
bgslides[3]="assets/images/header_img_4.jpg";
bgslides[4]="assets/images/header_img_5.jpg";
bgslides[5]="assets/images/header_img_6.jpg";

//Specify txt to rotate
var txtslides=new Array();
txtslides[0]="High performance matting";
txtslides[1]="5 year rot & fade guarantee on Waterhog Mats";
txtslides[2]="Free UK delivery";
txtslides[3]="Protect your expensive flooring";
txtslides[4]="Prevent slips and falls";
txtslides[5]="Stop dirt and moisture at the door";
txtslides[6]="Long lasting, rubber backed mats";
txtslides[7]="No Artwork charge on Logo Mats";


//Specify background images to rotate on "mats for home" category
var bgslidesMatsForHome=new Array();
bgslidesMatsForHome[0]="assets/images/Banner1.jpg";
bgslidesMatsForHome[1]="assets/images/Banner2.jpg";
bgslidesMatsForHome[2]="assets/images/Banner3.jpg";
bgslidesMatsForHome[3]="assets/images/Banner4.jpg";
bgslidesMatsForHome[4]="assets/images/Banner5.jpg";
bgslidesMatsForHome[5]="assets/images/Banner6.jpg";
bgslidesMatsForHome[6]="assets/images/Banner7.jpg";
bgslidesMatsForHome[7]="assets/images/Banner8.jpg";
bgslidesMatsForHome[8]="assets/images/Banner9.jpg";

//Specify txt to rotate
var txtslidesMatsForHome=new Array();
txtslidesMatsForHome[0]="Free Delivery to UK Mainland";
txtslidesMatsForHome[1]="No quibble, 100% Satisfaction Guarantee";
txtslidesMatsForHome[2]="Stop Dirt and Moisture at the door";
txtslidesMatsForHome[3]="Protect your hard floors and carpets";
txtslidesMatsForHome[4]="Prevent slips and falls";


//Specify interval between rotate (in miliseconds)
var speed=6000;
var iImgIndex = 1;
var iTxtIndex = 1;

//preload images
var processed=new Array();

function rotateback(){
	// rotate images
	document.getElementById('topimage').src=processed[Math.round(Math.random()*(processed.length-1))].src;
	// rotate text
	objtext = txtslides[Math.round(Math.random()*(txtslides.length-1))];
	document.getElementById('toptxt').innerHTML=objtext;
	document.getElementById('toptxt').alt=objtext;
	document.getElementById('toptxt').title=objtext;
}
function rotateback2(){
	// rotate images
	document.getElementById('topimage').src=processed[iImgIndex++].src;
	if(iImgIndex>=processed.length) iImgIndex = 0;
	// rotate text
	objtext = txtslidesMatsForHome[iTxtIndex++];
	document.getElementById('toptxt').innerHTML=objtext;
	document.getElementById('toptxt').alt=objtext;
	document.getElementById('toptxt').title=objtext;
	if(iTxtIndex>=txtslidesMatsForHome.length) iTxtIndex = 0;
}

if (document.all||document.getElementById) {
	if(window.location.search.indexOf("id2=1:31066") != -1) {
		for (i=0;i<bgslidesMatsForHome.length;i++) {
			processed[i]=new Image();
			processed[i].src=bgslidesMatsForHome[i];
		}
		window.onload=new Function('setInterval("rotateback2()",speed)')
	} else {
		for (i=0;i<bgslides.length;i++) {
			processed[i]=new Image();
			processed[i].src=bgslides[i];
		}
		window.onload=new Function('setInterval("rotateback()",speed)')
	}
}
// end rotate header

// Print web page
function printpage() {
	window.print();
}

// Open print page using _print extension.
function showPrint() {
	var strPage = window.location.pathname;
	
	strPage = strPage.substring(0, strPage.indexOf("_1.aspx"));
	if(strPage.indexOf("document") == 1) 
	{
		strPage = "document";
	}
	else if(strPage.indexOf("news") == 1) {
		strPage = "news";	
	}
	else if(strPage.indexOf("search") == 1) {
		strPage = "search";	
	}
	else {
		// set document as default
		strPage = "document";	
	}
	/*window.location = strPage + "_print_1.aspx" + window.location.search;*/
	window.open(strPage + "_print_1.aspx" + window.location.search);
	
}


// Search site
function checkSearchFields(objForm)
{	
		if(trim(objForm.keywords.value) == "") {
			alert("Please enter your keyword(s)");
			objForm.keywords.focus();
			return false;
		}
		else {
			return true;
		}
}

//Trim string
function trim(str)
{
   return str.replace(/^\s*|\s*$/g,"");
}
//End Function

//Right Trim string
function rtrim(str)
{
	return str.replace(/\s*$/, ""); 
}
//End Function

//Left Trim string
function ltrim(str)
{
	return str.replace(/^\s*/, ""); 
}
//End Function


//Gradual-Highlight image script- By Dynamic Drive
var baseopacity=90

function slowhigh(which2){
imgobj=which2
browserdetect=which2.filters? "ie" : typeof which2.style.MozOpacity=="string"? "mozilla" : ""
instantset(baseopacity)
highlighting=setInterval("gradualfade(imgobj)",50)
}

function slowlow(which2){
cleartimer()
instantset(baseopacity)
}

function instantset(degree){
if (browserdetect=="mozilla")
imgobj.style.MozOpacity=degree/100
else if (browserdetect=="ie")
imgobj.filters.alpha.opacity=degree
}

function cleartimer(){
if (window.highlighting) clearInterval(highlighting)
}

function gradualfade(cur2){
if (browserdetect=="mozilla" && cur2.style.MozOpacity<1)
cur2.style.MozOpacity=Math.min(parseFloat(cur2.style.MozOpacity)+0.1, 0.99)
else if (browserdetect=="ie" && cur2.filters.alpha.opacity<100)
cur2.filters.alpha.opacity+=10
else if (window.highlighting)
clearInterval(highlighting)
}


// Show & Hide
function show(c) {
	if (document.getElementById && document.getElementById(c)!= null) 
		node = document.getElementById(c).style.display='block'; 
	else if (document.layers && document.layers[c]!= null) 
		document.layers[c].display = 'block'; 
	else if (document.all && document.all(c)!= null) 
		document.all[c].style.display = 'block';
} 

function hide(c) {	
	if (document.getElementById && document.getElementById(c)!= null)
		node = document.getElementById(c).style.display='none';
	else if (document.layers && document.layers[c]!= null) 
		document.layers[c].display = 'none';
	else if (document.all && document.all(c)!= null) 
		document.all[c].style.display = 'none';
}

//

//]]>