//
// Javascript by Mark Theyer for RevSoft Pty Ltd
//
// (borrowed this code from www.theyergfx.com)
// 


// register as a new user
function doregister() {

	var product = document.all.item("product");
	var opsys   = document.all.item("opsys");
	var osver   = document.all.item("osver");

	var qs = new Querystring();
	product.value = qs.get("product", "default none");
	opsys.value   = qs.get("opsys",   "default windows");
	osver.value   = qs.get("osver");

	var dproduct = document.all.item("desired_product");
	var dopsys   = document.all.item("desired_opsys");
	var dosver   = document.all.item("desired_osver");
	dproduct.value = qs.get("product", "default none");
	dopsys.value   = qs.get("opsys",   "default windows");
	dosver.value   = qs.get("osver");

	document.forms.register.submit();
}


// perform revsoft download
function dodownload() {

	var product = document.all.item("product");
	var opsys   = document.all.item("opsys");
	var osver   = document.all.item("osver");

	var qs = new Querystring();
	product.value = qs.get("product", "default none");
	opsys.value   = qs.get("opsys",   "default windows");
	osver.value   = qs.get("osver");

	var form = document.all.item("download");
	form.submit();
}


// open a new window
function open_win( url ) {
	window.open( url );
}


// go back to the home page
function go_home() {
	window.replace( 'http://www.3dkitbuilder.com/main.htm' );
}


// download a file
function xppopup() {
	window.open( 'http://www.3dkitbuilder.com/xp/popup.htm', '_blank', 'toolbar=no, directories=no, location=no, status=no, menubar=no, resizable=yes, scrollbars=yes, width=500, height=600' );
}


// download a file
function download_file( url ) {
	window.open( url, '_blank', 'toolbar=no, directories=no, location=no, status=no, menubar=no, resizable=yes, scrollbars=no, width=300, height=100' );
	window.status = 'loading...';
}


// download a file
function open_barewin( url, width, height ) {
	window.open( url, '_blank', 'toolbar=no, directories=no, location=no, status=no, menubar=no, resizable=yes, scrollbars=no, width=' + width + ', height=' + height );
	window.status = 'loading...';
}


// show next slide
function next_slide( nslides, returnurl ) {
	
	var slide, i, url, regexp, name, next;

	slide = document.all.item("slide");
	if (slide) {
		url  = slide.src;
		regexp = "Slide" + nslides + ".JPG";
		if (url.match(regexp)) {
			window.location = returnurl;
			return;
		} 
		for( i=1; i<nslides; i++ ) {
			regexp = "Slide" + i + ".JPG";
			next   = "Slide" + (i+1) + ".JPG";
			//alert( i + " = " + regexp + "\n" + next ); 
			name = url.replace(regexp,next);
			//alert( url + "\n" + name );
			if (name != slide.src)
			{
				slide.src = name;
				return;
			}
		}
	}
}


// swap to the highlighted version of the label
function displaypagebyname(name,link,width,height) {


	var url, name, regexp, page, e;
	
	e = document.all.item(name);
	if (e) {
		page = document.all.item("page");
		page.src = "loading_page.jpg";
		url = e.src;
		name = name + "_page.jpg";
		page.style.display = 'none';
		page.src = name;
		page.style.display = 'block';
		var ref = document.all.item("link");
		if (width > 0) {
			ref.href='javascript:open_barewin("' + link + '",' + width + ',' + height + ')';
		} else {
			ref.href=link;
		}
		// highlight(e);
		window.status = name;
	}
}


// swap to the highlighted version of the label
function displaypage(e,link,width,height) {

	var url, name, regexp, page;
	
	page = document.all.item("page");
	page.src = "loading_page.jpg";
	url = e.src;
	regexp = /.gif$/i;
	name = url.replace(regexp,"_page.jpg");
	page.style.display = 'none';
	page.src = name;
	page.style.display = 'block';
	var ref = document.all.item("link");
	if (width > 0) {
		ref.href = 'javascript:open_barewin("' + link + '",' + width + ',' + height + ')';
	} else {
		ref.href = link;
	}
	highlight(e);
	window.status = name;
}


