acframeinuse = false;
accurrentp	= 0;

function openSite(theURL) {
	iwnewwindow = window.open(theURL,'newWindow','toolbar=yes,location=yes,directories=no,status=yes,menubar=yes,scrollbars=yes,resizable=yes,width=700,height=600');
	iwnewwindow.focus();
	iwnewwindow.resizeTo(700,600);		
}
function openSubwindow(message,theURL,width,height,tools) {
	openSubwindow2('subWindow',message,theURL,width,height,tools);
}

function openSubwindow2(name,message,theURL,width,height,tools) {
	if(tools=='yes'){ mn = 'yes'; st = 'yes'; sc = 'yes';}
	if(tools=='partly'){ st = 'yes'; sc = 'yes'; mn = 'no'; }
	if(tools=='no'){ st = 'no'; sc = 'no'; mn = 'no';}
	if (message != "") {
		iwnewwindow = window.open('',name,'toolbar=no,location=no,directories=no,status='+st+',menubar='+mn+',scrollbars='+sc+',resizable=yes,width='+width+',height='+height);
		iwnewwindow.focus();
		iwnewwindow.resizeTo(width+20,height+20);
		iwnewwindow.document.write('<HTML><HEAD><TITLE>Please wait...</TITLE></HEAD><STYLE></STYLE><LINK REL=stylesheet TYPE=text/css HREF=/admin.css><BODY ><BR><CENTER>');
		iwnewwindow.document.write('<TABLE><TR><TD ALIGN=center><BIG><B>Please wait...<BR><BR>');
		iwnewwindow.document.write('... ' + message + ' </B></BIG>');
		iwnewwindow.document.write('</TD></TR></TABLE></CENTER></BODY></HTML>');
		if (theURL != "") {
			iwnewwindow.location.href = theURL;
		}
	} else {
		iwnewwindow = window.open(theURL,name,'toolbar=no,location=no,directories=no,status='+st+',menubar='+mn+',scrollbars='+sc+',resizable=yes,width='+width+',height='+height);
		iwnewwindow.focus();
		iwnewwindow.resizeTo(width+20,height+20);
	}
}

function siteseal() {
			window.open("https://servicecenter.verisign.com/cgi-bin/Xquery.exe?Template=authCertByIssuer&amp;remote_host=https://digitalid.trustwise.com/secureServer/cgi-bin/haydn.exe&amp;form_file=../fdf/authCertByIssuer.fdf&amp;issuerSerial=d2b375dd320d7238131ee5cb40fd4343","win",'toolbar=0,location=0,directories=0,status=1,menubar=1,scrollbars=1,resizable=1,width=500,height=450'); }		
	
function openConfirmwindow(message,width,height,tools) {
	var st;
	var sc;
	if(tools=='yes'){ st = 'yes'; sc = 'yes';}
	if(tools=='partly'){ st = 'yes'; sc = 'no';}
	if(tools=='no'){ st = 'no'; sc = 'no';}
	iwnewwindow = window.open('','subWindow',	'toolbar=no,location=no,directories=no,status='+st+',menubar='+sc+',scrollbars='+sc+',resizable=yes,width='+width+',height='+height);
	iwnewwindow.focus();
	iwnewwindow.resizeTo(width+20,height+20);
	if (message != "") {
		iwnewwindow.document.write('<HTML><HEAD><TITLE>Please wait...</TITLE></HEAD><STYLE></STYLE><LINK REL=stylesheet TYPE=text/css HREF=/admin.css><BODY ><BR><CENTER>');
		iwnewwindow.document.write('<TABLE><TR><TD ALIGN=center><BIG>' + message + ' <BR></BIG>');
		iwnewwindow.document.write('</TD></TR><tr><td ALIGN=center><INPUT TYPE=button value=Close onClick=window.close();></td></tr></TABLE></CENTER></BODY></HTML>');}
}

function RoundToPence(N) {
 return (S=new String(Math.round(N*100))).substr(0, T=(S.length-2)) + '.' + S.substr(T, 2) }

function openLink(theURL,newWindow) {
	if(newWindow) {
		window.open(theURL,'newWindow');}
	else {
		window.location.href=theURL; }
}

