// ------------------------------------------------
// opens a new window to view the form (hopefully securely)

function getfrm( fname ){

var t = "/link.asp?fn=" + fname;
var w = window.open(t,"DownloadingFormData", "status=no,toolbar=no,scrollbars=yes,resizable=yes");
//location.replace(t);

return false;
}



function avail(){
window.open("../availability.asp?", "_blank","height=350,width=350,resizable=1,status=1");
return false;
}

// -----------------------------------------------
// ------------------------------------------------

function srmadminform(){


	var fm = window.document.adminform	

	if(fm.title.value.length == 0){
		alert("Field: " + fm.title.name + " Cannot be blank");
		return false;
	}
	if(fm.description.value.length == 0){
		alert("Field: " + fm.description.name + " Cannot be blank");
		return false;
	}
	if(fm.description.value.length > 253){
		alert("Field: " + fm.description.name + " is too long. Max 255 characters.");
		return false;
	}
	if(fm.papercode.value.length == 0){
		alert("Field: " + fm.papercode.name + " Cannot be blank. Enter zero if necessary.");
		return false;
	}

	if(fm.webcode.value.length == 0){
		alert("Field: OLF Code Cannot be blank. Enter zero if necessary.");
		return false;
	}
	if(fm.range.value.length == 0){
		alert("Field: " + fm.range.name + " Cannot be blank");
		return false;
	}
	if(fm.papercopyprice.value.length == 0){
		alert("Field: " + fm.papercopyprice.name + " Cannot be blank");
		return false;
	}
	if(fm.pages.value.length == 0){
		alert("Field: " + fm.pages.name + " Cannot be blank");
		return false;
	}
	if (isNaN(fm.size.value)) {
		alert("Field: " + fm.size.name + " Must be a number - no text.");
		return false;
	}


return true;
}
// ------------------------------------------------
// ------------------------------------------------

function srmlogin(){

	var fm = window.document.mainlogin;	

	if(fm.name.value.length <3){
		alert("Name must be at least 3 characters.");
		return false;
	}
	if(fm.password.value.length <6){
		alert("Password must be at least 6 characters.");
		return false;
	}



return true;
}
// ------------------------------------------------
// ------------------------------------------------

// opens a new window to view a PDF form

function getapdf( fname ){

var t = "/forms/customers/" + fname + ".pdf"
var w = window.open(t, "pdfform", "status=no,toolbar=no,scrollbars=yes,resizable=yes");

return false;

}

// -----------------------------------------------

function helpnotes(helpname){

		t = "help/" + helpname + "-hlp.htm";

		var w = window.open(t, "Help", "hotkeys=no, toolbar=yes, scrollbars=yes, fullscreen=no");
}

// ------------------------------------------------

// function mousetrap() {
// if (event.button==2) { alert("Not Available")}

// return false;
// }
// document.onmousedown=mousetrap

// ------------------------------------------------


function browinfo(){

var browser = "BROWSER INFORMATION:\n";
	for(var propname in navigator){
	browser += propname + ": " + navigator[propname] + "\n"
	}

alert(browser);

}

// ------------------------------------------------
// checks for browser and java compatibility every time




// -----------------------------------------------
// triggered by home.htm loading closes menu options
// and checks browser type

function blanktop(){


	t = "homeheader.asp"
	var l = parent.frames[0].location
	l.replace(t);

	var isIE;
	var is5;

	var an = window.navigator.appName;
	var av = window.navigator.appVersion;

	if (an.indexOf("Microsoft") != -1)
	isIE = true;

	if (av.indexOf("MSIE 5") != -1)
	is5 = true;

	var jv =  navigator.javaEnabled();

	if (is5 == false | isIE == false | jv == false){
		alert("This site will currently only work with Microsoft Internet Explorer 5 or above. You will need to upgrade if you wish to use this website.")
	}

}


// ----------------------------------------------------

// ----------------------------------------------------

