


function include(filename)
{
	var head = document.getElementsByTagName('head')[0];
	
	script = document.createElement('script');
	script.src = filename;
	script.type = 'text/javascript';
	
	head.appendChild(script)
}


// Get the HTTP Object
function getHTTPObject(){
if (window.ActiveXObject) return new ActiveXObject("Microsoft.XMLHTTP");
else if (window.XMLHttpRequest) return new XMLHttpRequest();
else {alert("Your browser does not support AJAX."); return null;}
}



function setHTMLwithScript(element, text) {
	var index = -1;
	index =text.lastIndexOf('<!--++++');	
	if (index != -1) {
		html = text.slice(0, index-1);
		script = text.slice(index+11);
		if (html.length > 0) element.innerHTML = html;
		//alert(script);
		if (script.length > 0) eval(script);
	} else {
		element.innerHTML = text;
	}
}

// Change the value of the outputText field

function setMiniHtml(){
	myID = document.getElementById('mini');	
	if(httpObject.readyState == 4){
	if(httpObject.status == 200) setHTMLwithScript(myID,	 httpObject.responseText);		
	httpObject = null;
	}
}
function setMessageHtml(){
	myID = document.getElementById('message');
	if(httpObject.readyState == 4){ 
	if(httpObject.status == 200) setHTMLwithScript(myID,	 httpObject.responseText);
	//document.getElementById('message').innerHTML = httpObject.responseText;
	httpObject = null;
	}
}
function setEmailHtml(){
	myID = document.getElementById('message');
	
	if(httpObject.readyState == 4){ 
	if(httpObject.status == 200) setHTMLwithScript(myID,	 httpObject.responseText);
	//document.getElementById('message').innerHTML = httpObject.responseText;
	httpObject = null;
	}
}
function setPhoogleHtml(){
	myID = document.getElementById('phoogle');
	if(httpObject.readyState == 4){ 
	if(httpObject.status == 200) setHTMLwithScript(myID,	 httpObject.responseText);
	//document.getElementById('message').innerHTML = httpObject.responseText;
	httpObject = null;
	setTimeout('showmap()', 1000);
	}
}
function setPhoogleHtmlLoading() {
	myID = document.getElementById('phoogle');
	html =  '<table width=' + myID.offsetWidth + ' height=' + myID.offsetHeight  + '><tr valign="center"><td align="center"><img src="http://radio.trannyradio.com/images/ajax-loader.gif"><br>Loading</td></tr></table>';
	myID.innerHTML = html;
}
function setChatHtml(){
	myID = document.getElementById('chat');
	if(httpObject.readyState == 4){
	if(httpObject.status == 200) setHTMLwithScript(myID,	 httpObject.responseText);
	httpObject = null;
	}
}
function setProfileHtml(){
	myID = document.getElementById('profile');
	if(httpObject.readyState == 4){
	if(httpObject.status == 200) setHTMLwithScript(myID,	 httpObject.responseText);
	httpObject = null;
	} 
}
function setProfileHtmlLoading() {
	myID = document.getElementById('profile');
	html = '<table width=' + myID.offsetWidth + ' height=' + myID.offsetHeight  + '><tr valign="center"><td align="center"><img src="http://radio.trannyradio.com/images/ajax-loader.gif"><br>Loading</td></tr></table>';
	myID.innerHTML = html;
}


function setAjaxHtml(target){
	myID = document.getElementById(target);	
	if(httpObject.readyState == 4){
	if(httpObject.status == 200) setHTMLwithScript(myID,	 httpObject.responseText);
	httpObject = null;
	}
	
}
// Implement business logic

function getMiniHtml(id, mode){
	var delay = function() { getMiniHtml(id,mode); };
	if  (httpObject != null) { setTimeout(delay,500);return;}
httpObject = getHTTPObject();
if (httpObject != null) {
	httpObject.open("GET", "ajax.php?id=" + id + "&cmd=mini&m=" + mode + "&w=400&h=300", true);
	httpObject.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");	
	httpObject.send(null);
	httpObject.onreadystatechange = setMiniHtml;
	}
}

function getProfileHtml(id){
	var delay = function() { getProfileHtml(id); };
	if  (httpObject != null) { setTimeout(delay,500);return;}
httpObject = getHTTPObject();
if (httpObject != null) {
	setProfileHtmlLoading();
	httpObject.open("GET", "ajax.php?id=" + id + "&cmd=showProfile&w=500&h=300", true);
	httpObject.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");	
	httpObject.send(null);
	httpObject.onreadystatechange = setProfileHtml;
	}
}

function getAlbumHtml(id, album){
	var delay = function() { getAlbumHtml(id, album); };
	if  (httpObject != null) { setTimeout(delay,500);return;}
httpObject = getHTTPObject();
if (httpObject != null) {
	setProfileHtmlLoading();
	httpObject.open("GET", "ajax.php?id=" + id + "&cmd=album&w=500&h=600&a=" + album, true);
	httpObject.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");	
	httpObject.send(null);
	httpObject.onreadystatechange = setProfileHtml;
	}
}

