var http_request = false;

function makePOSTRequest(url, parameters, callback) {
	http_request = false;
	if (window.XMLHttpRequest) { // Mozilla, Safari,...
	 	http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) {
			// set type accordingly to anticipated content type
			//http_request.overrideMimeType('text/xml');
			http_request.overrideMimeType('text/html');
		}
	} else if (window.ActiveXObject) { // IE
		try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}
	if (!http_request) {
		alert('Update your browser');
		return false;
	}
	http_request.onreadystatechange = callback;
	http_request.open('POST', url, true);
	http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http_request.setRequestHeader("Content-length", parameters.length);
	http_request.setRequestHeader("Connection", "close");
	http_request.send(parameters);
}

function winOpen(goto,height,width){
	window.open(goto,null,"height="+height+",width="+width+",status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes");
}




var isInternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
// Handle all the FSCommand messages in a Flash movie.
function babeFlv_DoFSCommand(command, args) {
	var babeFlvObj = isInternetExplorer ? document.all.babeFlv : document.babeFlv;
	hideDiv();
}





function writeBabe(babe, width, height) {
	
	var shown = readCookie("showModel");
	
	var objhtml = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" id="babeFlv" width="'+width+'" height="'+height+'" align="middle"><param name="allowScriptAccess" value="sameDomain" /><param name="movie" value="/includes/swf/'+babe+'.swf" /><param name="quality" value="high" /><param name="wmode" value="transparent" /><param name="bgcolor" value="#ffffff" /><embed src="/includes/swf/'+babe+'.swf" quality="high" wmode="transparent" bgcolor="#ffffff" width="'+width+'" height="'+height+'" swLiveConnect="true" id="babeFlv" name="babeFlv" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>';
	
	if (!shown || 1) document.getElementById("babeDiv").innerHTML = objhtml;
	setCookie("showModel",true);
	return;
	
}

function setCookie(name,value) {
	var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function setMaxLength() {
	var x = document.getElementsByTagName('textarea');
	var counter = document.createElement('div');
	counter.className = 'counter';
	for (var i=0;i<x.length;i++) {
		if (x[i].getAttribute('maxlength')) {
			var counterClone = counter.cloneNode(true);
			counterClone.relatedElement = x[i];
			counterClone.innerHTML = '<span>0</span>/'+x[i].getAttribute('maxlength');
			x[i].parentNode.insertBefore(counterClone,x[i].nextSibling);
			x[i].relatedElement = counterClone.getElementsByTagName('span')[0];

			x[i].onkeyup = x[i].onchange = checkMaxLength;
			x[i].onkeyup();
		}
	}
}

function checkMaxLength() {
	var maxLength = this.getAttribute('maxlength');
	var currentLength = this.value.length;
	if (currentLength > maxLength) {
		this.value = this.value.substr(0,maxLength);
	} else {
		//this.relatedElement.className = '';
	}
	this.relatedElement.firstChild.nodeValue = currentLength;
	// not innerHTML
}