function viewinv(cart){

t = "prepay.asp?review=" + cart;
window.location.replace(t)

}

// ----------------------------------------------------
function cartdel(cart){

t = "prepay.asp?kill=" + cart;
window.location.replace(t)

}
//-------------------------------------------------------------
function addordel(alt){

var x = parseInt(document.catitem.numberofcopies.value);





	if (isNaN(x)){
	document.catitem.numberofcopies.value = 1;
	totprice()
	return;
	}

x += alt;
	if (x < 1){x=1};
	

		document.catitem.numberofcopies.value = x;
		totprice();
		return;


}

//--------------------------------------------------------------
function totprice(){
//dynamic update of cost for seleted number of copies of form

	var amt = document.catitem.numberofcopies.value;
	var pgs = document.catitem.pages.value;
	OSOS_Price = document.catitem.OSOS_Price.value;
	OSOS_PricePer = document.catitem.OSOS_PricePer.value;
	
	// PAPER COPY
	if (document.catitem.typeofform.selectedIndex == 0){
	
		var ps = parseFloat(document.catitem.papercopyprice.value);
	
		if(ps != 0){
		//INDIVIDUALLY PRICED
			//x = parseInt(ps * amt * 100);
			x = (amt * OSOS_Price/OSOS_PricePer * 1.175)
			x = parseInt((x * 100) + 0.5);
			x = parseFloat(x /100);
		
	document.getElementById("pprice").innerHTML = "<p> [ Cost £" + x + " ]</p>";

		}
		else {
		//STANDARD PRICE
		var rv = getprice(pgs, amt, document.catitem.OSOS_Price.value, document.catitem.OSOS_PricePer.value);
	document.getElementById("pprice").innerHTML = "<p> [ Cost £" + rv + " ]</p>";

		}
	}
	//PDF COPIES
	else if (document.catitem.typeofform.selectedIndex == 1){
	
	var psw = parseFloat(document.catitem.webcopyprice.value);
	x = parseInt(psw * amt * 100);
	x = parseFloat(x /100);
	
	document.getElementById("pprice").innerHTML = "<p> [ Cost £" + x + " ]</p>";
	
	
	}
	//PDF MONTHS
	else if (document.catitem.typeofform.selectedIndex == 2){
	
		var pswm = parseFloat(document.catitem.webcopyprice.value);
		
		if (amt == 1){ 
		x = parseInt((pswm * 3) * 100);
		}
			
		else if (amt == 2) { 
		x = parseInt((pswm * 5 ) * 100);
		}
		else {
		 x = parseInt(((pswm * 3) + (pswm * amt)) * 100);
		 }
	
		x = parseFloat(x /100);
			
		document.getElementById("pprice").innerHTML = "<p> [ Cost £" + x + " ]</p>";
	
	}
	
}

//--------------------------------------------------------------
function getprice(pgs,  amt, OSOS_Price, OSOS_PricePer){
//called by totprice, same as includes/getprice

var BP;
	if (pgs <= 2) {
		if (isNaN(OSOS_Price)) {
			BP = 1.5;
		}
		else {
			BP = (OSOS_Price * 1.175 / OSOS_PricePer);
		}
	}
	else {
		if (isNaN(OSOS_Price)) {
			BP = 1.75;
		}
		else {
			BP = (OSOS_Price * 1.175 / OSOS_PricePer);
		}
	}
	

	if (pgs <= 2) {

		if (amt == 1) {FP = 3.5}
		else if (amt == 2) {FP = 3}
		else if (amt == 3) {FP = 3}
		else if (amt == 4 ) {FP = 2.65}
		else if (amt < 11) {FP = 2.5}
		else if (amt < 16) {FP = 2.2}
		else if (amt < 21) {FP = 1.8}
		else if (amt < 26) {FP = 1.65}
		else if (amt < 31) {FP = 1.5}
		else {	FP = BP}
 
		
		var x =  amt * FP;
	}
	else if (pgs > 2)  {
	

		if (amt == 1) {FP = 4}
		else if (amt == 2) {FP = 3.5}
		else if (amt == 3) {FP = 3.33}
		else if (amt == 4) {FP = 3}
		else if (amt < 11) {FP = 2.75}
		else if (amt < 16) {FP = 2.5}
		else if (amt < 21) {FP = 2.25}
		else if (amt < 26) {FP = 2}
		else if (amt < 31) {FP = 1.75}
		else {FP = BP}

		
		var x =  amt * FP;
		
	}
	
			x = parseInt((x * 100) + 0.5);
			x = parseFloat(x /100);
			
			return x;
	
}

