
function HTTPSocket(URL, method){
	this.url = URL;
	this.method = method;
	this.postValues = Array();
	this.postKeys = Array();
	this.post = Array();
	this.i = 0;
	if(window.XMLHttpRequest){
		this.xmlhttp = new XMLHttpRequest();
	} else {
		this.xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
}

HTTPSocket.prototype.setVar = function(key, value){
	this.postKeys[this.i] =  key;
	this.postValues[this.i] =  value;
	this.post[this.i] = ""+key+"="+escape(value)+"";
	this.i++;
}

HTTPSocket.prototype.send = function(){
	post = this.post.join("&");

	this.xmlhttp.open(this.method, this.url, false);
	if(post){

		this.xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=ISO-8859-1");
		this.xmlhttp.setRequestHeader("Content-length", post.length);
		this.xmlhttp.setRequestHeader("Connection","close");
		this.xmlhttp.send(post);
	} else {
		this.xmlhttp.send(null);
	}
}

HTTPSocket.prototype.getBody = function(){
	return this.xmlhttp.responseText;
}

function openPagina(a){
	window.title = 'Test';
	b = new HTTPSocket("/h/"+a,"GET");
	b.send();

	document.getElementById("contentvak").innerHTML  = b.getBody();
	createLinks();
	setTimeout(createLinks, 1000);

	window.location = "#"+a;
	huidigepagina = a;
	init();
}

var menuObj  = "";
var menuInterval = 0;
var menuHeight = 0;

function openJSMenu(obj, d){
	obj2 = document.getElementById(obj);

	if(document.all){
		ul_list = obj2.parentElement.parentElement.getElementsByTagName("ul");
		img_list = obj2.parentElement.parentElement.getElementsByTagName("img");
	} else { 
		ul_list = obj2.parentNode.parentNode.getElementsByTagName("ul");
		img_list = obj2.parentNode.parentNode.getElementsByTagName("img");
	}

	for(i=0; i < img_list.length; i++){
		if(img_list[i].src.indexOf("pijl1.png") == -1){
			img_list[i].src="/images/pijl1.png";
		}
	} 

	d.getElementsByTagName("img")[0].src="/images/pijl2.png";

	// parentNode in firefox.. straks fixen

	for(i=0; i < ul_list.length; i++){
		ul_list[i].style.display = "none";
	}
	document.getElementById(obj).style.display = "block"; 
}

function openSlideMenu(){
	nr = Number(document.getElementById(menuObj).style.height.split("px")[0]+1);
	if(nr > menuHeight){
		clearInterval(menuInterval);
	}
	document.getElementById(menuObj).style.height = nr+"px";
}

var deURL = "http://www.synermediagroep.nl";

function createLinks(){
	url = "";
	links = document.getElementsByTagName("a");
	
	for(i=0; i < links.length; i++){
		if(links[i].href.toString().substring(0,29) == deURL){
			links[i].onclick = function(){
				newlink = this.href.toString().substring(29);
				window.scrollTo(0,0);
				if(newlink == "/"){
					newlink = "/home.html";
				}
				openPagina(newlink);
				return false;
			}
		}
	}
}

function checkPagina(){
	var p = window.location.toString().split("#")[1];
	if(huidigepagina != p){
		openPagina(p);
	}
}

function init(){
	f = document.getElementsByTagName("form");
	if(f.length > 0){
		for(i=0; i < f.length; i++){

			if(f[i].action.indexOf("/focus/") == -1){
				f[i].onsubmit = function(){
					var con2 = new HTTPSocket(this.action,"POST");
					//alert(this.action);
					inp = this.getElementsByTagName("input");
					for(a=0; a < inp.length; a++){
						//alert(inp[a].name+"   =  "+inp[a].value);
						con2.setVar(inp[a].name, inp[a].value);    
					}

					inp = this.getElementsByTagName("select");
	
					for(a=0; a < inp.length; a++){
						//alert(inp[a].name+"   =  "+inp[a].value);
						con2.setVar(inp[a].name, inp[a].value);    
					}
	
					inp = this.getElementsByTagName("textarea");
					for(a=0; a < inp.length; a++){
						//alert(inp[a].name+"   =  "+inp[a].value);
						con2.setVar(inp[a].name, inp[a].value);    
					}
	
					con2.send();
					document.getElementById("contentvak").innerHTML  = con2.getBody();
	
					return false;
				}
			}
		}
	}
}

function submit_form(d){
	if(document.all){
		tag = d.parentElement.tagName.toLowerCase();
		obj = d.parentElement;
		
		while(tag != "form"){
			//alert(tag);
			tag = obj.parentElement.tagName.toLowerCase();
			obj = obj.parentElement;
		}
	
		obj.submit();
	} else {
		tag = d.parentNode.tagName.toLowerCase();
		obj = d.parentNode;

		while(tag != "form"){
			alert(tag);
			tag = obj.parentNode.tagName.toLowerCase();
			laatste = obj;
			obj = obj.parentNode;
		}

		//alert(tag);

		laatste.submit();
	}
}