function checkDate( f, al ) {
	var errf = "";
	var sls1 = f.value.indexOf("/",0);
	var sls2 = f.value.indexOf("/",sls1+1);
	if(f.value == "") return true;
	if ((sls1 == -1) || (sls2 == -1)){
		errf = "The DATE has been entered incorrectly";
	} else {
		var d = parseInt(f.value.substring(0,sls1),10);
		var m = parseInt(f.value.substring(sls1+1,sls2),10);
		var y = parseInt(f.value.substring(sls2+1,f.value.length),10);
		var sy	= f.value.substring(sls2+1,f.value.length);
		if(isNaN(d) || isNaN(m) || isNaN(y)) {
			errf = "The date contains spurious characters. Please use numerical characters and the / character only";
		} else {
			if(((y > 9999) || (y < 1000)) && !((sy.length==2) && (y >= 0 || y <= 99))) errf = "The year " + y + "  is invalid. Please amend";
			if((m > 12) || (m < 1)) errf = "The month " + m + " is invalid. Please check and try again";
			if((d > 31) || (d < 1)) errf = "The day " + d + "  is invalid. Please check and try again";
			if((m == 1) && (d > 31)) errf = "January only contains 31 days. Please amend";
			if((m == 2) && (d > 29)) errf = "February only contains (at most) 29 days. Please amend";
			if((m == 3) && (d > 31)) errf = "March only contains 31 days. Please amend";
			if((m == 4) && (d > 30)) errf = "April only contains 30 days. Please amend";
			if((m == 5) && (d > 31)) errf = "May only contains 31 days. Please amend";
			if((m == 6) && (d > 30)) errf = "June only contains 30 days. Please amend";
			if((m == 7) && (d > 31)) errf = "July only contains 31 days. Please amend";
			if((m == 8) && (d > 31)) errf = "August only contains 31 days. Please amend";
			if((m == 9) && (d > 30)) errf = "September only contains 30 days. Please amend";
			if((m == 10) && (d > 31)) errf = "October only contains 31 days. Please amend";
			if((m == 11) && (d > 30)) errf = "November only contains 30 days. Please amend";
			if((m == 12) && (d > 31)) errf = "December only contains 31 days. Please amend";
		}
	}
	if (errf != "") {
			if(al) alert(errf + " : NOTE (Use the format dd/mm/yyyy or dd/mm/yy)");
			f.value = "";
			return false; }
	else {
		return true; }
}

function checkNumeric( f, m ) {
	var t;
	if ((f.value+'' == '') && (m+'' == '')) {
		f.value = 0;
		return true; }

	t = parseFloat(f.value,10);
	if (isNaN(f.value)) {
		alert("The field MUST be numeric.");
		f.value = m;
		return false; }

	if((m+'' != '') && (isNaN(t) || (t.toString() == '') || (t < m))) {
		alert("The field MUST be at least " + m);
		f.value = m;
		return false; }
	return true;
}

function checkNumeric1(f, m, x) {
	var t;
	if ((f.value+'' == '') && (m+'' == '')) {
		f.value = 0;
		return true; }

	t = parseFloat(f.value,10);
	if (isNaN(f.value)) {
		alert("The field MUST be numeric.");
		f.value = m;
		return false; }

	if((m+'' != '') && (isNaN(t) || (t.toString() == '') || (t < m))) {
		alert("The field MUST be at least " + m);
		f.value = m;
		return false; }
	
	if((x+'' != '') && (isNaN(t) || (t.toString() == '') || (t > x))) {
		alert("The field MUST be at most " + x);
		f.value = x;
		return false; }
	return true;
}

function checkEmail( f, m ) {
	if (f.value != '') {
		if (f.value.indexOf('@',0) > 0) {
			if (f.value.indexOf(' ',0) < 0) {
				return true; }
			else {
				if (m) { alert('The email address cannot contain spaces.'); }
				f.value = '';
				return false; }
		} else {
			if (m) { alert('The field MUST contain a valid email address.'); }
			f.value = '';
			return false; }
	} else {
		return true; }
}

function checkURL( f ) {
	if (f.value != '') {
		if ((f.value.indexOf('http://',0) >= 0) || (f.value.indexOf('https://',0) >= 0) || (f.value.indexOf('ftp://',0) >= 0) || (f.value.indexOf('mailto:',0) >= 0) || (f.value.indexOf('javascript:',0) >= 0)) {
			if (f.value.indexOf(' ',0) < 0) {
				return true;
			} else {
				alert('The LINK address cannot contain spaces.');
				f.value = '';
				return false; }
		} else {
			alert('The field MUST contain a valid URL (starting with http:// or similar).');
			f.value = '';
			return false; }
	} else {
		return true; }
}

function checkText( f, s ) {
	if ((f.value != '') && (s > 0)) {
		if (f.value.length > s) {
			alert('The field has exceeded its maximum size of ' + s + ' characters.');
			f.value = f.value.substring(0,s);
			return false;
		} else {
			return true;
		}
	} else {
		return true;
	}
}