// swap to the highlighted version of the label
function highlight(e) {
	hide_menu();
	if ( e.tagName == "IMG" ) {
		var url, name, regexp;
		//window.event.srcElement.hspace = 2;
		//window.event.srcElement.vspace = 2;
		url = e.src;
		regexp = /.gif/i;
		name = url.replace(regexp,"_h.gif");
		e.src = name;
	}
}


// swap to the normal version of the label
function normal(e) {
	if ( e.tagName == "IMG" ) {
		var url, name, regexp;
		//window.event.srcElement.hspace = 0;
		//window.event.srcElement.vspace = 0;
		url = e.src;
		regexp = /_h.gif/i;
		name = url.replace(regexp,".gif");
		e.src = name;
	}
}


// swap the color
function swapcolor(e,col) {
	e.bgColor = col;
}


// display a 3D model from the dropmenu
function open_model( url ) {
	window.open( url, '_blank', 'toolbar=no, directories=no, location=no, status=no, menubar=no, resizable=yes, scrollbars=no, width=800, height=600' );
}


// draw the background box with a menu
function draw_main() {

	// menu
	draw_menu( "", 30, 30, 175 );
	draw_help_menu( "", 0, 0, 180 );
	//draw_background();
}


// draw the background box and background
function draw_kit() {

	// menu
	draw_menu( "../", 30, 30, 175 );
	draw_help_menu( "../", 0, 0, 180 );
}


// show the menu
function show_menu() {

	var		menu;

	menu = document.all.item("menu");
	if ( menu != null ) {
		menu.style.display = "block";
	} else {
		//alert( "Oops, the menu is still loading... going to the site map" );
		window.location = 'http://www.3dkitbuilder.com/map.htm';
	}
}


// show the help menu
function show_help() {

	var		menu;
	var		box;
	var		left;
	var		top;
	var		width;
	var		height;

	left = 0
	box = document.all.item("helpbox");
	if ( box != null ) {
		left = box.offsetLeft;
	}

	menu = document.all.item("help");
	if ( menu != null ) {
		menu.style.left = (left - 175) + 30;
		menu.style.top  = 30;
		menu.style.display  = "block";
	} else {
		//alert( "Oops, the menu is still loading... going to the site map" );
		window.location = 'http://www.3dkitbuilder.com/map.htm';
	}
}


// hide the menu
function hide_menu() {

	var		menu;

	menu = document.all.item("menu");
	if ( menu != null ) {
		menu.style.display = "none";
	}

	menu = document.all.item("help");
	if ( menu != null ) {
		menu.style.display = "none";
	}
}


// draw the menu
function draw_menu( path, x, y, width ) {

	var		html;
	var		box;
	var		height;

	// init
	height = 20;
	color  = "#FFFFFF";
	hcolor = "#CCCCCC";

	// menu code
	html = menu_start( "menu", x, y, width ) + 
		   menu_title( "3D Kit Builder", height, "#FF0000" ) +
		   menu_item(  "Home",					path, "main",		height, color, hcolor ) +
		   menu_item(  "3D Model Kits",			path, "kits",		height, color, hcolor ) +
		   menu_item(  "News",					path, "news",		height, color, hcolor ) +
		   menu_item(  "3D Preview",			path, "open_preview", height, color, hcolor ) +
		   menu_title( "Feedback", height, "#FF0000" ) +
		   menu_item(  "Suggest a Model",		path, "suggest",	height, color, hcolor ) +
		   menu_item(  "Sponsor a Model",		path, "sponsor",	height, color, hcolor ) +
		   menu_item(  "Your Ideas",			path, "feedback",	height, color, hcolor ) +
		   menu_item(  "Contact Us",			path, "contact",	height, color, hcolor ) +
		   menu_title( "Exit", height, "#FF0000" ) +
		   menu_end();

	// insert html
	box = document.body;
	if ( box != null ) {
		box.insertAdjacentHTML( "BeforeEnd", html );
	}
}


