///////////////////////////////////////////////////////////////////////////
//<!-- /AJAX STUFF 
//Browser Support Code
function ajaxFunction(funct,username){
	var ajaxRequest;  // The variable that makes Ajax possible!
	
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
if(funct == "changePass"){
//alert(funct);
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			var update_return = document.getElementById('changed_pass').innerHTML = "Password changed | ";
			var close_update = document.getElementById('pass_change');
			close_update.style.display = "none";
		}
	}
	var newPass = document.getElementById('newPass').value;
	var queryString = "?newPass=" + newPass + "&username=" + username;
	ajaxRequest.open("GET", "ajaxFunct.php" + queryString, true);
	ajaxRequest.send(null); 
}
if(funct == "viewer"){
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
		Effect.toggle('viewer', 'blind', {duration: 0.5 });
			var dVid = document.getElementById('Vholder');
			dVid.innerHTML=ajaxRequest.responseText;
		}
	}
	ajaxRequest.open("GET", "ajaxFunct.php?viewer=1&id="+username, true);
	ajaxRequest.send(null); 
}//viewer
if(funct == "notAdminViewer"){
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
		Effect.toggle('viewer', 'blind', {duration: 0.5 });
			var dVid = document.getElementById('Vholder');
			dVid.innerHTML=ajaxRequest.responseText;
		}
	}
	ajaxRequest.open("GET", "login/ajaxFunct.php?notAdmin=1&viewer=1&id="+username, true);
	ajaxRequest.send(null); 
}//notAdminViewer
if(funct == "cycleAdmin"){
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			var dVid = document.getElementById('Vholder');
			dVid.innerHTML=ajaxRequest.responseText;
		}
	}
	ajaxRequest.open("GET", "login/ajaxFunct.php?notAdmin=1&viewer=1&id="+username, true);
	ajaxRequest.send(null); 
		
}//cycleadmin
if(funct == "cycle"){
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			var dVid = document.getElementById('Vholder');
			dVid.innerHTML=ajaxRequest.responseText;
		}
	}
	ajaxRequest.open("GET", "ajaxFunct.php?viewer=1&id="+username, true);
	ajaxRequest.send(null); 
		
}//cycle
if(funct == "updateViewer"){
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			document.getElementById('titleUpdate'+username).innerHTML=Tinput;
		}
	}
	var Tinput = document.getElementById('Tinput'+username).value;
	var Dinput = document.getElementById('Dinput'+username).value;
	ajaxRequest.open("GET", "ajaxFunct.php?updateViewer=1&Tinput="+Tinput+"&Dinput="+Dinput+"&id="+username, true);
	ajaxRequest.send(null); 
		
}//updateViewer
if(funct == "viewerDelete"){
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			document.getElementById('viewerThumb'+username).style.display="none";
		}
	}
var con = confirm('are you sure you want to delete this entry?');
		if(con==true){
	ajaxRequest.open("GET", "ajaxFunct.php?viewerDelete=1&id="+username, true);
	ajaxRequest.send(null); 
}		
}//updateViewer
if(funct == "AimageDelete"){
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			document.getElementById('SBimage').style.display="none";
			document.getElementById('SBimage1').style.display="none";
			document.getElementById('SBaltText').innerHTML="";
			document.getElementById('SBbody').innerHTML="";
			document.getElementById('SBbody1').innerHTML="";
		}
	}
var con = confirm('are you sure you want to delete this entry?');
		if(con==true){
	ajaxRequest.open("GET", "ajaxFunct.php?AimageDelete=1&id="+username, true);
	ajaxRequest.send(null); 
}		
}//AimageDelete
if(funct == "linkDelete"){
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			document.getElementById('link'+username).style.display="none";
			document.getElementById('content').style.marginRight="10px";
		}
	}
var con = confirm('are you sure you want to delete this entry?');
		if(con==true){
	ajaxRequest.open("GET", "ajaxFunct.php?linkDelete=1&id="+username, true);
	ajaxRequest.send(null); 
}		
}//linkDelete
if(funct == "entryDelete"){
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			document.getElementById('entry'+username).style.display="none";
		}
	}