function getBlogHtml(id, command, a,b,c,d){
	if  (!a) a=0;
	if  (!b) b=0;
	if  (!c) c=0;
	if  (!d) d=0;
	if (!command) command="blog";
	var delay = function() { getBlogHtml(id, command,a,b,c,d); };
	if  (httpObject != null) { setTimeout(delay,500);return;}
httpObject = getHTTPObject();
if (httpObject != null) {
	setProfileHtmlLoading();
	httpObject.open("GET", "ajax.php?id=" + id + "&cmd=" + command + "&a=" + a + "&b=" + b + "&c=" + c + "&d=" + d , true);
	httpObject.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");	
	httpObject.send(null);
	httpObject.onreadystatechange = setProfileHtml;
	}
}

function getBlogPostHtml(id, command, a){
	if  (!a) a='';
	if  (!id) id=-1;
	if (!command) command="makePost";
	var delay = function() { getBlogHtml(id, command,a); };
	if  (httpObject != null) { setTimeout(delay,500);return;}
httpObject = getHTTPObject();
if (httpObject != null) {
	setProfileHtmlLoading();
	httpObject.open("POST", "ajax.php", true);
	httpObject.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	httpObject.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");	
	//alert("Sending" + a);
	httpObject.send("id=" + id + "&cmd=" + command + a);
	httpObject.onreadystatechange = setProfileHtml;
	}
}

function getManageHtml(id,a,b){
//if  (httpObject != null) { setTimeout('getManageHtml(' + id + ',' + a + ',' + b + ')',500);return;}
//httpObject = getHTTPObject();
//if (httpObject != null) {
	simulateInWindow("ajax.php?id=" + id + "&a=" + a + "&b=" + b + "&cmd=manage&w=400");
//	httpObject.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
//	httpObject.send(null);
//	httpObject.onreadystatechange = setMessageHtml;
//	}
}

function getSubmitEmailHtml(id,a,b,c,d){
//if  (httpObject != null) { setTimeout('getSubmitEmailHtml(' + id + ',' + a + ',' + b + ',' + c + ',' + d + ')',500);return;}
//httpObject = getHTTPObject();
//if (httpObject != null) {
//	httpObject.open("GET", "ajax.php?id=" + id + "&a=" + a + "&b=" + b + "&c=" + c + "&d=" + d + "&cmd=submitEmail&w=500", true);
//	httpObject.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
//	httpObject.send(null);
//	httpObject.onreadystatechange = setEmailHtml;
//	}
	simulateInWindow("ajax.php?id=" + id + "&a=" + a + "&b=" + b + "&c=" + c + "&d=" + d + "&cmd=submitEmail&w=500");
}


function getChatHtml(id){
	if (!id) id = 0;
	var delay = function() { getChatHtml(id); };
	if  (httpObject != null) { setTimeout(delay,500);return;}
httpObject = getHTTPObject();
if (httpObject != null) {
	httpObject.open("GET", "ajax.php?cmd=chat&w=400&id=" + id, true);
	httpObject.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");	
	httpObject.send(null);
	httpObject.onreadystatechange = setChatHtml;
	}
	
}

function getPhoogleHtml(){
	var delay = function() { getPhoogleHtml(); };
	if  (httpObject != null) { setTimeout(delay,500);return;}
httpObject = getHTTPObject();
if (httpObject != null) {
	setPhoogleHtmlLoading();
	httpObject.open("GET", "ajax.php?cmd=phoogle&w=400&h=300", true);
	httpObject.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");	
	httpObject.send(null);
	httpObject.onreadystatechange = setPhoogleHtml;
	}
	
}



var ajaxTarget;
function getAjaxHtml(script, target, width, a, f, loading, otherArgs, postArgs){
	if (!a) var a=0;
	if (!f) var f = 0;
	if (typeof(postArgs)=='undefined') {var postArgs="";}
	if (typeof(otherArgs)=='undefined') {var otherArgs="";}
	if (typeof(loading)=='undefined') var loading='yes';
	var delay = function() { getAjaxHtml(script, target, width, a, f,loading, otherArgs, postArgs); };
	if  (httpObject != null) { setTimeout(delay,500);return;}
	//alert("Testing - Sorry " + script + " a:" + a);
httpObject = getHTTPObject();
if (httpObject != null) {
	myID = document.getElementById(target); 
	if (loading == 'yes') {
		html =  '<table width=' + myID.offsetWidth + ' height=' + myID.offsetHeight  + '><tr valign="center"><td align="center"><img src="http://radio.trannyradio.com/images/ajax-loader.gif"><br>Loading</td></tr></table>';
		myID.innerHTML = html;
	}
	if (postArgs == "") {
		httpObject.open("GET", "ajax.php?cmd=" + script + "&w=" + width + "&a=" + a + "&f=" + f + otherArgs, true);
		httpObject.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");	
		httpObject.send(null);
	} else {
		httpObject.open("POST", "ajax.php" , true);
		httpObject.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		httpObject.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");	
		httpObject.send("cmd=" + script + postArgs);
	}
	ajaxTarget = target;
	httpObject.onreadystatechange = function(){
		myID = document.getElementById(ajaxTarget);
    	if(httpObject.readyState == 4){
			if(httpObject.status == 200) {
				setHTMLwithScript(myID,	 httpObject.responseText);
			}
			httpObject = null;
		}		
	}
}
}


