// (c) daa
function toggleHTML(string){
	if(	string.toLowerCase().indexOf("&amp;")<0
	&&	string.toLowerCase().indexOf("&lt;")<0
	&&	string.toLowerCase().indexOf("&gt;")<0
	&&	string.toLowerCase().indexOf("&quot;")<0
	&&	string.toLowerCase().indexOf("&#039;")<0
	)
	{
	//	alert('ENcoding...');
		return string	//encode
		.replace(/&/g, "&amp;")		//first thing to do
		.replace(/</g, "&lt;")
		.replace(/>/g, "&gt;")
		.replace(/"/g, "&quot;")
		.replace(/'/g, "&#039;");
		}
	else
	{
	//	alert('DEcoding...');
		return string	//decode
		.replace(/&lt;/g, "<")
		.replace(/&gt;/g, ">")
		.replace(/&quot;/g, "\"")
		.replace(/&#039;/g, "'")
		.replace(/&amp;/g, "&");	//last thing to do
		}
	}
function toggleclass(objID,class1,class2){
	if(document.getElementById(objID)){
		obj=document.getElementById(objID);
		if(!obj.Tclass) Fclass(obj);
		if (obj.Cclass(class1))	{obj.Aclass(class2);obj.Rclass(class1);}
		else			{obj.Aclass(class1);obj.Rclass(class2);}
		}
	}
function Aclass(className){ //Add
	// check if this class does exist already!
	if(this.Cclass(className)) return true;
	// ifnot, proceed adding this className
	classNames=this.className.split(" ");
	classNames[classNames.length]=className;
	this.className=classNames.join(" ");
	}
function Rclass(className){ //Remove
	// check if this class is missing already!
	if(!this.Cclass(className)) return true;
	// ifnot, proced removing this class
	classNames=this.className.split(" ");
	for(i in classNames)
		if(classNames[i]==className)
			classNames[i]='';
	this.className=classNames.join(" ");
	}
function Cclass(className){ //Check
	classNames=this.className.split(" ");
	var i; for(i in classNames)
		if(classNames[i]==className)
			return true;
	return false;
	}
function Tclass(className){ //Toggle
	if(this.Cclass(className))
		this.Rclass(className);
	else	this.Aclass(className);
	}
function Fclass(obj){//assign class functions (ARCT)
	obj.Aclass=Aclass;
	obj.Rclass=Rclass;
	obj.Cclass=Cclass;
	obj.Tclass=Tclass;
	}

function switchFormAction(input){	//this function must be called by a switcher input
	if(!(form=input.parentNode)) alert('can not determine parent node');	//let's say
	while(form.tagName.toLowerCase()!='form')
		if(form.tagName.toLowerCase()=='body') {alert('reached to body');return;} // no form to act on
		else form=form.parentNode; //go upwards
	//disable all existing action inputs
	var actions=form.getElementsByName('action');
	alert(actions.length+' action inputs found');
	for(var i=0;i<actions.length;i++)
		if(actions[i]==input)	actions[i].disabled=false; // except this one
		else			actions[i].disabled=true;
	return false;
	}
//
function defHTMLhead(title,charset){
	var defHTMLhead='<html></head>';
	charset = charset || 'iso-8859-2';
	defHTMLhead+='<meta http-equiv="Content-Type" content="text/html; charset='+charset+'" />';
	var d = new Date();
	title = title || 'SAAD';
	defHTMLhead+='<title>'+title+' - '+d.getFullYear()+d.getMonth()+d.getDate()+'-'+d.getHours()+d.getMinutes()+d.getSeconds()+'</title>';
	defHTMLhead+='<link media="all"		type="text/css"        rel="stylesheet"    href="css.css" />';
	defHTMLhead+='<link media="screen"	type="text/css"        rel="stylesheet"    href="css_screen.css" />';
	defHTMLhead+='<link media="print"	type="text/css"        rel="stylesheet"    href="css_print.css" />';
	defHTMLhead+='</head><body>';
	return defHTMLhead;
	}
function defHTMLfoot(){ return '</body></html>'; }
function separate(content){
	var separate=window.open();
	separate.document.open();
	separate.document.write(defHTMLhead());
	separate.document.write(content);
	separate.document.write(defHTMLfoot());
	separate.document.close();
	}
//Keyboard
var keyboard_target;
var keyboard_container;
var keyboard_OFFtimer;
function keyboard(value){
	if(!keyboard_target) {window.status='keyboard: no target';return false;}
	switch(value){
		case "<":	keyboard_target.value=keyboard_target.value.substring(0,keyboard_target.value.length-1); break;
		default :	keyboard_target.value+=value;
				keyboard_target.scrollTop = 999999;
		}
	
	/**///move cursor to the end of text/textarea
	/**/	if(typeof keyboard_target.selectionStart == "number") {
	/**/		  keyboard_target.selectionStart = keyboard_target.selectionEnd = keyboard_target.value.length;
	/**/		  }
	/**/	else if (typeof keyboard_target.createTextRange != "undefined") {
	/**/		keyboard_target.focus();
	/**/		var range = keyboard_target.createTextRange();
	/**/		range.collapse(false);
	/**/		range.select();
	/**/		}
	
	clearTimeout(keyboard_OFFtimer);
	keyboard_OFFtimer=setTimeout('keyboardOFF()',10000);
	}
function keyboardON(target,container,type){
	//deal with target
	if(!target) {window.status='keyboardON: no target';return false;}
	keyboard_target=target;
	//deal with container
	keyboard_container=container;
	if(!keyboard_container) {window.status='keyboardON: no keyboard_container';return false;}
	//do the do
	AJAXquery(keyboard_container,'keyboard.php?type='+type);
	//reset timeout
	clearTimeout(keyboard_OFFtimer);
	keyboard_OFFtimer=setTimeout('keyboardOFF()',10000);
	}
function keyboardOFF(){
	keyboard_target=false;
	keyboard_container.innerHTML='';
	}
//AJAX
function AJAXquery(target, address, POST){
	if(!target) {window.status='AJAXquery: no target';return false;}
						// code for IE7+, Firefox, Chrome, Opera, Safari
									// code for IE6, IE5
	var xmlhttp= window.XMLHttpRequest ?	new XMLHttpRequest() :	new ActiveXObject("Microsoft.XMLHTTP");
	var method= POST ? "POST" : "GET";
	xmlhttp.onreadystatechange=function(){
		if(xmlhttp.readyState==4 && xmlhttp.status==200){
			target.innerHTML=xmlhttp.responseText;
			}
  		}
	xmlhttp.open(method,address,true);
	xmlhttp.send(POST);
	}
var slappers=new Array();
function slapImage(id){
	var EXsrc=document.getElementById(id).src.split("&slap=");
	var d = new Date();
	document.getElementById(id).src=EXsrc[0]+"&slap="+d.getTime();
	}
function addSlapper(id,interval){
	if(document.getElementById("Slapper_"+id))		return false;		//we already have a slapper for that ID
	var image=document.getElementById(id);	if(!image)	return false;
	interval = interval ? interval : 1000 ;
	var oImg=document.createElement("img");
	
	oImg.setAttribute('src', image.src);
	oImg.setAttribute('id', "Slapper_"+id);
	oImg.setAttribute('style', "display:none");
	oImg.setAttribute('onload', "document.getElementById('"+id+"').src=this.src");
	document.body.appendChild(oImg);
	slappers[id]=setInterval("slapImage('Slapper_"+id+"');",interval);
	}
function remSlapper(id){
	clearInterval(slappers[id]);
	document.body.removeChild(document.getElementById('Slapper_'+id));
	}