var con = confirm('are you sure you want to delete this entry?');
		if(con==true){
	var pageName = document.getElementById('pageName').value;
	ajaxRequest.open("GET", "ajaxFunct.php?entryDelete=1&pageName="+pageName+"&id="+username, true);
	ajaxRequest.send(null); 
}		
}//entryDelete
if(funct == "sidebannerIO"){
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			t('SideWrapper');
		}
	}
	ajaxRequest.open("GET", "ajaxFunct.php?sbIO=1&page="+username, true);
	ajaxRequest.send(null); 
}//sidebannerIO
if(funct == "send"){
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			if(ajaxRequest.responseText!=""){
				document.getElementById('errorSpan').innerHTML=ajaxRequest.responseText;
				new Effect.Morph('errorSpan', {
					style: 'background:#980000; color:#fff;', // CSS Properties
					duration: 0.3 // Core Effect properties
				});
				new Effect.Morph('errorSpan', {
					style: 'background:#fff;color:#000;', // CSS Properties
					duration: 0.3, delay: 0.5 // Core Effect properties
				});
			} else {
			document.getElementById('contact').style.display="none";
			document.getElementById('errorSpan').style.display="none";
			document.getElementById('thanks').style.display="";
		}//validation
		}
	}
	var n = document.getElementById('name').value;
	var p = document.getElementById('phone').value;
	var e = document.getElementById('email').value;
	var c = document.getElementById('comments').value;
	n = urlencode(n);
	p = urlencode(p);
	e = urlencode(e);
	c = urlencode(c);
	var query = "&n="+n+"&p="+p+"&e="+e+"&c="+c;
	//alert(query);
	ajaxRequest.open("GET", "login/ajaxFunct.php?send=1"+query, true);
	ajaxRequest.send(null); 
		
}//send
}//end master ajaxFunction
// END AJAX-->
function urlencode(str) {
return escape(str).replace('+', '%2B').replace('%20', '+').replace('*', '%2A').replace('/', '%2F').replace('@', '%40');
}
///////////////////////////////////////////////////////////////////////////
function OpenComments (c){
   window.open(c,'comments','width=550,height=510,scrollbars=yes,status=yes,resizable=yes');
}

///////////////////////////////////////////////////////////////////////////
function toggle_sub(id, opt){
	var Element = document.getElementById(id);
	if(opt == 'open')
		Element.style.display = "";
	else if(opt == 'close')
		Element.style.display = "none";
}
///////////////////////////////////////////////////////////////////////////
function t(id){
	var i = document.getElementById(id);
		if(i.style.display==""){
			i.style.display="none";
		}else if(i.style.display=="none"){
			i.style.display="";
		}
}
///////////////////////////////////////////////////////////////////////////
shortcut.add("Ctrl+shift+l",function() {
	var l_login = document.getElementById('l_login');
		l_login.style.display = "";
		//get the focus
		document.getElementById('myusername').focus();
},{
	'type':'keydown',
	'propagate':true,
	'target':document
});
///////////////////////////////////////////////////////////////////////////
function preview(io){
	if (io=="ON"){
	var p = document.getElementById('preview');
	var c = document.getElementById('content');
		c.style.display = "none";
		p.style.display = "";
	//open the "you need to save box"
	var s = document.getElementById('l_needToSave');
		s.style.display = "";
		document.getElementById('switch').innerHTML = "<a class=\"l_options\" onclick=\"preview('OFF')\" href='#'>Return to edit</a> |" 
	}else if (io=="OFF"){
	var p = document.getElementById('preview');
	var c = document.getElementById('content');
		c.style.display = "";
		p.style.display = "none";
		document.getElementById('switch').innerHTML = "<a class=\"l_options\" onclick=\"preview('ON')\" href='#'>Preview this page</a> |" 
	}
}
///////////////////////////////////////////////////////////////////////////
function clear_focused(id){
	var clear_it_out = document.getElementById(id);
	if(clear_it_out.value=="Name"||clear_it_out.value=="Your comments"||clear_it_out.value=="E-mail (only visible to author)"||clear_it_out.value=="New Title"){
		clear_it_out.value="";
		clear_it_out.style.color = "grey";
		clear_it_out.style.fontStyle= "italic";
		}
		clear_it_out.style.color = "";
		clear_it_out.style.fontStyle= "";
}