//--------------------------------------------------------------
function requestbrowserform(fc){
t = "requestform.asp?frm=" + fc
var w = window.open(t, "Request","toolbar=no,status=no,menubar=no,hotkeys=no,width=350,height=150");

return false;
}
   
//===========================================
var openLists = [];
function compactMenu(oID,oAutoCol,oPlMn) {
	if( !document.getElementsByTagName || !document.childNodes || !document.createElement ) { return; }
	var baseElement = document.getElementById( oID ); if( !baseElement ) { return; }
	compactChildren( baseElement, 0, oID, oAutoCol, oPlMn, baseElement.tagName.toUpperCase() );
}
function compactChildren( oOb, oLev, oBsID, oCol, oPM, oT ) {
	if( !oLev ) { oBsID = escape(oBsID); if( oCol ) { openLists[oBsID] = []; } }
	for( var x = 0, y = oOb.childNodes; y[x]; x++ ) { if( y[x].tagName ) {
		//for each immediate LI child
		var theNextUL = y[x].getElementsByTagName( oT )[0];
		if( theNextUL ) {
			//collapse the first UL/OL child
			theNextUL.style.display = 'none';
			//create a link for expanding/collapsing
			var newLink = document.createElement('A');
			newLink.setAttribute( 'href', '#' );
			newLink.onclick = new Function( 'clickSmack(this,' + oLev + ',\'' + oBsID + '\',' + oCol + ',\'' + escape(oT) + '\');return false;' );
			//wrap everything upto the child U/OL in the link
			var theT = y[x].innerHTML.toUpperCase().indexOf('<'+oT);
			var theA = y[x].innerHTML.toUpperCase().indexOf('<A');
			var theHTML = y[x].innerHTML.substr(0, ( theA + 1 && theA < theT ) ? theA : theT );
			while( !y[x].childNodes[0].tagName || ( y[x].childNodes[0].tagName.toUpperCase() != oT && y[x].childNodes[0].tagName.toUpperCase() != 'A' ) ) {
				y[x].removeChild( y[x].childNodes[0] ); }
			y[x].insertBefore(newLink,y[x].childNodes[0]);
			y[x].childNodes[0].innerHTML = oPM + theHTML.replace(/^\s*|\s*$/g,'');
			compactChildren( theNextUL, oLev + 1, oBsID, oCol, oPM, oT );
} } } }
function clickSmack( oThisOb, oLevel, oBsID, oCol, oT ) {
	if( oThisOb.blur ) { oThisOb.blur(); }
	oThisOb = oThisOb.parentNode.getElementsByTagName( unescape(oT) )[0];
	if( oCol ) {
		for( var x = openLists[oBsID].length - 1; x >= oLevel; x-=1 ) { if( openLists[oBsID][x] ) {
			openLists[oBsID][x].style.display = 'none'; if( oLevel != x ) { openLists[oBsID][x] = null; }
		} }
		if( oThisOb == openLists[oBsID][oLevel] ) { openLists[oBsID][oLevel] = null; }
		else { oThisOb.style.display = 'block'; openLists[oBsID][oLevel] = oThisOb; }
	} else { oThisOb.style.display = ( oThisOb.style.display == 'block' ) ? 'none' : 'block'; }
}