// draw the menu
function draw_help_menu( path, x, y, width ) {

	var		html;
	var		box;
	var		height;

	// init
	height = 20;
	color  = "#FFFFFF";
	hcolor = "#CCCCCC";

	// menu code
	html = menu_start( "help", x, y, width ) + 
		   menu_title( "About",	height, "#FF0000" ) +
		   menu_item(  "3D Kit Builder",		path, "aboutkit",	height, color, hcolor ) +
		   menu_item(  "System Requirements",	path, "system",	height, color, hcolor ) +
		   menu_item(  "Developer",				path, "aboutus",	height, color, hcolor ) +
		   menu_title( "Retail and Distribution", height, "#FF0000" ) +
		   menu_item(  "Buy from a Retailer",	path, "instore",	height, color, hcolor ) +
		   menu_item(  "Opportunities",			path, "retail",		height, color, hcolor ) +
		   menu_item(  "Register",				path, "register",	height, color, hcolor ) +
		   menu_item(  "Place an Order",		path, "order",		height, color, hcolor ) +
		   menu_item(  "Contact Us",			path, "contact",	height, color, hcolor ) +
		   menu_title( "Help", height, "#FF0000" ) +
		   menu_item(  "Installation Help",		path, "install",	height, color, hcolor ) +
		   menu_item(  "Help and Support",		path, "support",	height, color, hcolor ) +
		   menu_item(  "Site Map",				path, "map",	height, color, hcolor ) +
		   menu_item(  "Links",					path, "links",	height, color, hcolor ) +
		   menu_title( "Exit", height, "#FF0000" ) +
		   menu_end();

	// insert html
	box = document.body;
	if ( box != null ) {
		box.insertAdjacentHTML( "BeforeEnd", html );
	}
}


// start of a menu
function menu_start( name, x, y, width ) {

	var opt;

	opt = "<TABLE id=\"" + name + "\" style=\"display: none; position: absolute; left: " + x + "; top: " + y + 
	"; width: " + width + ";\" cellPadding=0 cellSpacing=0 border=0>" +
	menu_line_x(2);

	return( opt );
}


// end of a menu
function menu_end() {

	var opt = menu_line_x(2) +
		"</TABLE>";

	return( opt );
}


// menu line x
function menu_line_x( size ) {

	var opt = "<TR height=" + size + "><TD bgcolor=FF0000></TD><TD bgcolor=FF0000></TD><TD bgcolor=FF0000></TD></TR>";
	return( opt );
}


// menu line y
function menu_line_y( size ) {

	var opt = "<TD bgcolor=FF0000 width=" + size + ">";
	return( opt );
}


// draw a menu item
function menu_item( title, path, name, height, color, hcolor ) {
	
	var opt;

	opt = "<TR height=" + height + "><A HREF=" + path + name + ".htm>" + menu_line_y(2) +
	"<TD style=\"cursor: hand\" bgcolor=\"" + color + "\" onmouseover=menu_highlight(\"" + hcolor + "\") onmouseout=menu_normal(\"" + color + "\")>" +
	"<FONT face=Arial size=3 color=FF0000 style=\"textDecoration: none\" onmouseover=menu_highlight(\"" + hcolor + "\") onmouseout=menu_normal(\"" + color + "\")>&nbsp" + 
	title +
	"</TD></A>" +  menu_line_y(2) + "</TR>";
	
	//alert( opt );
	return( opt );
}


// draw a menu title
function menu_title( title, height, color ) {
	
	var opt;

	opt = "<TR height=" + height + ">" + menu_line_y(2) +
		"<TD align=center bgcolor=\"" + color + "\">" +
		"<FONT face=Arial size=3 color=FFFFFF ><B>" + 
		title + 
		"</TD>" +  menu_line_y(2) + "</TR>";
		// + 
		//menu_line_x(2);
	
	return( opt );
}


// swap to the highlighted version of the menu
function menu_highlight( color ) {

	var	element;

	if ( window.event.srcElement.tagName == "TD" ) {
		window.event.srcElement.bgColor = color;
	} else {
		element = window.event.srcElement.parentElement;
		while( element != null && element.tagName != "TD" ) {
			element = element.parentElement;
		}	
		element.bgColor = color;
	}
}


// swap to the normal version of the menu
function menu_normal( color ) {

	var	element;

	if ( window.event.srcElement.tagName == "TD" ) {
		window.event.srcElement.bgColor = color;
	} else {
		element = window.event.srcElement.parentElement;
		while( element != null && element.tagName != "TD" ) {
			element = element.parentElement;
		}	
		element.bgColor = color;
	}
}


// show 3d preview help
function show_3d_help () {
	window.open( 'help3d.htm', '_blank', 'toolbar=no, directories=no, location=no, status=no, menubar=no, resizable=yes, scrollbars=no, width=600, height=550'  );
}