function checkEmail(sender1,sender2,subject,message,user_id,hide)
{
		//alert("Checking " + sender1 + ":" + sender2 + ":" + subject + ":" + message + ":" + user_id + ":" + hide);
	if (sender1 != "" && sender2 != sender1) {
		alert("The two email addresses you entered are different");
	} else if (subject.length < 2) {
		alert("Your email has no subject!");
	} else if (message.length < 4) {
		alert("You haven't entered a message to send");
	} else 	if ((sender2==null)||(sender2=="")){
		alert("Please enter an email address");
	} else if (sender2==false){
		alert("Please enter a valid email address");
	} else {
		//alert("Email OK to send");
		return true;
//getSubmitEmailHtml(user_id,sender2,subject,message,"indexGirls.php");
	}
 return false;
}


function submitEmail(sender1,sender2,subject,message,user_id,hide)
{
	if (sender1 != "" && sender2 != sender1) {
		alert("The two email addresses you entered are different");
	} else if (subject.length < 2) {
		alert("Your email has no subjectXX");
	} else if (message.length < 4) {
		alert("You haven't entered a message to send");
	} else 	if ((sender2==null)||(sender2=="")){
		alert("Please enter an email address")
	} else if (sender2==false){
		alert("Please enter a valid email address")
		return false
	} else {
 		hm('premail'); 
		if (hide) {
			simulateInWindow("ajax.php?to=" + user_id + "&sender=" + sender2 + "&subject=" + subject + "&message=" + message +  "&cmd=submitEmail&w=500");
		} else {
			simulateInWindow("ajax.php?to=" + user_id + "&sender=" + sender2 + "&subject=" + subject + "&message=" + message  + "&hide=1&cmd=submitEmail&w=500");		}

//getSubmitEmailHtml(user_id,sender2,subject,message,"indexGirls.php");
	}
 return false;
}


// And to run ajax in simulation mode in a pop-up window....
function simulateInWindow(url)
{
	window.open(url,"simulate", "menubar=no,width=10,height=10,toolbar=no");	
}

function setMessageText(message) 
{
	document.getElementById('messageBox').innerHTML  = message;
	setTimeout('setMessageText(" ")', 10000);
}

function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    return false
		 }

 		 return true					
	}


// ====================================================================
//       URLEncode and URLDecode functions
//
// Copyright Albion Research Ltd. 2002
// http://www.albionresearch.com/
//
// You may copy these functions providing that 
// (a) you leave this copyright notice intact, and 
// (b) if you use these functions on a publicly accessible
//     web site you include a credit somewhere on the web site 
//     with a link back to http://www.albionresearch.com/
//
// If you find or fix any bugs, please let us know at albionresearch.com
//
// SpecialThanks to Neelesh Thakur for being the first to
// report a bug in URLDecode() - now fixed 2003-02-19.
// And thanks to everyone else who has provided comments and suggestions.
// ====================================================================

URLEncode = function( plaintext)
{
	// The Javascript escape and unescape functions do not correspond
	// with what browsers actually do...
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";
	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
	    if (ch == " ") {
		    encoded += "+";				// x-www-urlencoded, rather than %20
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
			    alert( "Unicode Character '" 
                        + ch 
                        + "' cannot be encoded using standard URL encoding.\n" +
				          "(URL encoding only supports 8-bit characters.)\n" +
						  "A space (+) will be substituted." );
				encoded += "+";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	} // for

	return encoded;
};

form2ajax = function(me, target)
{
	//var x=document.getElementById("post");
	//alert(target);
	var x = me;
	var params = '';
	for (var i=0;i<x.length;i++)
	{
		if (x.elements[i].name == 'helpbox' ) continue;
		var type = x.elements[i].type;
		if (type=='text' || type=='hidden' || type=='submit' || type=='radio' || type=='textarea'|| type=='select-one') {
			params += '&';
			params += x.elements[i].name + '=' + URLEncode(x.elements[i].value);
		}
	}
	//alert("TESTING "  + target + "=" + params);
	switch (target) {
	 case "admin/search": 
		getAjaxHtml(target,"lefthandside",600,"admin",0,"yes",params);
		break;
	 case "newGirl": 
		getAjaxHtml(target,"lefthandside",600,"admin",0,"yes",params);
		break;		
	 case "showProfile":
		getAjaxHtml(target,"righthandside",600,"admin",0,"yes",params);
		break;
	 case "profileEdit":
	   //alert(target);
		getAjaxHtml(target,"profile",600,"",0,"yes","",params);
		break;
	 case "attendee":
		getAjaxHtml(target,"attendee",600,"",0,"yes",params);
		break;
	default:
		getBlogPostHtml(0, 'makePost', params);
	}

	return false;
}
	