function convertBase(num) {
    var i = 0; var j = 20;
    var str = "#";

    while(j >= 0) {
      i = (num >> j)%16;
      if(i >= 10) {
	if(i == 10) str += "A";
	else if(i == 11) str += "B";
	else if(i == 12) str += "C";
	else if(i == 13) str += "D";
	else if(i == 14) str += "E";
	else str += "F";
      } else
	str += i;
      j -= 4;
    }

    return str;
}

function cHex(R, G, B) {
  var n = B; 
  n += G << 8;
  n += R << 16;
  return convertBase(n);
}

function cMonth(M, Format) {
  if(Format == 0) {
	switch(M) {
		case 0: return "Jan";
		case 1:	return "Feb";
		case 2:	return "Mar";
		case 3:	return "Apr";
		case 4:	return "May";
		case 5:	return "Jun";
		case 6:	return "Jul";
		case 7:	return "Aug";
		case 8:	return "Sep";
		case 9:	return "Oct";
		case 10: return "Nov";
		case 11: return "Dec";
	}
  }
  if(Format == 1) {
	switch(M) {
		case 0:	return "January";
		case 1:	return "February";
		case 2:	return "March";
		case 3:	return "April";
		case 4:	return "May";
		case 5:	return "June";
		case 6:	return "July";
		case 7:	return "August";
		case 8:	return "September";
		case 9:	return "October";
		case 10: return "November";
		case 11: return "December";
	}
  }
  if(Format == 2) {
	return (M+1) & '';
  }
}

function cDay(D, Format) {
  if(Format == 0) {
	switch(D) {
		case 0: return "Sun";
		case 1:	return "Mon";
		case 2:	return "Tue";
		case 3:	return "Wed";
		case 4:	return "Thur";
		case 5:	return "Fri";
		case 6:	return "Sat";
	}
  }
  if(Format == 1) {
	switch(D) {
		case 0:	return "Sunday";
		case 1:	return "Monday";
		case 2:	return "Tuesday";
		case 3:	return "Wednesday";
		case 4:	return "Thursday";
		case 5:	return "Friday";
		case 6:	return "Saturday";
	}
  }
  if(Format == 2) {
	return (D+1) & '';
  }
}

function FormatNumber(Number,Decimals,Separator)
{
 Number += ""
 Decimals += ""
 Separator += ""
 if((Separator == "") || (Separator.length > 1))
  Separator = "."
 if(Number.length == 0)
  Number = "0"
 var OriginalNumber = Number
 var Sign = 1
 var Pad = ""
 var Count = 0
 if(parseFloat(Number)){
  Number = parseFloat(Number)} else {
  Number = 0}
 if((parseInt(Decimals,10)) || (parseInt(Decimals,10) == 0)){
  Decimals = parseInt(Decimals,10)} else {
  Decimals = 2}
 if(Number < 0)
 {
  Sign = -1
  Number *= Sign
 }
 if(Decimals < 0)
  Decimals *= -1
 Number = "" + Math.floor(Number * Math.pow(10,Decimals + 1) + 5)
 if((Number.substring(1,2) == '.')||((Number + '')=='NaN'))
  return(OriginalNumber)
 if(Number.length < Decimals +1)
 {
  for(Count = Number.length; Count <= Decimals; Count++)
   Pad += "0"
 }
 Number = Pad + Number
 if(Decimals == 0){
 Number = Number.substring(0, Number.length -1)} else {
 Number = Number.substring(0,Number.length - Decimals -1) +
          Separator +
          Number.substring(Number.length - Decimals -1,
          Number.length -1)}
 if(Sign == -1)
 Number = "-" + Number
 if(Number.length == 0)
  Number="0"
 if(Number.substring(0,1) == '.')
  Number="0"+Number
 return(Number)
}