// show preview
function show_preview () {
	window.open( 'detect.htm', '_blank', 'toolbar=no, directories=no, location=no, status=no, menubar=no, resizable=yes, scrollbars=no, width=800, height=600'  );
}


// draw background images
function draw_background() {

	var		html;
	var		box;
	var		left;
	var		top;
	var		width;
	var		height;
	var		grid;
	var     page;

	// use a grid size of 800 pixels...
	grid = 800;

	// draw
	var page = document.all.item("page");
	if ( page != null ) {
		height = page.offsetHeight;
		if ( height >= grid ) {

			// create table same size
			html = "<TABLE width=100% style=\"z-index: -1; position: absolute; left: 0; top: 0;\" cellPadding=0 cellSpacing=0 border=0>";

			// add image 1 per grid size
			while( height > grid ) {
				html = html + "<TR><TD align=center height=800><IMG border=0 src=3dback.gif></TD></TR>";
				height = height - grid;
			}

			// finish off table
			html = html + "</TABLE>";

			// insert html
			alert('insert!');
			//page.insertAdjacentHTML( "AfterBegin", html );
		}
		alert('height=' + height);
	}
}


// detect shockwave
function detect_shockwave ( url ) {

	var FlashMode = 0;
	var ShockMode = 0;

	<!-- attempt to detect at least Shockwave 8.5 -->
	if ( navigator.mimeTypes && navigator.mimeTypes["application/x-director"] && navigator.mimeTypes["application/x-director"].enabledPlugin ) {

		if ( navigator.plugins && navigator.plugins["Shockwave for Director"] && (versionIndex = navigator.plugins["Shockwave for Director"].description.indexOf(".")) != - 1 ) {

			var versionString		= navigator.plugins["Shockwave for Director"].description.substring(versionIndex-1, versionIndex);
			var subVersionString	= navigator.plugins["Shockwave for Director"].description.substring(versionIndex+1, versionIndex+2);
			versionIndex			= parseInt( versionString );
			subVersionIndex			= parseInt(subVersionString);

			if ( versionIndex = 8 ) {
				if ( subVersionIndex >= 5 )
					ShockMode = 1;
			} else if ( versionIndex > 8 ) {
				ShockMode = 1;
			}
		}
	} else if ( navigator.userAgent && navigator.userAgent.indexOf("MSIE") >= 0 && (navigator.userAgent.indexOf("Windows 95")>=0 || navigator.userAgent.indexOf("Windows 98") >= 0 || navigator.userAgent.indexOf("Windows NT") >= 0 )) {

	    document.write('<SCRIPT LANGUAGE=VBScript\> \n');
	    document.write('on error resume next \n');
	    document.write('ShockMode = (IsObject(CreateObject("SWCtl.SWCtl.8.5")))\n');
	    document.write('</SCRIPT\> \n');

    }

	<!-- no Shockwave? -->
	if ( ShockMode = 0 ) {
		url = 'noshock.htm';
	}

	window.location.replace( url );
}


// get shockwave plug-in
function get_shockwave () {

	window.open( 'http://www.macromedia.com/shockwave/download' );
}


/* Client-side access to querystring name=value pairs
	Version 1.2.3
	22 Jun 2005
	Adam Vandenberg
*/
function Querystring(qs) { // optionally pass a querystring to parse
	this.params = new Object()
	this.get=Querystring_get
	
	if (qs == null)
		qs=location.search.substring(1,location.search.length)

	if (qs.length == 0) return

// Turn <plus> back to <space>
// See: http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.4.1
	qs = qs.replace(/\+/g, ' ')
	var args = qs.split('&') // parse out name/value pairs separated via &
	
// split out each name=value pair
	for (var i=0;i<args.length;i++) {
		var value;
		var pair = args[i].split('=')
		var name = unescape(pair[0])

		if (pair.length == 2)
			value = unescape(pair[1])
		else
			value = name
		
		this.params[name] = value
	}
}

function Querystring_get(key, default_) {
	// This silly looking line changes UNDEFINED to NULL
	if (default_ == null) default_ = null;
	
	var value=this.params[key]
	if (value==null) value=default_;
	
	return value
}

