// JavaScript Document
function check_agreement(){
	var elem=document.getElementById('acceptance_agreement');
	if (elem.checked) {
		window.location = "aboutus.html";
	} else {
		alert('You must agree the conditions in order to continue');
	}
}

function LoadDiv(pagename,parameters,div_name){
    var elem=document.getElementById(div_name);
    xmlreqGET(pagename+parameters,div_name);
}

function OpenNewWindow(address){
	window.open(address,'referer from 1stEscortDirectory');
}

function URLEncode(plaintext)
{
	var SAFECHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_.!~*'()";
	var HEX = "0123456789ABCDEF";
	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
	    if (ch == " ") {
		    encoded += "+";
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
				encoded += "+";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	}
	return encoded;
}

function doPostForm(){
	var str_write='';

	str_write+='?i_age='+URLEncode(document.getElementById('i_age').value)+'&';
	str_write+='i_model='+document.getElementById('i_model').options[document.getElementById('i_model').selectedIndex].value+'&';
	str_write+='i_period='+document.getElementById('i_period').options[document.getElementById('i_period').selectedIndex].value+'&';
	str_write+='i_time='+document.getElementById('i_time').options[document.getElementById('i_time').selectedIndex].value+'&';
	str_write+='i_day='+document.getElementById('i_day').options[document.getElementById('i_day').selectedIndex].value+'&';
	str_write+='i_month='+document.getElementById('i_month').options[document.getElementById('i_month').selectedIndex].value+'&';
	str_write+='i_location='+document.getElementById('i_location').options[document.getElementById('i_location').selectedIndex].value+'&';
	str_write+='i_contactvia='+document.getElementById('i_contactvia').options[document.getElementById('i_contactvia').selectedIndex].value+'&';
	str_write+='i_timetocall='+document.getElementById('i_timetocall').options[document.getElementById('i_timetocall').selectedIndex].value+'&';
	str_write+='i_name='+URLEncode(document.getElementById('i_name').value)+'&';
	str_write+='i_address='+URLEncode(document.getElementById('i_address').value)+'&';
	str_write+='i_email='+URLEncode(document.getElementById('i_email').value)+'&';
	str_write+='i_1stphone='+URLEncode(document.getElementById('i_1stphone').value)+'&';
	str_write+='i_2ndphone='+URLEncode(document.getElementById('i_2ndphone').value)+'&';
	str_write+='i_comment='+URLEncode(document.getElementById('i_comment').value);
	LoadDiv('zmail.php',str_write,'form_result');
}

//////////////////////////////////////////////////////////////////
///   Begin of the AJAX access - 2nd method - multi requests   ///
//////////////////////////////////////////////////////////////////

var xmlreqs = new Array();

function CXMLReq(freed) {
	this.freed = freed;
	this.xmlhttp = false;
	if (window.XMLHttpRequest) {
		this.xmlhttp = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
}

function xmlreqGET(url, div_id) {
	var pos = -1;
	for (var i=0; i<xmlreqs.length; i++) {
		if (xmlreqs[i].freed == 1) { pos = i; break; }
	}
	if (pos == -1) { pos = xmlreqs.length; xmlreqs[pos] = new CXMLReq(1); }
	if (xmlreqs[pos].xmlhttp) {
		xmlreqs[pos].freed = 0;
		xmlreqs[pos].xmlhttp.open("GET",url,true);
		xmlreqs[pos].xmlhttp.onreadystatechange = function() {
			if (typeof(xmlhttpChange) != 'undefined') { xmlhttpChange(pos,div_id); }
		}
		if (window.XMLHttpRequest) {
			xmlreqs[pos].xmlhttp.send(null);
		} else if (window.ActiveXObject) {
			xmlreqs[pos].xmlhttp.send();
		}
	}
}

function xmlreqGET_sync(url, div_id) {
	var pos = -1;
	for (var i=0; i<xmlreqs.length; i++) {
		if (xmlreqs[i].freed == 1) { pos = i; break; }
	}
	if (pos == -1) { pos = xmlreqs.length; xmlreqs[pos] = new CXMLReq(1); }
	if (xmlreqs[pos].xmlhttp) {
		xmlreqs[pos].freed = 0;
		xmlreqs[pos].xmlhttp.open("GET",url,false);
		xmlreqs[pos].xmlhttp.onreadystatechange = function() {
			if (typeof(xmlhttpChange) != 'undefined') { xmlhttpChange(pos,div_id); }
		}
		if (window.XMLHttpRequest) {
			xmlreqs[pos].xmlhttp.send(null);
		} else if (window.ActiveXObject) {
			xmlreqs[pos].xmlhttp.send();
		}
	}
}

function xmlreqPOST(url,data, div_id) {
	var pos = -1;
	for (var i=0; i<xmlreqs.length; i++) {
		if (xmlreqs[i].freed == 1) { pos = i; break; }
	}
	if (pos == -1) { pos = xmlreqs.length; xmlreqs[pos] = new CXMLReq(1); }
	if (xmlreqs[pos].xmlhttp) {
		xmlreqs[pos].freed = 0;
		xmlreqs[pos].xmlhttp.open("POST",url,true);
		xmlreqs[pos].xmlhttp.onreadystatechange = function() {
			if (typeof(xmlhttpChange) != 'undefined') { xmlhttpChange(pos, div_id); }
		}
		xmlreqs[pos].xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		xmlreqs[pos].xmlhttp.send(data);
	}
}

function xmlhttpChange(pos, div_id) {
	if (typeof(xmlreqs[pos]) != 'undefined' && xmlreqs[pos].freed == 0 && xmlreqs[pos].xmlhttp.readyState == 4) {
		if (xmlreqs[pos].xmlhttp.status == 200 || xmlreqs[pos].xmlhttp.status == 304) {
			handle_response(xmlreqs[pos].xmlhttp.responseText, div_id);
		} else {
			handle_error(div_id);
		}
		xmlreqs[pos].freed = 1;
	} else {
	    document.getElementById(div_id).innerHTML='<div align="center"><img src="images/checking.gif" border=0 alt="Loading Page..."></div>';
	}
}

function handle_response(TheResponse, div_id){
	var stripped = TheResponse;
	document.getElementById(div_id).innerHTML='load dates';
/*	try {
	document.getElementById(div_id).innerHTML='';
*/	document.getElementById(div_id).innerHTML=stripped;
/*	} catch(e) {
	document.getElementById(div_id).innerHTML='load failed';
	}
*/
}

function handle_error(div_id){
    document.getElementById(div_id).innerHTML='Could not load page...';
}

function StripSlashes(str) {
	str=str.replace(/\\'/g,'\'');
	str=str.replace(/\\"/g,'"');
	str=str.replace(/\\\\/g,'\\');
	str=str.replace(/\\0/g,'\0');
	return str;
}

//////////////////////////////////////////////////////////////////
///    End of the AJAX access - 2nd method - multi requests    ///
//////////////////////////////////////////////////////////////////

function OpenEscortDetails(id){
	LoadDiv('escortdet.php','?id='+id,'mainpage');
}

function EscortChangePic(divname, escname, id){
	elem=document.getElementById(divname);
	elem.innerHTML='<img src="pictures/'+escname+id+'.jpg" alt="Escort picture" />';
}