function getWidth(str){
	return new Number(str.substr(0, str.length - 2));
}

function $xml(obj){
	var $elements = [];
	for(var i = 0, len = obj.childNodes.length; i < len; ++i){
		try{
			var nametag = obj.childNodes[i].nodeName;
			if(nametag != "#text"){
				if(typeof($elements[nametag]) != "object") $elements[nametag] = [];
				$elements[nametag][$elements[nametag].length] = obj.childNodes[i];
			}
		}
		catch(e){}
	}
	return $elements;
}

function opacity(id, opacStart, opacEnd, millisec) {
	var speed = Math.round(millisec / 200);
	var timer = 0;
	if(opacStart > opacEnd) {
		for(i = opacStart; i >= opacEnd; i--) {
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	} else if(opacStart < opacEnd) {
		for(i = opacStart; i <= opacEnd; i++)
			{
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	}
}
function changeOpac(opacity, id) {
	var object = document.getElementById(id).style; 
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
}

function shiftOpacity(id, millisec) {
	if(document.getElementById(id).style.opacity == 0) {
		opacity(id, 0, 10, millisec);
	} else {
		opacity(id, 10, 0, millisec);
	}
}

function blendimage(divid, imageid, imagefile, millisec) {
	var speed = Math.round(millisec / 100);
	var timer = 0;
	document.getElementById(divid).style.backgroundImage = "url(" + document.getElementById(imageid).src + ")";
	changeOpac(0, imageid);
	document.getElementById(imageid).src = imagefile;
	for(i = 0; i <= 100; i++) {
		setTimeout("changeOpac(" + i + ",'" + imageid + "')",(timer * speed));
		timer++;
	}
}

function currentOpac(id, opacEnd, currentOpac, millisec) {
	if(document.getElementById(id).style.opacity < 100) {
		currentOpac = document.getElementById(id).style.opacity * 100;
	}
	opacity(id, currentOpac, opacEnd, millisec)
}

function validate(form_name){
	var $form = $("innercontainer").getElementsBySelector("[name=\""+form_name+"\"]")[0];
	var $fields = $form.getElementsByTagName("input");
	var $_fields = [];
	var $form_id = $fields[0].value;
	var params = [];
	var $width = 0;
	for(var i = 0, len = $fields.length; i < len; ++i){
		$_fields[$fields[i].name] = $fields[i];
		switch($fields[i].type){
			case "text":
			case "password":
				if($fields[i].className == "inputerror"){
					$width = getWidth($fields[i].style.width);
					$width += 17;
					$width = new String($width);
					$width += "px";
					$fields[i].style.width = $width;
				}
				$fields[i].className = "input";
				$("errorfield_"+form_name).update();
			break;
		}
		params[params.length] = $fields[i].name+"="+$fields[i].value;
	}
	new Ajax.Request("index.php?com=form&sub=validate_ajax&mode=standalone", {
		method: 'post',
		postBody: params.join("&"),
		onSuccess: function(transport){
			var xml = transport.responseXML.documentElement;
			var $elements = $xml(xml);
			var errors = $elements['inputerror'] != null ? $elements['inputerror'] : [];
			var $submit = $elements['submit'] != null ? $elements['submit'] : [];
			var target = $elements['target'] != null ? $elements['target'] : [];
			var message = "";
			for(var i = 0, len = errors.length; i < len; ++i){
				//alert(errors[i].readAttribute("name"));
				var name = errors[i].attributes.getNamedItem("name").value;
				var msg = errors[i].firstChild.nodeValue;
				/*
				var loop = errors[i].attributes.getNamedItem("name");
				var ss = "";
				for(a in loop) ss += a +" = "+loop[a]+"\n";
				alert(ss);
				*/
				$_fields[name].className = "inputerror";
				$_fields[name].style.width = new String(getWidth($_fields[name].style.width)-17) + "px";
				message += " &rsaquo; "+msg+"<br />";
			}
			$("errorfield_"+form_name).update(message);
			if(errors.length == 0){
				//alert($submit[0].firstChild.nodeValue);
				new Ajax.Request($submit[0].firstChild.nodeValue, {
					method: 'post',
					postBody: params.join("&"),
					onSuccess:function(transport){
						switch(transport.responseText){
							case "OK":
								target[0].firstChild.nodeValue.length < 1 ? window.location.reload() : window.location = target[0].firstChild.nodeValue;
							break;
							default:
								alert(transport.responseText);
							break;
						}
					}
				});
			}
		}
	});
}
function UI(){
	this.numstep = function(name){
		this.name = name;
		this.current = 0;
		this.steps = [];
		this.value = "";
		this.setValue = function(value){
			this.current = this.steps.indexOf(value) > -1 ? this.steps.indexOf(value) : this.current;
			this.value = this.steps[this.current];
		};
		this.up = function(){
			this.current = typeof(this.steps[this.current+1]) != "undefined" ? this.current+1 : this.current;
			$("numstep_"+this.name+"_display").innerHTML = this.steps[this.current];
			$("numstep_"+this.name).value = this.steps[this.current];
			this.value = this.steps[this.current];
		};
		this.down = function(){
			this.current = typeof(this.steps[this.current-1]) != "undefined" ? this.current-1 : this.current;
			$("numstep_"+this.name+"_display").innerHTML = this.steps[this.current];
			$("numstep_"+this.name).value = this.steps[this.current];
			this.value = this.steps[this.current];
		};
	};
}
var UI = new UI();

function WHOIS(){
	this.extentions = [];
	this.responses = [];
	this.dns = [];
	this.check = function(domain){
		var extentions = this.extentions;
		var responses = [];
		var ext = "";
		var url = "";
		var status = "";
		for(var i = 0, len = extentions.length; i < len; ++i){
			ext = extentions[i];
			int = i;
			url = "index.php?com=whois&sub=proxy&domain="+domain+"&ext="+ext+"&mode=standalone";
			new Ajax.Request(url, {
				method : 'get',
				onSuccess: function(transport){
					responses[responses.length] = transport.responseText;
					if(int == (extentions.length-1)){
						for(var i = 0, len = extentions.length; i < len; ++i){
							ext = extentions[i];
							switch(responses[i]){
								case "Bezet":
									$("status_"+ext).setStyle({ color : "#CC0000" });
								break;
								case "Beschikbaar":
									$("status_"+ext).setStyle({ color : "#00CC00" });
									$("img_"+ext).src = "_user/img/shoppingcart.png";
									$("img_"+ext).onmouseover = new Function("Tip('Toevoegen aan winkelwagen')");
								break;
								case "Onbekend":
									$("status_"+ext).setStyle({ color : "#CC0000" });
								break;
							}
							str = typeof(responses[i]) != "undefined" ? responses[i] : "Bezig met controleren...";
							$("status_"+ext).update(str);
						}
					}
				}
			});
		}
	};
	this.addExtention = function(ext){
		this.extentions[this.extentions.length] = ext;
	};
}




/*
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="36" height="22" id="tlds" align="middle">
<param name="allowScriptAccess" value="sameDomain" />
<param name="movie" value="{SYS_LOCATION}_user/media/tlds.swf" />
<param name="menu" value="false" />
<param name="quality" value="high" />
<param name="wmode" value="transparent" />
<param name="bgcolor" value="#ffffff" />
<embed src="{SYS_LOCATION}_user/media/tlds.swf" menu="false" quality="high" wmode="transparent" bgcolor="#ffffff" width="36" height="22" name="tlds" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>
*/


function SWF(url, width, height, bgcolor, wmode){
	this.params = [];
	this.addParam = function(name, value){
		this.params[name] = value;
	}
	this.parse = function(id){
		var $object = document.createElement("object");
		$object.classid = "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000";
		$object.codebase = "http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0";
		$object.width = width;
		$object.height = height;
		$object.align = "middle";
		this.params.each(function(value, name){
			$param = document.createElement("param");
			$param.name = name;
			$param.value = value;
			$object.appendChild($param);
		});
		var $embed = document.createElement("embed");
		$embed.src = url;
		$embed.menu = false;
		$embed.quality = "high";
		$embed.wMode = "transparant";
		$embed.bgColor = bgcolor;
		$embed.width = width;
		$embed.height = height;
		$embed.align = "middle";
		//$embed.allowScriptAccess = "sameDomain";
		$embed.type = "application/x-shockwave-flash";
		//$embed.pluginsPage = "http://www.macromedia.com/go/getflashplayer";
		$object.appendChild($embed);
		document.getElementById(id).parentNode.appendChild($object);
		document.getElementById(id).parentNode.removeChild(document.getElementById(id));
	}
}
