/* 
	Author: Alexander Shatalov <admin@cmsdragon.com>
	All rights reserved, using this script or part of this scripts or this script but modified without author's permission is illegal.
*/
var E=function(e){return document.getElementById(e)}
var is_ie=(navigator.userAgent.toLowerCase().indexOf('msie')!=-1);
function findPos(o){var l=t=0;if(o.offsetParent){l=o.offsetLeft;t=o.offsetTop;while(o=o.offsetParent){l+=o.offsetLeft;t+=o.offsetTop}}return[l,t]}
function urlencode(s,u){s=s.replace(/\r\n/g,"\n").replace(/\%/g,'%25').replace(/\+/g,'%2B');var t='';for(var n=0;n<s.length;n++){var c=s.charCodeAt(n);if(c<128){t+=String.fromCharCode(c)}else if((c>127)&&(c<2048)){t+=String.fromCharCode((c>>6)|192);t+=String.fromCharCode((c&63)|128)}else{t+=String.fromCharCode((c>>12)|224);t+=String.fromCharCode(((c>>6)&63)|128);t+=String.fromCharCode((c&63)|128)}}if(!u){s=escape(s)}return s}
function serialize(f){var q='',t;if(!f[0]){if($(f)){var f=$(f).getElementsByTagName('*')}else{return ''}}for(i=0;i<f.length;i++){t=f[i].type;if(t=='undefined'){continue}else if(f[i].disabled||!f[i].name){continue}else if(t!='text'&&t!='password'&&t!='textarea'&&t!='radio'&&t!='checkbox'&&t!='hidden'&&t!='select-one'&&t!='select-multiple'&&t!='button'&&t!='submit'){continue}else if((t=='checkbox'||t=='radio')&&!f[i].checked){continue}else if(t=='select-one'&&f[i].selectedIndex!=-1&&!f[i].value&&f[i].name.indexOf('id')<=0&&f[i].options[f[i].selectedIndex].text){q+='&'+f[i].name+'='+urlencode(f[i].options[f[i].selectedIndex].text)}else{q+='&'+f[i].name+'='+urlencode(f[i].value)}}return q}		
var xml=new Array();
function XML(c){if(typeof XMLHttpRequest!='undefined'){xml[c]=new XMLHttpRequest()}else if(window.ActiveXObject){xml[c]=new ActiveXObject("Microsoft.XMLHTTP")}else{xml[c]=false}}
function post(fn,u,e){var c=xml.length;XML(c);if(!xml[c]){alert('Could not load AJAX');return false}xml[c].open('POST',SC.SiteURL+u+'&n='+Math.floor(Math.random()*10000),true);xml[c].setRequestHeader('Content-Type','application/x-www-form-urlencoded');xml[c].onreadystatechange=function(){if(xml[c].readyState==4){if(e){E(e).style.display='';E(e).innerHTML=xml[c].responseText}else{eval(xml[c].responseText)}}};xml[c].send((fn?serialize(fn.elements):''))}
function getTop(){return gT=window.pageYOffset||document.documentElement.scrollTop||0;}
p=function(arr){var h='<table>';if(typeof(arr)=='object'){for(i in arr){h+='<tr align="left"><td>'+i+':</td><td> '+arr[i]+'</td></tr>'}h+='</table>';var d=document.createElement('DIV');d.innerHTML=h;document.body.appendChild(d)}else{alert(arr)}}
function getElementsByClass(c,n,t){var e=new Array();if(!n){n=document}if(!t){t='*'}var l=n.getElementsByTagName(t),p=new RegExp("(^|\\s)"+c+"(\\s|$)");for(i=0,j=0;i<l.length;i++){if(p.test(l[i].className)){e[j]=l[i];j++}}return e}
function kD(e){var W='';var k;if(e){ctrl=e.ctrlKey;alt=e.altKey;k=e.which}else{k=event.keyCode;ctrl=event.ctrlKey;alt=event.altKey}if((k==83&&ctrl&&is_ie)||(k==83&&alt)){W='ctrl+s'}if(W=='ctrl+s'){FORM.save(E('save_link'))}}document.onkeydown=kD;
function writeFrame(n){var f=document.createElement('IFRAME');if(!n){n='frame_set'}f.id=n;f.name=n;f.style.display='none';f.src='javascript:void(0);';document.body.appendChild(f)}
function download(p,i){E('frame_set').src='/download.php?p='+p+'&f='+i}
function getWindowSize(){var w,h;if(window.innerWidth){w=window.innerWidth}else if(document.documentElement&&document.documentElement.clientWidth){w=document.documentElement.clientWidth}else if(document.body){w=document.body.clientWidth}if(window.innerHeight){h=window.innerHeight}else if(document.documentElement&&document.documentElement.clientHeight){h=document.documentElement.clientHeight}else if(document.body){h=document.body.clientHeight}return[parseInt(w),parseInt(h)]}
function kill(f,e){var l=f.elements.length;if(!l){return false}for(n=0;n<l;n++){if((f.elements[n].type=='select-one'||f.elements[n].type=='select-multiple')&&f.elements[n].selectedIndex&&f.elements[n].value==''){continue}if(!e&&(f.elements[n].value==''||f.elements[n].value=='0')&&f.elements[n].type!='hidden'){f.elements[n].disabled=true}else if(e&&f.elements[n].type=='text'){f.elements[n].value=''}}}
function copy(t){var d=document.createElement('TEXTAREA');d.innerHTML=t.replace(/"/g,'&quot;').replace(/</g,'&lt;').replace(/>/g,'&gt;');var c=d.createTextRange();c.execCommand('Copy')}
function ViewImage(f,x,y,t){var c=getWindowSize();var top=(c[1]-y)/2;var left=(c[0]-x)/2;var w=window.open('','imageviewer','width='+x+',height='+y+',menubar=no,toolbar=no,top='+top+',left='+left);w.document.open();w.document.write('<html><head><title>'+t+'</title></head><body><div style="position:absolute;width:'+x+'px; height:'+y+'px;left:0px;top:0px"><a href="javascript:void(0)" onclick="self.close()"><img src="'+SC.SiteURL+f+'" border="0"></a></div></body></html>');w.document.close()}
/*COOKIE*/
var Cookie={set:function(n,v,e,p,d,s){var t=new Date();t.setTime(t.getTime());if(e){e=e*86400000}var ed=new Date(t.getTime()+e);document.cookie=n+'='+escape(v)+(e?';expires='+ed.toGMTString():'')+(p?';path='+p:'')+(d?';domain='+d:'')+(s?';secure':'')},get:function(n){var ac=document.cookie.split(';'),f='',v='',t='',c='';for(i=0;i<ac.length;i++){t=ac[i].split('=');c=ac[0].replace(/^\s+|\s+$/g,'');if(n==c){return unescape(t[1].replace(/^\s+|\s+$/g,''))}}return null},del:function(n,p,d){if(this.get(n)){document.cookie=n+'='+(p?';path='+p:'')+(d?';domain='+d:'')+';expires=Thu, 01-Jan-1970 00:00:01 GMT'}}}
function popup(url,w,h,s,p){if(s){s='yes'}else{s='no'}if(!w){w=800}if(!h){h=600}var c=getWindowSize();var top=(c[1]-h)/2;var left=(c[0]-w)/2;var win=window.open((p?'':SC.SiteURL+'/popup.php')+url,url.replace(/[^A-Za-z0-9]/gi,''),'directories=no,statusbar=no,location=no,scrollbars='+s+',resizable=yes,width='+w+',height='+h+',top='+top+',left='+left);win.focus()}
var stop_timer;
function Timer(i,sec,func,id){if(stop_timer){window.status='';return false}if(i>=sec){eval(func.replace('`','\''));return 1}
var left=seconds2time(sec-i);
E(id).innerHTML=left;window.status=left+' seconds left..';i++;window.setTimeout("Timer("+i+","+sec+",'"+func+"','"+id+"')",1000)}
function seconds2time (s) {
var ss = function(n){return n==1?'':'s'};
if(s<0){return'just now'}if(s<60){var n=s;return n+' second'+ss(n)}if(s<60*60){var n=Math.floor(s/60);return n+' minute'+ss(n)}if(s<60*60*24){var n=Math.floor(s/60/60);return n+' hour'+ss(n)}if(s<60*60*24*7){var n=Math.floor(s/60/60/24);return n+' day'+ss(n)}if(s<60*60*24*31){var n=Math.floor(s/60/60/24/7);return n+' week'+ss(n);}if(s<60*60*24*365){var n=Math.floor(s/60/60/24/31);returnn+' month'+ss(n);}var n=Math.floor(s/60/60/24/365);return n+' year'+ss(n)}
function d(v){if(typeof(v)=='object'||typeof(v)=='array'){var r='<table cellspacing="2">';for(i in v){r+='<tr><td>'+v+'</td><td>'+i[v]+'</td></tr>';}r+='</table>'} else{r = v;}var d=document.createElement('DIV');d.innerHTML=r;window.document.body.appendChild(d)}
function toggleCookie(c,obj,img){if(obj.style.display!='none'){obj.style.display='none';img.src=SC.SiteURL+'/img/down.png';Cookie.set('toggle_'+c,1);}else{obj.style.display='';img.src=SC.SiteURL+'/img/up.png';Cookie.set('toggle_'+c,0)}}
function oL() {
	writeFrame();
}
function slideAds() {
	var o=E('ads_main').childNodes[0];
	// TODO:
}
var house_t;
var house_height=false;
var house_closed=false;
function _hideInSecs(d,h){
	if (h<=74) {post('','/ajax.php?u=session&sw=close_house');E('click_here2readmore').style.display='none';house_closed=true;clearTimeout(house_t);return false;}
	var e=E(d);
	h-=5;
	E(d).style.height=h+'px';
	var house_t=setTimeout("_hideInSecs('"+d+"',"+h+")",4);
}
function hideInSecs(d,s) {
	house_height=parseInt(E(d).style.height);
	setTimeout("_hideInSecs('"+d+"',"+house_height+")",s*1000);
}
function toggleHide(d) {
	if (SC.house_closed){
		E(d).style.height=SC.house_closed+'px';
	}
	else if (house_closed) {
		E(d).style.height=house_height+'px';
	}
	E('click_here2readmore').style.display='';
}

function rz(h){window.parent.document.getElementById('upload_frame').style.height=h+'px'}
function rzMe() {var d = getElementsByClass('sz_photo');var max_height=0;for(i=0;i<d.length;i++){if(d[i].height>max_height){max_height=d[i].height}}var rows=Math.ceil(d.length/6);var extra = SC.do_height?40:0;var s=rows*max_height+42+(rows*32)+extra;rz(s)}
function substrMe(o,l,d){if(o.value.length>l){o.value=o.value.substring(0,l);d.style.color='red'} else d.style.color='#888';d.innerHTML=(l-o.value.length)+' characters left'}
var W;
function kU(e) {
	var k;if(e){ctrl=e.ctrlKey;alt=e.altKey;k=e.which}else{k=event.keyCode;ctrl=event.ctrlKey;alt=event.altKey}
	if(k==13){W='enter'}
	else if(k==123&&!alt){window.document.location.replace(SC.SiteURL+'/login')}else if(k==120){window.document.location.replace(SC.SiteURL+'/')}
	else if(k==119){window.document.location.replace(SC.SiteURL+'/profile')}
}
function kD(e) {
	kU(e);
}
window.onload=oL;
window.onkeyup=kU;window.onkeydown=kD;