function empty($value){
return (!$value || $value===null || $value==='' || $value==='undefined' || $value===undefined || typeof $value === 'undefined') ? true : false;
 }
function ucfirst(str){
var firstLetter = str.substr(0, 1);
return firstLetter.toUpperCase() + str.substr(1);
 } //v5
function in_array(string,array){
for(i = 0; i < array.length; i++){
if(array[i] === string){ return true; }
}
 } //v5
function is_array($val){ return ($val.length > 0) ? true : false; }
function isInt(x){
if(isNaN(Number(x))){ return false; }
 }
function getId(id){
if(!empty(id)){ return document.getElementById(id); }
	}
function css(id,paramx,value){
var param = fix_param(paramx);
var j = getId(id);
if(!empty(j)){
eval('j.style.'+param+'="'+value+'"; j.'+param+'="'+value+'";');
}
 } //v5
function animate(id,param,direction,funct,seconds_per_unit,amount_per_unit,total_no_of_units){
var initial_value = parseFloat(getValue(id,param));
if(param === 'opacity' && isNaN(initial_value)){ initial_value = 1.00; }
	for(x = 1; x <= total_no_of_units; x++){
		var amount = parseFloat(amount_per_unit) * x;
		var time = seconds_per_unit * x;
		var num = initial_value + ((direction === '-') ?  -amount : amount); 
		var metric = (param === 'opacity') ? '' : 'px';
		setTimeout("eval('"+funct+"')('"+id+"','"+param+"','"+num+metric+"')",time);
	}
 } //v5
function effects($id,$type){
if(!empty($id)){
	if($type === 'fade_in'){
		css($id,'opacity',0); animate($id,'opacity','+','css',100,0.1,10);
	}else if($type === 'fade_out'){
		animate($id,'opacity','-','css',100,0.1,10);
	}
}	
 }
function inLink($id,content,$effect){
var j = getId($id);
if(!empty(j)){ 
if(!empty($effect)){ effects($id,$effect); }
	j.innerHTML=content;
	j.value=content;
	}
 }
//cookies
function createCookie(name,value,days){
if(days!==''){
	var date = new Date();
	date.setTime(date.getTime()+(days*24*60*60*1000));
	var expires = '; expires='+date.toGMTString();
 }else{
	var expires='';
 }
document.cookie = name+'='+value+expires;
 }