function menuHandle() {
	if(this.list.newWindow) {
		openSubwindow('',this.list.value,600,500,'yes');
	} else {
		window.location.href=this.list.value;
	}
}
function showmenus(menuid, vis, dir, bgc,ffam,fsize,fsty,fwei,fcol,w,h,img, e) {
	if(vis==1) {
		eval('themenu=menu'+menuid);
		if(themenu.isactive == 1) {
		if(document.all){
			if(dir == 0) {
				menuX = e.clientX - e.offsetX+w;
				menuY = e.clientY + document.body.scrollTop - e.offsetY+2;
			} else {
				menuX = e.clientX - e.offsetX;
				menuY = e.clientY + document.body.scrollTop - e.offsetY+h; }
		} else {
			menuX = e.pageX+2;
			menuY = e.pageY+2; }
		themenu.show(menuX,menuY);
	
		}
	}
	if(document.all('obj'+menuid)) {
		obj = document.all('obj'+menuid).style;
		obj.backgroundColor = bgc;
		obj.fontFamily	= ffam;
		obj.fontSize	= fsize;
		obj.fontStyle	= fsty;
		obj.fontWeight	= fwei;
		obj.color	= fcol;		
		if (!(img=='')) {
			if (window.location.href.indexOf("/preview/") != -1) {
				document.all('menuimage'+menuid).src = '../images/'+img;
			}
			else {
				document.all('menuimage'+menuid).src = 'images/'+img;
			}
		}
	}
}
function hidemenus(menuid,vis,bgc,ffam,fsize,fsty,fwei,fcol,img,e) {
	if(vis==1) {
		eval('themenu=menu'+menuid);
		if(themenu.isactive == 1) {
		themenu.list.isover = false;
		themenu.hide("menu"+menuid); } }
	if(document.all){
	window.setTimeout("hidethemenus("+menuid+","+vis+",'"+bgc+"','"+ffam+"',"+fsize+",'"+fsty+"','"+fwei+"','"+fcol+"','"+img+"')",1);
	}
}

function hidethemenus(menuid,vis,bgc,ffam,fsize,fsty,fwei,fcol,img) {
	changestuff = true;
	if(vis==1) {
		eval('themenu=menu'+menuid);
		if (themenu.visible) {
			window.setTimeout("hidethemenus("+menuid+","+vis+",'"+bgc+"','"+ffam+"',"+fsize+",'"+fsty+"','"+fwei+"','"+fcol+"','"+img+"')",1);
			changestuff = false; }
	}
	if(changestuff) {
			if(document.all('obj'+menuid)) {
				obj = document.all('obj'+menuid).style;
				obj.backgroundColor = bgc;
				obj.color	= fcol;
				obj.fontFamily	= ffam;
				obj.fontSize	= fsize;
				obj.fontStyle	= fsty;
				obj.fontWeight	= fwei; }

			if(!(img=='')) {
				if (window.location.href.indexOf("/preview/") != -1) {
					document.all('menuimage'+menuid).src = '../images/'+img;
				}
				else {
					document.all('menuimage'+menuid).src = 'images/'+img;
				}
			}
	}
}

function copyObj(obj) {
    var i;
    var newObj = new Object();
    for (i in obj) {
        newObj[i] = obj[i];
        }
    return newObj; }

var overthing = false;
var overelement;

function showFavColor(theelement,w,h) {
	overelement = theelement;
	if(document.all.FavColor) {
		document.all.FavColor.style.pixelLeft = event.clientX - event.offsetX + w;
		document.all.FavColor.style.pixelTop = event.clientY + document.body.scrollTop - event.offsetY + h;
		document.all.FavColor.style.visibility = "visible"; }
}

function hideFavColor() {
	if(document.all.FavColor) {	window.setTimeout('hideFavColor2()',500); }
}
	
function hideFavColor2() {
	if(overthing) { window.setTimeout('hideFavColor2()',500); }
	else { document.all.FavColor.style.visibility= "hidden"; }
}

function changeFontColor() {
	return true;
}

function changeTheColor(sColor) {
	for (i = 0; i < document.styleSheets.length; i++) {
		if(!document.styleSheets(i).readOnly){
		for(j = 0; j < document.styleSheets(i).rules.length; j++) {
			if (document.styleSheets(i).rules(j).selectorText == "." + overelement.className) {
				document.styleSheets(i).rules(j).style.color=sColor;
				document.styleSheets(i).rules(j).style.backgroundColor=sColor; }
		}
		}
	}
	if (overelement.id == "BGColor") {
	if (document.frames.length > 0)
		for (i=0; i < document.frames.length; i++)
			if (document.frames(i).id = "edit")	{ document.frames(i).document.body.style.backgroundColor=sColor; break; } }
	overelement.value = sColor;
	overthing = false;
}

function keypress() {	
	event.cancelBubble = true;
	event.returnValue = false;
	openSubwindow2('KnowledgeBase','','/login/kbase',700,600,'partly');
	return false;
}

function wishlistmove(f,p,i) {
	eval('newpage = document.iwwishlist.iwseqno'+i+'.value');
	window.location.href = f + '?ProductID='+ p + '&iwwishlistmove=1&position=' + newpage;
}

