var xmlhttp;
var page;
var target = "<h2>LOADING...</h2>";

	function query_async(url) {
		if (window.XMLHttpRequest) {
			xmlhttp=new XMLHttpRequest();
			xmlhttp.onreadystatechange = get_status;
			xmlhttp.open("GET",url,true);
			xmlhttp.send(null);
	
		} else if (window.ActiveXObject) {
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
			if (xmlhttp) {
				xmlhttp.onreadystatechange = get_status;
				xmlhttp.open("GET",url,true);
				xmlhttp.send();
    			}
		}
	}


	function query(url) {
		if (window.XMLHttpRequest) {
			xmlhttp=new XMLHttpRequest();
			xmlhttp.open("GET",url,false);
			xmlhttp.send(null);
	
		} else if (window.ActiveXObject) {
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
			if (xmlhttp) {
				xmlhttp.open("GET",url,false);
				xmlhttp.send();
    			}
		}
	return xmlhttp.responseText;
	}

	function get_page(id, action, lang, show) {
	
		target = document.getElementById("loader");
		page = query_async("get_section.php?section=" + id + "&action=" + action + "&lang=" + lang + "&show=" + show);

	}

	function get_status() {
		if (xmlhttp.readyState == 4) {
			if (xmlhttp.status == 200) {
				target.innerHTML = "LOADING...";
				target.innerHTML = xmlhttp.responseText;
				
				if (navigator.appName == "Microsoft Internet Explorer") {
					correctPNG();
				}
				set_repeat();
			}
		} else if (xmlhttp.readyState == 2) {
			target.innerHTML = "<h2>LOADING...</h2>";
		}
	}

	function show_image(name, ref) {
		//nice and simple stoopid switch
		//this is a workaround because of IE's problems with PNG's
		//sorry :(
		a = document.getElementById("angle");
		f = document.getElementById("front");
		s = document.getElementById("side");

		ad = (ref == "angle") ? "block" : "none";
		sd = (ref == "side") ? "block" : "none";
		fd = (ref == "front") ? "block" : "none";

		a.style.display = ad;
		f.style.display = fd;
		s.style.display = sd;
	}

	function val_form() {
		error = new Array();
		table = document.getElementById("thetable");
		pieces = table.getElementsByTagName("input");
		bmessage = document.getElementById("msg");

		for (var i = 0; i < pieces.length; i++) {
			if (pieces[i].id == "subject") {
				mesg = document.getElementById(pieces[i].id +"_msg");
				if (pieces[i].value.length < 1) {
					col = "#e5ea91";
					warn = "Not Complete";
					error.push(1);
				} else {
					warn = "";
					col = "white";
	
				}
			pieces[i].style.backgroundColor = col;
			mesg.innerHTML = warn;
			}

			if (pieces[i].id == "email") {
				obj = document.getElementById(pieces[i].id + "_msg");
				if (pieces[i].value.length > 1) {
					result = query("email_checker.php?email=" + pieces[i].value);
					if (result == 1) {
						objcolor ="#e5ea91";
						objmsg = "Invalid Email";
						error.push(1);
					} else {
						objmsg = "";
						objcolor = "white";
					}
				} else {
					//error more info required
						objmsg = "Invalid Email";
						objcolor = "#e5ea91";
						error.push(1);
				}

				pieces[i].style.backgroundColor = objcolor;
				obj.innerHTML = objmsg;

			}

		}

		if (error.length == 0) {
			for (var i = 0; i < pieces.length; i++) {
				pieces[i].disabled = true;
			}
				bmessage.disabled = true;
		
			emesg = document.getElementById("end_msg");
			result = query("email_checker.php?subject=" + pieces[1].value + "&email=" + pieces[0].value + "&message=" + message.value + "&sendmail=yes");

			if (result == 0) {
				emesg.innerHTML = "<h2>Message Sent</h2>";
			} else {
				emesg.innerHTML = "<h2>Message Not Sent!</h2>";
			}

		}
			
	}