function readCookie(name){
	if(document.cookie){
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	if(is_array(ca)){
	for(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 cookie_exists(cooky){
return !empty(readCookie(cooky)) ? true : false;
	}
function eraseCookie(name){
	createCookie(name,"stub",-1);
 }
function killCookies(){ 
var whole_cookie = document.cookie;
var each_cookie = whole_cookie.split(";");
for (i = 0; i < each_cookie.length; i++){ 
var cname = each_cookie[i].split("=");
eraseCookie(cname[0]);
 }
 }
//v5
function openClose(divName,state){
if(!empty(divName)){
	if(!empty(state)){
		var j = getId(divName);
	if(!empty(j)){	
		if(state === 'open'){ 
		createCookie('px_'+divName,divName,1);
			j.style.display = 'block'; } 
		else if(state === 'close'){ 
		eraseCookie('px_'+divName);
			j.style.display = 'none'; 
		}
	}
	}
}
 }
function fix_param(param){
if(param){ 
var i = param.split(" ");
if(i[1]){ return i[0]+ucfirst(i[1]); }else{ return i[0];}
}	
	} //v5
function getValue(id,paramx){
var j = getId(id);
var param = fix_param(paramx);
if(!empty(j)){ 
var g = eval('j.'+param+';');
var f = eval('j.style.'+param+';'); 
	if(g !== undefined){ 
		return g; 
	}else if(f !== undefined){ 
		return f; 
	}else{
		return '';	
	}
}	
 } //v5
function ticker($div,$prefix,$start,$end,$time){
if(!empty($div)){
for($i = $start; $i <= $end; $i++){ 
setTimeout("inLink('"+$div+"',getContent('"+$prefix+$i+"'),'fade_in')",$time*1000*($i-$start));
}
setTimeout("ticker('"+$div+"','"+$prefix+"','"+$start+"','"+$end+"','"+$time+"')",$time*1000*($end-($start-1)));
}
 }
//DOM
function getFrameContent(id){
var oDoc = getId(id).contentWindow || getId(id).contentDocument;
if(oDoc){ return oDoc.document.body.innerHTML; }
 }
function getContent(id){
if(!empty(id)){
var j = getId(id);
if(!empty(j)){
	if(j.value && j.value.length > 0){
		var content = j.value;
	}else if(j.innerHTML && j.innerHTML.length > 0){
		var content = j.innerHTML;
	}
return content;
}
}
 }
function getInput(form,element){
return getId(form).elements[element];
	}
//rte
function fontEdit(x,y){
textEditor.document.execCommand(x,"",y);
textEditor.focus();
 }
function rte_ini(){
var testframe = document.createElement("iframe");
testframe.name = testframe.id = "textEditor";
testframe.style.width='99%';
testframe.style.border='1px solid #EEE';

if (testframe.addEventListener){
testframe.addEventListener("load",function(e){this.contentWindow.document.designMode = "on";}, false);
} else if (testframe.attachEvent){
testframe.attachEvent("load", function(e){this.contentWindow.document.designMode = "on";});
}

getId('rte_body').appendChild(testframe);

textEditor.document.designMode="on";
textEditor.document.open();
textEditor.document.write('<head><style type="text/css">body{ font-family:arial; font-size:13px; }</style> </head>');
textEditor.document.close();
textEditor.focus();
 }
//file upload
function fileupload(form3,target,process,params){ 
var j = getId(form3);
if(j.elements[0].value){ 
j.enctype='multipart/form-data';
j.method='post';
j.action='?q='+process+'&file='+j.elements[0].id+'&folder='+j.elements[1].value+'&'+params;
j.target=target;
j.submit();
j.elements[0].value='';
}
 }
function uploading(){
if(cookie_exists('upload')){
inLink('progress',readCookie('upload')+' upload complete!','fade_out');
eraseCookie('upload');
}
 }
function upload(formx){ 
var j = getId(formx);
var file = getInput(formx,'file').value;
inLink('hidden_div','');
var iframe = document.createElement("iframe");
iframe.setAttribute('name','hidden_frame'); 
iframe.setAttribute('frameborder','0'); 
iframe.setAttribute('style','width:0; height:0; position:fixed; z-index:10; bottom:-10px; right:-10px;'); 
iframe.setAttribute('onLoad','uploading();');
getId('hidden_div').appendChild(iframe);	
if(file){ 
createCookie('upload',file,1);
inLink('progress',file+' uploading...','fade_in');
j.enctype='multipart/form-data';
j.method='post';
j.action='kitnes.php?ssid=12389234';
j.target='hidden_frame';
j.submit();
getInput(formx,'file').value='';
setTimeout("xlink('view_uploaded','','k_attached')",0);
}
 }
//html5
function k_os($key,$value){
return (!$value) ? eval('localStorage.'+$key) : eval('localStorage.'+$key+'="'+$value+'"'); 
 }
//navigation
function GetXmlHttpObject(){
var xmlHttp=null;
		try{ xmlHttp=new XMLHttpRequest();}
		catch(e){ 
		try{ xmlHttp=new ActiveXObject('Msxml2.XMLHTTP');}
		catch(d){ xmlHttp=new ActiveXObject('Microsoft.XMLHTTP');}
		}
	return xmlHttp;
 }
function validate(formId){ 
var qstr = '';
var xform = getId(formId);
if(xform===null){alert('Form Construct Error!'); return;}
var elem = xform.elements; 
	for(i = 0; i < elem.length; i++){ 
	var k = getId(elem[i].name);
	var $rq = elem[i].getAttribute('required');
		if(elem[i].value === '' && ($rq === 'yes' || $rq === 'required')){
			alert('"'+elem[i].getAttribute('title')+'" is a required field and cannot be left empty!'); 
			k.style.backgroundColor='#ffeedd'; 
			k.focus();  
			return;
		}
		else if(elem[i].value === '' && elem[i].getAttribute('required') === 'optional'){
			if(elem[i].value === ''){
				if(confirm('leave "'+elem[i].getAttribute('title')+'" empty?')){ 
					k.style.backgroundColor='#ffeedd'; 
					k.value='NULL'; 
				}else { 
					k.style.backgroundColor='#ffeedd'; 
					k.focus(); 
					return;
				}
			}else{ 
				k.style.backgroundColor=''; 
			} 
		}
		var $itype = elem[i].getAttribute('itype');
		if($itype === 'email' || $itype === 'im'){
			if(elem[i].value.search("@") === -1 || elem[i].value.search("[.*]") === -1){
			var $cf = 'Correct format is USERNAME @ SERVICE PROVIDER\'S WEB ADDRESS. e.g. sam@skype, sam@yahoomail.com';
				alert('Email address not valid!'); return false;
			}
		/*}else if($itype === 'phone' || $itype === 'fax'){
			if(elem[i].value.search("-") < 2){ 
			var $cf = 'Correct format is COUNTRY CODE - NETWORK/REGIONAL CODE - PHONE/FAX NUMBER - EXTENSION(IF ANY) e.g. +233-24-4617704';
				alert('Phone address is not valid! '+$cf); return false;
			}*/
		}else if($itype === 'country'){
			if(!isInt(elem[i].value)){
			xlink('get_location','type=country&name='+elem[i].value);
			elem[i].value = getContent('hidden_div');
			}
			xlink('get_location','');
		}
			var ci = elem[i].value; 
			//var cx = ci.replace('&','%26');
			var cd = ci.replace(/\+/g,'-d-');
			var cx = cd.replace(/&/g,'%26');
	qstr += elem[i].name + '=' + cx + '&';
	} 
	return qstr;
 }
function getformvalues(url,dis,formId){ 
if(validate(formId)){
	if(dis!==null){ effects('progress_bar','fade_in'); inLink('progress_bar','sending data, please wait..'); }
return validate(formId)+url;
}
 }
function xlink(str,url2,dis,form3){ 
	if(empty(str)){ return; }
	var gop = (!empty(form3)) ? 'p' : 'g'; 
	var $pb = 'progress_bar'; 
	if(empty(dis)){ dis = 'hidden_div'; } 
	var display=dis;
    var xmlHttp3= new GetXmlHttpObject();
	if(xmlHttp3===null){ alert('Browser does not support HTTP Request'); return; }
		if(str === 'reload'){ 
			if(url2 === 'clear'){  killCookies();  }else{  eraseCookie('pc_main'); }
		window.location.reload(); 
		return; 
		/*} else if(str === 'redirect'){ 
			if(split_url2(url2,'clear') === 'cookies'){ 
				killCookies(); 
			}
		location.href = unescape(split_url2(url2,'path'));	
		return;*/
		}
	//var $curl = (cookie_exists('kuid')) ? '&cm='+readCookie('kuid') : '';
	var url='kitnes.php?q='+str+'&'+url2+'&div='+display+'&ssid='+Math.random(); //+$curl;
		if(gop==='p'){ 
			if(getformvalues(url,display,form3)){ 
			xmlHttp3.open('POST',url,true);
		    xmlHttp3.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
			xmlHttp3.send(getformvalues(url,display,form3)); 
			openClose('dropDown','close');
			}
		}
		else if(gop==='g'){ 
			css($pb,'opacity',1); inLink($pb,'please wait..');
			var uas = ['login','logout','phpJs','update','runInsert','minor_ops','rotate_image','adserve','nully'];
			if(readCookie('ar') === null && !in_array(str,uas)){ 
			if(url2){ 
			var url2x = (split_url2(url2,'sr') === 'runInsert') ? url2.replace('sr=runInsert','') : url2;
			var url2y = (split_url2(url2x,'sr') === 'update') ? url2x.replace('sr=update','') : url2x;
			}
			eraseCookie2(display);
			//k_os('pc_'+display,str+','+url2y+','+display); 
			}else{ eraseCookie('ar'); } 
			//var $cookies = doCookies();
			xmlHttp3.open('GET',url,true);
			xmlHttp3.send(null);
			//doCookies($cookies);
		}
    xmlHttp3.onreadystatechange = function(){
	var jp = getId(display);
	if(!empty(jp)){ 
	if(xmlHttp3.readyState===1){ inLink($pb,'connecting..'); }
	if(xmlHttp3.readyState===2){ inLink($pb,'connected..'); }
	if(xmlHttp3.readyState===3){ inLink($pb,'downloading..'); }
	if(xmlHttp3.readyState===4 || xmlHttp3.readyState==='complete'){
		if(xmlHttp3.status===404){ inLink(display,'load failed..'); }
		var $rsp = xmlHttp3.responseText;
		inLink($pb,((gop === 'g') ? 'receiving data..' : 'data received, thank you!'));
		setTimeout("effects('"+$pb+"','fade_out')",1000);
		if(split_url2(url2,'go')){ location.href = 'kitnes.php?q='+str+'&'+url2; }
		if(!empty($rsp)){ 
		inLink(display,$rsp); 
		anchorx(url2,$rsp); 
		if(empty(split_url2(url2,'kc'))){ load_kml('','x','click'); }
		//setTimeout("load_kitnes_js('"+display+"')",0);
/*		var $sp = $rsp.split(':');
			if($sp[0] === 'xlink'){
				if($sp[1] === 'error'){ alert('error'); return; }
				//var $s = $sp[1].split(',');
			}*/
		}
		if(split_url2(url2,'goto')){ 
		setTimeout("inLink('"+$pb+"','redirecting..')",2000); 
		location.href = unescape(split_url2(url2,'goto')); 
		}
	} }
 };
 }
function eraseCookie2($name){
if(!empty($name)){
$j = document.cookie;
if($j){
var $obj = $j.split(';');  
for (i = 0; i < $obj.length; i++){ 
var $x = $obj[i].split('=');
if(contains(sub_rebind($name),$x[0])){ 
eraseCookie($x[0]);
 } } } }
 } //v9!
function anchorx(path,content){
if(!empty(path)){
var x = path.split('&');
	for(i = 0; i < x.length; i++){
		var z = x[i].split('=');
		if(z[0] === 'a'){ window.location.hash = '#'+z[1]; }	
		//if(z[0] == 'id'){ createCookie('zid',z[1],1); }
		if(z[0] === 'tab'){ create_page(content); }
	} 
}
 }
function split_url2(path,key){
var x = path.split('&');
	for(i = 0; i < x.length; i++){
		var z = x[i].split('=');
		if(z[0] === key){ return z[1]; }
	}
 }
function create_page(content){
var page = (cookie_exists('page_num')) ? readCookie('page_num') : 0;
createCookie('page_num',Number(page)+1,1);
var page_id = 'page-'+readCookie('page_num'); 
var newdiv = document.createElement('div');
newdiv.setAttribute('id',page_id);
newdiv.setAttribute('onclick',"inLink('rightContent1',getContent(this.id));page_up();openClose('opened-pages','close');");
newdiv.innerHTML = content;     
newdiv.className = 'dyn_pages';
newdiv.title = 'reopen this page';
getId('opened-pages').appendChild(newdiv);
 }
function contains($value,$str){
if(!empty($value) && !empty($str)){ return ($str.search($value) === -1) ? false : true;	}
 }
function sub_rebind($div){ 
if(!empty($div)){
if(contains('-',$div)){ var $bind = '-'; }else if(contains('_',$div)){ var $bind = '_'; }
if(!empty($bind)){
var $k = $div.split($bind);
return $k[0]+$bind+$k[1];	
}else{
return Math.random();	
	}
}
 }
function doCookies($str){
if(empty($str)){ var $mode = 'erase'; var $j = document.cookie; }else{ var $mode = 'create'; var $j = $str; }
if($j){
var $obj = $j.split(';');  
for (i = 0; i < $obj.length; i++){ 
var $x = $obj[i].split('=');
$vars = ['PHPSESSID','kuid'];
if(!in_array($x[0],$vars)){ 
	if($mode === 'create'){ 
		createCookie($x[0],$x[1],1); 
	}else if($mode === 'erase'){ 
		eraseCookie($x[0]);
	}
 }
 }
return $j;
 }
 } //v9!
function process_cookies(){
var whole_cookie = document.cookie;
var each_cookie = whole_cookie.split(";");  
for (i = 0; i < each_cookie.length; i++){ 
var so = each_cookie[i].split("=");
createCookie('ar','',1);
if(so[0].indexOf('pc_') === 1){
var new_val = each_cookie[i].replace(so[0]+'=','');
var x = new_val.split(",");
setTimeout("xlink('"+x[0]+"','"+x[1]+"','"+x[2]+"')",0);
}
 }
//setTimeout("process_cookies2()",10);
 }
function process_cookies2(){
var whole_cookie = document.cookie;
var each_cookie = whole_cookie.split(";");  
for (i = 0; i < each_cookie.length; i++){ 
var so = each_cookie[i].split("=");
if(so[0].indexOf('px_') === 1){ openClose(so[1],'open'); }
 }
 }
//start
function k_livescript($url){
var $js = document.createElement("script");
var $d = 'kitnes_wf';
$js.setAttribute('type','text/javascript'); 
$js.setAttribute('src',$url+'&ssid='+Math.random()); 
inLink($d,'');
getId($d).appendChild($js);
 }
function k_tls($id,$content,$url,$time){
inLink($id,$content);
setTimeout("k_livescript('"+$url+"')",$time*1000);	
 }
function load_kml($e,$timer,$event){
if(empty(get('ssid'))){ 
var $sec = parseInt(readCookie('time'));
if(empty($timer)){
document.write('<div id="hidden_div" style="width:0; height:0; position:fixed; z-index:10; bottom:-10px; right:-10px;"></div>');
document.write('<div id="kitnes_bar" style="visibility:hidden; position:fixed; z-index:1000; bottom:0; width:100%; height:20px;"></div>');
document.write('<div id="kitnes_wf" style="width:0; height:0; position:fixed; z-index:10; bottom:-11px; right:-11px;"></div>');	
}
//get query string
var $ue_url = document.location.href;
var $u = escape($ue_url);
var $ux = $ue_url.split('?');
if(is_array($ux)){
var $uxx = (!empty($ux[1])) ? $ux[1].split('#') : '';
var $qstr = (!empty($uxx[1])) ? $uxx[0] : $ux[1];
}	
//scan elements
if(empty($e)){
var $x = document.all ? document.all : document.getElementsByTagName("*");
}else{
var $x = getId($e).all ? getId($e).all : getId($e).getElementsByTagName("*");
}
//loop through elements
if(is_array($x)){ 
for(i=0; i<$x.length; i++){ 
//create id
var $id = $x[i].getAttribute('id');
if(empty($id)) $x[i].setAttribute('id',Math.random());
var $d = $x[i].getAttribute('$d');
$d = (!empty($d)) ? $d : $x[i].getAttribute('id'); 
//check overlay
var $o = $x[i].getAttribute('o'); 
if(!empty($o) && $o === 'yes' && empty($event) && !empty($timer) && getValue($id,'display') !== 'none' && getValue($id,'visibility') !== 'hidden'){ 
setTimeout("create_overlay('"+$d+"')",100); 
$x[i].removeAttribute('o');
}
//run function
var $f = $x[i].getAttribute('f');
if(!empty($f)){ 
var $p = $x[i].getAttribute('p'); 
//ad plugin
var $itype = $x[i].getAttribute('i');
if(!empty($itype)){ 
if($itype === 'ad' && !empty($event)){ $x[i].setAttribute('t','once'); }
}
//process 'em
if(!empty($timer)){
	var $t = $x[i].getAttribute('t'); 
	if(!empty($t)){ 
		if($t == 'once'){
		$x[i].removeAttribute('t'); 
		setTimeout("xlink('"+$f+"','"+$p+"&kc=yes&url="+$u+'&'+$qstr+"','"+$d+"')",0);
		}
	var $t2 = parseInt($t);
	if($sec % $t2 == 0){ 
	setTimeout("xlink('"+$f+"','"+$p+"&kc=yes&url="+$u+'&'+$qstr+"','"+$d+"')",0);
	} }
}else{ 
setTimeout("xlink('"+$f+"','"+$p+"&kc=yes&url="+$u+'&'+$qstr+"','"+$d+"')",0);
}
 } 
} } 
}
 } //v11!
function create_overlay($id){ 
var $tag = getId($id).tagName.toLowerCase();
if($tag == 'img' || $tag == 'object' || $tag == 'embed'){ 
var $width = parseInt(getValue($id,'width'));
var $height = parseInt(getValue($id,'height'));
if($width !== 0 || $height !== 0){ 
var $left = findPosX($id); 
var $top = findPosY($id);
$new_height = $height/7.35; 
var $new_layer = document.createElement('div');
var $i = $id+'-nl';  
$new_layer.setAttribute('id',$i); 
var $sf = getId($id).getAttribute('sf'); 
var $sp = getId($id).getAttribute('sp'); 
var $op = getId($id).getAttribute('op'); 
if(!empty($sf)) $new_layer.setAttribute('f',$sf); 
if(!empty($sp)) $new_layer.setAttribute('p',$sp);
insertAfter($new_layer,getId($id));
css($i,'position','relative');
css($i,'width',$width+'px');
css($i,'height',($new_height)+'px');
var $new_left = findPosX($i);
css($i,'left',($left-$new_left)+'px'); 
css($i,'background color','#000'); 
css($i,'color','#FFF');
css($i,'opacity',0.75);
css($i,'z index',1009);
if(!empty($op) && $op === 'up'){
css($i,'margin top',-$height+'px');	
css($i,'margin bottom',$height-$new_height+'px');
}else{ 
css($i,'margin top',-$new_height+'px');	
}
inLink($i,'ad space for rent');
} }
 }
function insertAfter(newElement,targetElement){
var parent = targetElement.parentNode;
if(!empty(parent)){
  if (parent.lastChild == targetElement) {
    parent.appendChild(newElement);
  } else {
    parent.insertBefore(newElement,targetElement.nextSibling);
  }
}
 }
function load_kitnes_js(){ 
load_kml();
k_livescript('kitnes.php?v=1');
shortcuts();
//eraseCookie('page_num');
//process_cookies();
var int = self.setInterval("create_time()",1000);
var x = self.setInterval("load_kml('','x')",1000);
rte_ini();
//document.onmouseup = function(){ selectedText(); }
 } //run on page load
function create_time(){
return (cookie_exists('time')) ? createCookie('time',parseInt(readCookie('time'))+1) : createCookie('time',0);
 } //new!
//chat
function chatjs(){
xlink('show_chat_messages','sr=runInsert&runI=portal','chat_messages','chat_form');
getId('data').focus();
getId('data').value='';
 }
function call_chat(){
var div = 'chat_display';
if(getContent('_portal_type') === 'forum'){ 
xlink('call_chat','repeat',div);	
xlink('call_users','repeat','chat_users');
var j = getId(div);
j.scrollTop = j.scrollHeight;
}
 } //v9
function chat_clear_focus(){
var j = getId('data');
j.value=''; 
j.focus();
 }
function chat_up(){
var w = getId('chat-messages');
w.scrollTop = w.scrollHeight;	
 }
function page_up(){
var j = getId('body');
j.scrollTop = j.scrollHeight;	
 }
function chatjs2(form){
xlink('display_chat','sr=runInsert&runI=message&host='+getContent('_message_host')+'&guest='+getContent('_message_guest'),'chat-messages',form);
chat_clear_focus();
 }
//toggle n stuff
function toggle(div){
if(!empty(div)){ return (getId(div).style.display==='none') ? openClose(div,'open') : openClose(div,'close'); }
 }
function toggleHide(rC,div){
var j = getId(rC);
if(j.style.display==='none'){ 
j.style.display='block';
inLink(div,'Hide');
	}else{ 
j.style.display='none';
inLink(div,'Add New');
}
 }
function dropDown(event){
var $x = '<span name="dropDown" id="dropDown" style="z-index:101; position:fixed; left:'+event.clientX+'px; top:'+(event.clientY-85)+'px"><img src="images/preload.gif"></span>';
inLink('xyPoint',$x);
 }
function remove(id,object,field){
	if(confirm('Do you really want to delete "'+object+'"?')){
		xlink('update','elem=deleted&val=y&id='+id);
			openClose(field,'close'); 
			openClose(id,'close');	
	}
	openClose('dropDown','close');
 }
function attach2(id){
	if(cookie_exists('host') && cookie_exists('host_div') && id !== ''){ 
		xlink('list_entry_files','id='+readCookie('host')+'&sr=runInsert&runI=service&_service_mode=link&_service_host='+readCookie('host')+'&_service_guest='+id,readCookie('host_div'));
	}
	openClose('dropDown','close');
 }
function remove2(id,obj){
if(confirm('confirm delete?')){
inLink(id,(getContent(id)).replace(obj,''));
xlink('listLinks','string='+getContent('files'),'list_attachments');
	}
 }
function toggle3(group,id,empty){
	if(cookie_exists(group)){
		openClose(readCookie(group),'close');
		if(empty==='yes'){inLink(readCookie(group),'');}
		}
	openClose(id,'open');
	createCookie(group,id,1);
	}
function toggle4($group,$id,$param,$new_val,$old_val){
	if(cookie_exists($group)){
		css(readCookie($group),$param,$old_val);
		}
	css($id,$param,$new_val);
	createCookie($group,$id,1);
	}
function visited(id){
	if(document.cookie && readCookie('visited') !== null && readCookie('visited') !== ''){
		getId(readCookie('visited')).style.color='';
		}
	getId(id).style.color='#f00';
	createCookie('visited',id,1);
	}
function hash_id($apid){
var $x = document.getElementsByTagName('span');
if(is_array($x)){ 
for(i=0; i<$x.length; i++){ 
if($x[i].getAttribute('apid') == $apid){
return $x[i].getAttribute('id'); 
} } }	
 }
function navigate(prefix,dir,pos){ 
var left = prefix+'left';
var right = prefix+'right';
var num = prefix+'count';
var div = prefix+'photo_area';
var c_div = prefix+'caption';
var $total = Number(getContent(prefix+'0'));

var $h = location.hash;
if(!empty($h)){ 
$j = $h.split("#");
$pos = hash_id($j[1]).split(prefix);
createCookie(num,$pos[1],1); 
 }
if(!cookie_exists(num)){ createCookie(num,1,1); }
if(!empty(pos)){ createCookie(num,pos,1); }
if(Number(readCookie(num)) > $total){ createCookie(num,1,1); } //use folder id to do an add, check on new album

if(dir === 'left'){ var x = -1;}
else if(dir === 'right'){ var x = +1;}
else { var x = 0;}
createCookie(num,Number(readCookie(num))+x,1);

var $xid = prefix+readCookie(num);
inLink(div,getContent($xid),'fade_in');
var $c_xid = $xid+'caption';
inLink(c_div,getContent($c_xid));

if($xid){
$xx = getId($xid);
if(!empty($xx)){
var $apid = getId($xid).getAttribute('apid');
location.hash = '#'+$apid;
inLink('_portal_parent',$apid);
//xlink('comments','id='+$apid,'comments_area');
}
}

$r = Number(readCookie(num));
if($total === 1){ openClose(left,'close'); openClose(right,'close'); }
else if($r === 1){ openClose(left,'close'); openClose(right,'open'); }
else if($r === $total){ openClose(right,'close'); openClose(left,'open'); }
else{ openClose(left,'open'); openClose(right,'open'); }

inLink(prefix+'total',$total);
inLink(prefix+'current',$r);
 }
function relocate(id){
if(!readCookie(id+'zindex')){ createCookie(id+'zindex',2,1); }
if(readCookie(id+'zindex') === 2){ 
getId(id).style.zIndex = 5;
createCookie(id+'zindex',5,1);
}else if(readCookie(id+'zindex') === 5){
getId(id).style.zIndex = 1;
createCookie(id+'zindex',1,1);
}else if(readCookie(id+'zindex') === 1){
getId(id).style.zIndex = 2;	
createCookie(id+'zindex',2,1);
}
 } //v4!
function popup(){
var j = window.open('','','width=640,height=480');
j.document.write("<p>This is 'myWindow'</p>");
j.focus();
 }
function checknswitch($e){
var $res = screen.width;
var $mobile = ($res > 240 && $res < 400) ? true : false;
var $url = document.location.href;
var $s = $url.split('?');
var $x = $url.split('index.php');
var $t = $url.split('/mobile');
if($mobile == true){
if(empty($e)){
	if(get('view') != 'mobile'){ 
	$urlx = (!empty($s[1])) ? $url.replace('?','?view=mobile&') : $url+'?view=mobile';
	} 
}else{
	if(empty($t[1])){ 
		if(!empty($s[1])){ 
		$urlx = (!empty($x[1])) ? $url.replace('index.php?','mobile/?') : $url.replace('?','mobile/?');
		}else{
		$urlx = (!empty($x[1])) ? $url.replace('index.php','mobile/') : $url+'mobile/';
		} 
	}
}
if(!empty($urlx)) document.location = $urlx;
}
 }
function get($key){
var $i = location.href; 
var $u = $i.split('?');	
if(!empty($u[1])){
var $t = $u[1].split('&');
if(is_array($t)){
	for(i=0; i<$t.length; i++){
	var $b = $t[i].split('=');
	if(!empty($key) && $key == $b[0]){ return $b[1]; }
	} 
}else{
	var $b = $u[1].split('=');
	if(!empty($key) && $key == $b[0]){ return $b[1]; }
}
}else{ return '';}
 } //v11!
//edit
function copy(id,name){
createCookie('clipboard',id,1);
alert(name+' has been copied unto the clipboard!');
openClose('dropDown','close');
 }
function paste(id){ 
if(cookie_exists('clipboard')){ inLink(id,readCookie('clipboard')); }
 }
function clear_copied(){ 
eraseCookie('clipboard');
alert('clipboard has been erased!');
openClose('dropDown','close');
 }
function cut(id,name){
if(confirm('If you decide to cut, the object will be put on the clipboard and then deleted after you paste. Do you wish to proceed?')){
copy(id,name);
css(id,'opacity',0.5);
}
	}
function cField(id){
createCookie('cField',id,1);
 }
function hideReplace($id,$content,$re){
if(empty($re) && cookie_exists('clipboard')){
inLink($id,readCookie('clipboard'));
openClose('dropDown','close');
enableDisable($id,'disable');
css($id,'type','hidden');	
inLink($id+'-hr',$content,'fade_in');
}else{
enableDisable($id,'enable');
inLink($id,'');
css($id,'type','text');	
inLink($id+'-hr','');
}
 }
function selectedText(){
var $txt = '';
if(window.getSelection){
$txt = window.getSelection();
}else if(document.getSelection){
$txt = document.getSelection();
}else if(document.selection){
$txt = document.selection.createRange().text;
}else{
return false;
}
if(!empty($txt)){ createCookie('selectedText',$txt); }
 }
function insertAtCursor(myField,myValue){ //myField accepts an object reference, myValue accepts the text strint to add
//IE support
if (document.selection) {
myField.focus();
/*in effect we are creating a text range with zero length at the cursor location and replacing it with myValue*/
sel = document.selection.createRange();
sel.text = myValue;
}
//Mozilla/Firefox/Netscape 7+ support
else if (myField.selectionStart || myField.selectionStart === '0') {
/*Here we get the start and end points of the selection. Then we create substrings up to the start of the selection and from the end point of the selection to the end of the field value. Then we concatenate the first substring, myValue, and the second substring to get the new value.*/
var startPos = myField.selectionStart;
var endPos = myField.selectionEnd;
myField.value = myField.value.substring(0, startPos)+ myValue+ myField.value.substring(endPos, myField.value.length);
} else {
myField.value += myValue;
}
if(getId('files')){
openClose('dropDown','close');
xlink('listLinks','string='+getContent('files'),'list_attachments');
}
 }
//business
function openClose2(value,valueX,id){
return (value === valueX) ? openClose(id,'open') : openClose(id,'close');	
 }
function switchformfield($id,$x){
if($x === 'new'){ changeToInput($id); }	
 }
function changeToInput(obj){
var tb = document.createElement('INPUT');
tb.name = obj.getAttribute('name');
tb.type = 'text';
tb.value = ''; //obj.options[obj.selectedIndex].text;
obj.parentNode.insertBefore(tb,obj);
obj.parentNode.removeChild(obj);
 }
function clearfield(id){
getId(id).style.backgroundColor='';
 }
function swap(id,original,replacement){
(getId(id).innerHTML !== original) ? inLink(id,original) : inLink(id,replacement);
 }
function addUp(quantity,cost,total){
var qty = getId(quantity).value;	
var price = (getId(cost).value).replace(',','');	
getId(total).value = (qty * price).toFixed(2);
 }
function toPrice(amount,field){
var amt = (amount * 1).toFixed(2);
inLink(field,amt);	
	}
function clearComma(id){
var j = getId(id);
if(!empty(j)){ j.value = j.value.replace(',',''); }
 }
function money_format(id){
if(id){
var amount = getId(id).value.replace(',','');
var amt = (amount * 1).toFixed(2);
inLink(id,amt);	 
}
 }
//move
function move_em(e){ //onmousedown
if(e === null){e = window.event;}
var sender = (typeof(window.event) != "undefined" ) ? e.srcElement : e.target; 
var $id = sender.id;
if(!$id) $id = sender.setAttribute('id',Math.random()); 
if(getId($id).getAttribute('m') === '1'){ 
mouseover=true;
var $l = parseInt(findPosX($id));
var $t = parseInt(findPosY($id));
var $x = e.clientX;
var $y = e.clientY;
document.onmousemove=function(e){
if(e === null){e = window.event;}
css($id,'left',$l+e.clientX-$x+"px");
css($id,'top',$t+e.clientY-$y+"px");
return false;
 };
}
 }
function halt_em(e){ //onmouseup
document.onmousemove=null;
document.onmousedown=null;
 }
//specials
function scale($id){
if(!empty($id)){
$width = getId($id).width;
$height = getId($id).height;
$incr = 1;
if($width > $height){
$w_ratio = 2*($width/$height); 
$new_height = (2*$incr)+$height; 
$new_width = ($w_ratio*$incr)+$width; 
}else{
$h_ratio = 2*($height/$width); 
$new_width = (2*$incr)+$width; 
$new_height = ($h_ratio*$incr)+$height; 	
}
css($id,'height',$new_height+'px');
css($id,'width',$new_width+'px'); 
}
 }
function shortcuts(){
//http://www.openjs.com/scripts/events/keyboard_shortcuts/
shortcut = {
	'all_shortcuts':{},//All the shortcuts are stored in this array
	'add': function(shortcut_combination,callback,opt) {
		//Provide a set of default options
		var default_options = {
			'type':'keydown',
			'propagate':false,
			'disable_in_input':false,
			'target':document,
			'keycode':false
		}
		if(!opt) opt = default_options;
		else {
			for(var dfo in default_options) {
				if(typeof opt[dfo] == 'undefined') opt[dfo] = default_options[dfo];
			}
		}

		var ele = opt.target;
		if(typeof opt.target == 'string') ele = document.getElementById(opt.target);
		var ths = this;
		shortcut_combination = shortcut_combination.toLowerCase();

		//The function to be called at keypress
		var func = function(e) {
			e = e || window.event;
			
			if(opt['disable_in_input']) { //Don't enable shortcut keys in Input, Textarea fields
				var element;
				if(e.target) element=e.target;
				else if(e.srcElement) element=e.srcElement;
				if(element.nodeType==3) element=element.parentNode;

				if(element.tagName == 'INPUT' || element.tagName == 'TEXTAREA') return;
			}
	
			//Find Which key is pressed
			if (e.keyCode) code = e.keyCode;
			else if (e.which) code = e.which;
			var character = String.fromCharCode(code).toLowerCase();
			
			if(code == 188) character=","; //If the user presses , when the type is onkeydown
			if(code == 190) character="."; //If the user presses , when the type is onkeydown

			var keys = shortcut_combination.split("+");
			//Key Pressed - counts the number of valid keypresses - if it is same as the number of keys, the shortcut function is invoked
			var kp = 0;
			
			//Work around for stupid Shift key bug created by using lowercase - as a result the shift+num combination was broken
			var shift_nums = {
				"`":"~",
				"1":"!",
				"2":"@",
				"3":"#",
				"4":"$",
				"5":"%",
				"6":"^",
				"7":"&",
				"8":"*",
				"9":"(",
				"0":")",
				"-":"_",
				"=":"+",
				";":":",
				"'":"\"",
				",":"<",
				".":">",
				"/":"?",
				"\\":"|"
			}
			//Special Keys - and their codes
			var special_keys = {
				'esc':27,
				'escape':27,
				'tab':9,
				'space':32,
				'return':13,
				'enter':13,
				'backspace':8,
	
				'scrolllock':145,
				'scroll_lock':145,
				'scroll':145,
				'capslock':20,
				'caps_lock':20,
				'caps':20,
				'numlock':144,
				'num_lock':144,
				'num':144,
				
				'pause':19,
				'break':19,
				
				'insert':45,
				'home':36,
				'delete':46,
				'end':35,
				
				'pageup':33,
				'page_up':33,
				'pu':33,
	
				'pagedown':34,
				'page_down':34,
				'pd':34,
	
				'left':37,
				'up':38,
				'right':39,
				'down':40,
	
				'f1':112,
				'f2':113,
				'f3':114,
				'f4':115,
				'f5':116,
				'f6':117,
				'f7':118,
				'f8':119,
				'f9':120,
				'f10':121,
				'f11':122,
				'f12':123
			}
	
			var modifiers = { 
				shift: { wanted:false, pressed:false},
				ctrl : { wanted:false, pressed:false},
				alt  : { wanted:false, pressed:false},
				meta : { wanted:false, pressed:false}	//Meta is Mac specific
			};
                        
			if(e.ctrlKey)	modifiers.ctrl.pressed = true;
			if(e.shiftKey)	modifiers.shift.pressed = true;
			if(e.altKey)	modifiers.alt.pressed = true;
			if(e.metaKey)   modifiers.meta.pressed = true;
                        
			for(var i=0; k=keys[i],i<keys.length; i++) {
				//Modifiers
				if(k == 'ctrl' || k == 'control') {
					kp++;
					modifiers.ctrl.wanted = true;

				} else if(k == 'shift') {
					kp++;
					modifiers.shift.wanted = true;

				} else if(k == 'alt') {
					kp++;
					modifiers.alt.wanted = true;
				} else if(k == 'meta') {
					kp++;
					modifiers.meta.wanted = true;
				} else if(k.length > 1) { //If it is a special key
					if(special_keys[k] == code) kp++;
					
				} else if(opt['keycode']) {
					if(opt['keycode'] == code) kp++;

				} else { //The special keys did not match
					if(character == k) kp++;
					else {
						if(shift_nums[character] && e.shiftKey) { //Stupid Shift key bug created by using lowercase
							character = shift_nums[character]; 
							if(character == k) kp++;
						}
					}
				}
			}
			
			if(kp == keys.length && 
						modifiers.ctrl.pressed == modifiers.ctrl.wanted &&
						modifiers.shift.pressed == modifiers.shift.wanted &&
						modifiers.alt.pressed == modifiers.alt.wanted &&
						modifiers.meta.pressed == modifiers.meta.wanted) {
				callback(e);
	
				if(!opt['propagate']) { //Stop the event
					//e.cancelBubble is supported by IE - this will kill the bubbling process.
					e.cancelBubble = true;
					e.returnValue = false;
	
					//e.stopPropagation works in Firefox.
					if (e.stopPropagation) {
						e.stopPropagation();
						e.preventDefault();
					}
					return false;
				}
			}
		}
		this.all_shortcuts[shortcut_combination] = {
			'callback':func, 
			'target':ele, 
			'event': opt['type']
		};
		//Attach the function with the event
		if(ele.addEventListener) ele.addEventListener(opt['type'], func, false);
		else if(ele.attachEvent) ele.attachEvent('on'+opt['type'], func);
		else ele['on'+opt['type']] = func;
	},

	//Remove the shortcut - just specify the shortcut and I will remove the binding
	'remove':function(shortcut_combination) {
		shortcut_combination = shortcut_combination.toLowerCase();
		var binding = this.all_shortcuts[shortcut_combination];
		delete(this.all_shortcuts[shortcut_combination])
		if(!binding) return;
		var type = binding['event'];
		var ele = binding['target'];
		var callback = binding['callback'];

		if(ele.detachEvent) ele.detachEvent('on'+type, callback);
		else if(ele.removeEventListener) ele.removeEventListener(type, callback, false);
		else ele['on'+type] = false;
	}
 }
shortcut.add("Ctrl+Up",function(){
document.onmousedown=function(e){
if(e == null){e = window.event;}
var $elem = (typeof(window.event) != "undefined" ) ? e.srcElement : e.target; 
var $id = $elem.id;
if(!$id) $id = $elem.setAttribute('id',Math.random()); 
createCookie('curObj',$id,1);
return false;
 };
});
shortcut.add("Shift+Up",function(){xlink('profile','','rightContent1')});
shortcut.add("??",function(e){
//document.onmousedown=function(e){dropDown(e);}
//document.onmouseup=function(e){ xlink('dropMenu','runM=file&dm=note','dropDown'); }
}
);
shortcut.add("??",function() {
//move start
document.onmousedown=function(e){
if(e == null){e = window.event;}
var sender = (typeof(window.event) != "undefined" ) ? e.srcElement : e.target; 
var $id = sender.id;
if(!$id) $id = sender.setAttribute('id',Math.random()); 
if(getId($id).getAttribute('mobile') == 'yes'){
mouseover=true;
var $l = parseInt(findPosX($id));
var $t = parseInt(findPosY($id));
var $x = e.clientX;
var $y = e.clientY;
document.onmousemove=function(e){
if(e == null){e = window.event;}
css($id,'position','absolute');
css($id,'left',$l+e.clientX-$x+"px");
css($id,'top',$t+e.clientY-$y+"px");
return false;
 };
}else{
return false;	
}
return false;
 };
document.onmouseup=function(e){
document.onmousemove=null;
document.onmousedown=null;
//shortcut.remove("Ctrl+Shift");
 };
//move end
},{
	'type':'keydown',
	'propagate':true,
	'target':document
}); 
 }
//utilities
function findPosX(obj){
var obj = getId(obj);
    var curleft = 0;
    if(obj.offsetParent){
        while(1){
          curleft += obj.offsetLeft;
          if(!obj.offsetParent){ break; }
          obj = obj.offsetParent;
        }
	}else if(obj.x){
        curleft += obj.x;
	}
    return curleft;
  } 
function findPosY(obj){
var obj = getId(obj);
    var curtop = 0;
    if(obj.offsetParent){
        while(1){
          curtop += obj.offsetTop;
          if(!obj.offsetParent){ break; }
          obj = obj.offsetParent;
        }
	}else if(obj.y){
        curtop += obj.y;
	}
    return curtop;
 } 
//others
function enableDisable(id,state){
	var j = getId(id);
	if(state==='enable'){
		j.disabled=false;	
	}else if(state==='disable'){
		j.disabled=true; 
		}
	}
function dropDownInnerSelect(id){
var x = getId(id);
return x.options[x.selectedIndex].text;
	}
function resizeTextarea(id){
var j = getId(id); 
var text = j.value.length;
var area = j.rows * j.cols;
var ratio = text / area;
var invratio = 1/ratio;
if(ratio > 1){ ++j.rows; }
for(x=0; x < 1000; x++){
	if(invratio >= 2){ --j.rows;
	} else { break;
	}
}
inLink('textrows',j.rows);
 }
//misc 
function remove_from_sentence(word){
createCookie('per_line',readCookie('per_line').replace(word,''),1);
 } 
function exec(id,param,value){
var j = getId(id);
if(!empty(j)){ eval('j.style.'+param+'=value'); }
	}
function fetchIn(line,kind){
var str = line.split(" ");
for(i = 0; i < str.length; i++){ 
if(type(str[i]) === kind){
	remove_from_sentence(str[i]);
	return str[i];
}
}
 }
function locateIn(line,val){
if(line.search(val) !== -1){ 
remove_from_sentence(val);
return true;
}
 }
function create(objName, html, width, height, left, top){
if(objName==='square'){
var newdiv = document.createElement('div');
newdiv.setAttribute('id',readCookie('curObj'));   
width =(!empty(width)) ? width : 200;
newdiv.style.width=width+'px';
height  = (!empty(height)) ? height : 200;		
newdiv.style.height = height+'px';
newdiv.style.background = "#EEE";
newdiv.style.border = "1px solid #000";
newdiv.innerHTML = (!empty(html)) ? html : "";  
document.body.appendChild(newdiv);
 } //square codes
else if(objName==='circle'){
	}
 }
function type(str){
var colors = ['blue','black','green','red','pink'];
if(in_array(str,colors)){ return 'color'; }
var shapes = ['square','circle','triangle'];
if(in_array(str,shapes)){ return 'shape'; }
var distance = ['50','100','500'];
if(in_array(str,distance)){ return 'move'; }
var style = ['dashed','solid','dotted'];
if(in_array(str,style)){ return 'style'; }
var compound = ['background','border','font','list','margin','padding'];
if(in_array(str,'compound')){ return 'compound'; }
 }
function move(id,value){
var y = getId(id);
if(y){
y.style.position = 'absolute';
y.style.left = value+'px';
}
 }
function read(line){
createCookie('per_line',line,1); 
if(locateIn(line,'draw')){
openClose(readCookie('curObj'),'close');
var id = Math.random();
createCookie('curObj',id,1);
	create(fetchIn(line,'shape'),'','200','200', '500','100');
var root = 'background';
var attr = 'color';
var param = (type(root) === 'compound') ? root+ucfirst(attr) : root;
if(locateIn(line,attr)){ exec(id,param,fetchIn(line,attr)); }

if(locateIn(line,'move')){ move(id,fetchIn(line,'move')); }
var root = 'border'; 
if(locateIn(line,root)){ exec(id,root,fetchIn(line,'color')); }
}	
 }
function syn(line){
if(line !== ''){
var lineEdit = line.replace("create", "draw");
return lineEdit;
}
 }
function draw(cmd){
if(cmd!==''){
var str = getContent(cmd).split("\n");
	for(i=0; i<str.length; i++){
	read(syn(str[i]));
	}
}
 }
function hex2num(hex){
	if(hex.charAt(0) === "#"){ hex = hex.slice(1); } //Remove the '#' char - if there is one.
	hex = hex.toUpperCase();
	var hex_alphabets = "0123456789ABCDEF";
	var value = [3];
	var k = 0;
	var int1,int2;
	for(i=0;i<6;i+=2) {
		int1 = hex_alphabets.indexOf(hex.charAt(i));
		int2 = hex_alphabets.indexOf(hex.charAt(i+1)); 
		value[k] = (int1 * 16) + int2;
		k++;
	}
	return(value);
 }
function num2hex(triplet){
	var hex_alphabets = "0123456789ABCDEF";
	var hex = "#";
	var int1,int2;
	for(i=0;i<3;i++) {
		int1 = triplet[i] / 16;
		int2 = triplet[i] % 16;

		hex += hex_alphabets.charAt(int1) + hex_alphabets.charAt(int2); 
	}
	return(hex);
 }
function file_get_contents($url){
//document.domain = $url_sub;
var $f = document.createElement("iframe");
$f.src=$url;
$f.setAttribute('id','fr2'); 
$f.setAttribute('frameborder','0'); 
$f.setAttribute('style','width:0; height:0; position:fixed; z-index:10; bottom:-10px; right:-10px;'); 
$f.setAttribute('onLoad','inLink(\'hidden_div\',getFrameContent(this.id));');
document.body.appendChild($f);	
//alert($f.domain);
 }