function wishlistmove2(f,p,i,w) {
	eval('newpage = document.iwwishlist' + w + '.iwseqno'+i+'.value');
	window.location.href = f + '?ProductID='+ p + '&iwwishlistmove=1&position=' + newpage;
}

function iwaddtocart(f,p,o,r) {
	if (document.iwprodopt) {
		if (!(iwprodoptcheck())) { return; }
		document.iwprodopt.AddProductID.value = p;
		if (r) { document.iwprodopt.Rent.value = r; }
		document.iwprodopt.target = '';
		document.iwprodopt.action = f;
		document.iwprodopt.submit();
		return;
	}
	iscat = false;
	eval('iscat = (document.searchform' + o + ');');
	if (iscat) {
		eval('document.searchform' + o + '.target = \'\'');
		eval('document.searchform' + o + '.action = \'' + f + '\'');
		eval('document.searchform' + o + '.AddProductID.value='+p);
		eval('document.searchform' + o + '.submit()');
		return;
	}
	if (r) {
		document.location.replace(f + '?AddProductID=' + p + '&rent=1');
		return;
	}
	
	document.location.replace(f + '?AddProductID=' + p + '&ProductID=' + p);
	return;
}

function showprod(c,p) {
	if (!(accurrentp == p)) {
		accurrentp = p;
		if ((window.frames["actionframe"]) && ((testdoc('acfieldtext',window)) || (testdoc('acfieldimage',window)) || (testdoc('acfieldlongdesc',window)))) {
			counter = 300000
			while ((acframeinuse = true) && counter > 0) {
				counter = counter - 1;
			}
			acframeinuse = true;
			window.frames["actionframe"].document.location.replace('/login/aqua/acshowprod.asp?CompanyID='+c+'&ProductID='+p);
		}
	}
}

function togglewl(c,p) {
	if (window.frames["actionframe"]) {
		counter = 300000
		while ((acframeinuse = true) && counter > 0) {
			counter = counter - 1;
		}
		acframeinuse = true;
		window.frames["actionframe"].document.location.replace('/login/aqua/acwishlist.asp?CompanyID='+c+'&ProductID='+p);
	}
}

function togglecart(c,p) {
	if (window.frames["actionframe"]) {
		counter = 300000
		while ((acframeinuse = true) && counter > 0) {
			counter = counter - 1;
		}
		acframeinuse = true;
		window.frames["actionframe"].document.location.replace('/login/aqua/accart.asp?CompanyID='+c+'&ProductID='+p);
	}
}

function changeratings(c,o,p,a,r,m,on,off,on2,off2) {
	var i;
	if(document.all('acratingper'+o+'-'+p)) {
		document.all('acratingper'+o+'-'+p).innerHTML = parseInt(r/m*100) + '%';
	}
	for(i=1;i<=m;i=i+1){
		if(a>=i) {
			if(document.all('acrating'+o+'-'+p+'-'+i)) {
				if(r>=i){ document.all('acrating'+o+'-'+p+'-'+i).src=on2; }
				else { document.all('acrating'+o+'-'+p+'-'+i).src=on; }
			}
		} else {
			if(document.all('acrating'+o+'-'+p+'-'+i)) {
				if(r>=i){ document.all('acrating'+o+'-'+p+'-'+i).src=off2; }
				else { document.all('acrating'+o+'-'+p+'-'+i).src=off; }
			}
		}
	}
	window.frames["actionframe"].document.location.href='/login/aqua/acratings.asp?CompanyID='+c+'&ProductID='+p+'&Rating='+(r/m);
}

function ratingni(c,p,off,on,ob) {
	if(ob.src.substr(ob.src.lastIndexOf('/')) == on.substr(on.lastIndexOf('/'))) {
		ob.src = off;
		window.frames["actionframe"].document.location.href='/login/aqua/acratings.asp?CompanyID='+c+'&ProductID='+p+'&NotInterested=0';
	} else {
		ob.src = on;
		window.frames["actionframe"].document.location.href='/login/aqua/acratings.asp?CompanyID='+c+'&ProductID='+p+'&NotInterested=1';
	}
}

function doc(id,f) {
	if(f.document.all) {
		return f.document.all[id];
	} else {
		return f.document.getElementById(id);
	}
}

function testdoc(id,f) {
	thetest = false;
	if(f.document.all) {
		if (f.document.all[id]) { thetest = true; };
	} else {
		if (f.document.getElementById(id)) { thetest = true; };
	}
	return thetest;
}

document.onhelp = keypress;

window.onerror = new Function('return true;');
