
var timestamp = Math.round((Math.random() * 1000)*(Math.random()*100));
var alphabet = "abcdefghijklmnopqrstuvwxyz";
var pop = 0;
var popups = new Array();

function save(toggle) {
	switch(toggle) {
		case 1:
			document.mainform.state.value="save & preview";
			break;
		case 2:
			document.mainform.state.value="save";
			break;
		case 3:
			document.mainform.state.value="preview";
			break;
	}
	document.mainform.submit();
}

function logout() {
	var biscuit = "USER";
	var lastyear = new Date();								//	get date
	lastyear.setFullYear(lastyear.getFullYear() - 1);		//	take a year off it
	document.cookie = biscuit + "=null; expires=" + lastyear.toGMTString();	// and write an expired cookie
	self.location = "/index.html";
}

function shade(oldcolour) {
	refstr="0123456789ABCDEF";
	attrib = new Array();
	attrib[0] = oldcolour.slice(1,3);
	attrib[1] = oldcolour.slice(3,5);
	attrib[2] = oldcolour.slice(5,7);
	for(at = 0; at < 3; at++) {
		fv = attrib[at].slice(0,1);
		fv = fv.toUpperCase();
		var ps = refstr.indexOf(fv);
		if(ps > 7) {
			fv = refstr.slice(ps-1,ps);
		} else {
			fv = refstr.slice(ps+1,ps+2);
		}
		sv = attrib[at].slice(1);
		sv = sv.toUpperCase();
		var ps = refstr.indexOf(sv);
		if(ps > 7) {
			sv = refstr.slice(ps-1,ps);
		} else {
			sv = refstr.slice(ps+1,ps+2);
		}
		attrib[at] = fv + sv;
	}
	var newcolour = "#" + attrib[0] + attrib[1] + attrib[2];
	return newcolour;
}

function imageinfo(a,b,c,d,e,f) {
	var command = a + "," + b + "," + c + "," + d + "," + e + "," + f;
	c = (c-0) + 20;
	d = (d-0) + 100;
	var left = (800 - c)/2;
	var top = (600 - d)/2;
	alert("c:" + c + " d:" + d);
	window.open("/image_inspector.html?" + command,"imageinspector","width=" + c + ",height=" + d + ",top=" + top +",left=" + left + ",SCREENX=" + left + ",SCREENY=" + top,false);
}

function templates(set) {
	window.open("/_tools/templates_F.html?"+set,"Templates","height=60,width=450,left=200,top=200,screenX=200,screenY=200",true);	
}

function navigate_old(direction) {
	if(page.length == 1) {
		var curpage = -1;
		var cursec = alphabet.indexOf(page);
	} else {
		var curpage = alphabet.indexOf(page.charAt(1));
		var cursec = alphabet.indexOf(page.charAt(0));
	}
	if(direction == "prev") {
		if(curpage == -1) {
			var prevpage = 7;
			var prevsec = cursec - 1;
			var thelink = action + alphabet.charAt(prevsec) + alphabet.charAt(prevpage);
			if(edit_mode == 3) thelink = thelink + ".html";
		} else {
			var prevpage = curpage - 1;
			var prevsec = cursec;
			var thelink = action + alphabet.charAt(prevsec) + alphabet.charAt(prevpage);
			if(edit_mode == 3) thelink = thelink + ".html";
		}
		if(curpage == -1 && cursec == 0) {
			document.write("&nbsp;");
		} else {
			document.write("<A HREF='" + thelink + "'><FONT SIZE='1' COLOR='#" + textst + "'>&lt;&lt; Previous</FONT></A>");
		}
	}
	if(direction == "next") {
		if(curpage == 7) {
			var nextpage = 0;
			var nextsec = cursec + 1;
			var thelink = action + alphabet.charAt(nextsec);
			if(edit_mode == 3) thelink = thelink + ".html";
		} else {
			var nextpage = curpage + 1;
			var nextsec = cursec;
			var thelink = action + alphabet.charAt(nextsec) + alphabet.charAt(nextpage);
			if(edit_mode == 3) thelink = thelink + ".html";
		}
		if(curpage == 7 && cursec == 7) {
			document.write("&nbsp;");
		} else {
			document.write("<A HREF='" + thelink + "'><FONT SIZE='1' COLOR='#" +  + textst + "'>Next &gt;&gt;</FONT></A>");
		}
	}
}

// shiny new popups

// Link Popup
function doLink(field)
{
	url = "/_tools/html/pop_link.html?" + field;
	pop = window.open(url,"LinkEd","WIDTH=300,HEIGHT=260",1);
}
// Style Popup
function doStyle(field)
{
	url = "/_tools/html/pop_style.html?" + field;
	pop = window.open(url,"StyleEd","WIDTH=300,HEIGHT=280",1);
}
// List Popup
function doList(field)
{
	url = "/_tools/html/pop_list.html?" + field;
	pop = window.open(url,"ListEd","WIDTH=300,HEIGHT=280",1);
}

function controls(field)
{
	document.write("<font size=\"1\">( ");
	document.write("<a href=\"javascript:doLink('" + field + "');\">Add Link</A> | ");
	document.write("<a href=\"javascript:doStyle('" + field + "');\">Add Style</A> | ");
	document.write("<a href=\"javascript:doList('" + field + "');\">Add List</A>");
	document.write(" )</font>");
}

function infopop(num)
{
	pop = window.open("/_tools/quickhelp/info.html?" + num,"QuickHelp","WIDTH=300,HEIGHT=100");
}

function popup(image,width,height)
{
	now = new Date();
	mils = now.getMilliseconds();
	pop = window.open("http://www.take2theweb.com/_tools/popup.html?" + image,"popup" + mils.toString() ,"WIDTH=" + width + ",HEIGHT=" + (height+20));
}

function update_link(who)
{
	var dname = who.name.slice(0, who.name.length - 5);
	var dest = eval("document.mainform." + dname);
	dest.value = who.value + ".html";
}
