﻿// banner
var currentselid = 0;
var selidint;
/*function setfoc(id){
    currentselid = id;
    for(i=1;i<6;i++){
        document.getElementById("tmb"+i).className = "border3";
    }
    document.getElementById("bannerad").className = "banner"+id;
    document.getElementById("tmb"+id).className ="border2";
    document.getElementById("bannerbigtitle").innerHTML = document.getElementById("bigtitle"+id).value;
    document.getElementById("bannersmltitle").innerHTML = document.getElementById("smltitle"+id).value;
    document.getElementById("bannertext").innerHTML = document.getElementById("btext"+id).value;
    stopit();
}*/
function playnext(){
    if(currentselid==5){
        currentselid = 1;
	} else {
        currentselid++;
    }
    //setfoc(currentselid);
    playit();
}
function playprev(){
    if(currentselid==1){
        currentselid = 5;
	} else {
        currentselid--;
    }
    //setfoc(currentselid);
    playit();
}
function playit(){
    stopit();
    selidint = setTimeout(playnext,8000);
}
function stopit(){
    clearTimeout(selidint);
}
window.onload = function(){
    playit();
}
// create community
function setCreateValue(){
	objValue = document.getElementById("CommunityName");
	if(objValue.value==""){
		objValue.value = "yourdomain";
	}
}
function setValue(){
	objValue = document.getElementById("CommunityName");
	if(objValue.value=="yourdomain"){
		objValue.value = "";
	}
}
function QuickCreateKeyPress(event) {
	event = event || window.event;
	if(event.keyCode == 13){
		QuickCreate();
	}
	return false;
}
function QuickCreate() {
	var CommunityName = document.getElementById('CommunityName').value;
	if(CommunityName.toLocaleLowerCase()=="yourdomain"){CommunityName = "";}
	if(CommunityName.length <= 0){window.location.href = "http://www.aimoo.com/Create.html";}
	else{window.location.href = "http://www.aimoo.com/CommunityName-" + CommunityName + "/Create.html";}
}
// Testimonials
var tspeed = 30;
var oMarquee = document.getElementById("mq");
var omqdemo = document.getElementById("mqdemo");
var h_content = oMarquee.offsetHeight;
var odl_content = omqdemo.offsetHeight;
var x_c = parseInt(h_content/odl_content)+1;
for(var i=0; i<x_c; i++){
    var o_c = omqdemo.cloneNode(true);
    oMarquee.appendChild(o_c);
}
var iScrollAmount = 1;
var tmyMar;
function scroll(){
    oMarquee.scrollTop += iScrollAmount;
    var ol_c = oMarquee.scrollTop;
    if(odl_content-ol_c <= 0){
        window.clearTimeout(tmyMar);
        oMarquee.scrollTop = 0;
    }else{
        if(ol_c % h_content != 0){
            tmyMar = window.setTimeout(scroll,tspeed);
        }else{
            window.clearTimeout(tmyMar);
        }
    }
}
var t_c = 10000;
function clipShow(){
    scroll();
    window.setTimeout(clipShow,t_c);
}
window.setTimeout(clipShow,t_c);
// author
var testimonials_name = setInterval(tofnamefunc,10000);
var testimonials_name_id = document.getElementById("mq1");
function tofnamefunc(){
    var t_o = testimonials_name_id.firstChild;
    testimonials_name_id.removeChild(t_o);
    testimonials_name_id.appendChild(t_o);
}
testimonials_name_id.onmouseover = function(){clearInterval(testimonials_name)}
testimonials_name_id.onmouseout = function(){testimonials_name = setInterval(tofnamefunc,10000);}
// time
var testimonials_time = setInterval(toftimefunc,10000);
var testimonials_time_id = document.getElementById("mq2");
function toftimefunc(){
    var t_o = testimonials_time_id.firstChild;
    testimonials_time_id.removeChild(t_o);
    testimonials_time_id.appendChild(t_o);
}
testimonials_time_id.onmouseover = function(){clearInterval(testimonials_time)}
testimonials_time_id.onmouseout = function(){testimonials_time = setInterval(toftimefunc,10000);}
// Statistics
function intComma(num){
    num = parseInt(num);
    var T = "", S = String(num), L = S.length - 1, C, j, P = S.indexOf(".") - 1;
    if (P < 0) {P = L;}
    for (j = 0; j <= L; j++) {
        T += (C = S.charAt(j));
        if ((j < P) && ((P - j) % 3 == 0) && (C != "-")) {T += ",";}
    }
    return T;
}
var ups = 0.090451388889;
var tps = 0.130451388889;
var rps = 0.226427854938;
var fps = 0.01262731481481;
$(function(){
    setInterval(function(){
    document.getElementById("usersid").innerHTML = intComma(user_counter+=ups);
    document.getElementById("topicsid").innerHTML = intComma(topic_counter+=tps);
    document.getElementById("repliesid").innerHTML = intComma(reply_counter+=rps);
    document.getElementById("forumsid").innerHTML = intComma(forums_counter+=fps);
    },1000);
});
window.setInterval(upstatistics,20000);
function upstatistics(){
	var usercount = document.getElementById("usersid").innerHTML;
	var topiccount = document.getElementById("topicsid").innerHTML;
	var replycount = document.getElementById("repliesid").innerHTML;
	var forumcount = document.getElementById("forumsid").innerHTML;
	statisticsbegin(usercount,topiccount,replycount,forumcount);
}
function statisticsbegin(usercount,topiccount,replycount,forumcount){
    loadAjaxData("/StatisticsAjax.cfm",{usercount:usercount,topiccount:topiccount,replycount:replycount,forumcount:forumcount},statisticssuccess,statisticsfail);
}
function statisticssuccess(v){}
function statisticsfail(){};
// search forum
function ysetValues(){
	objValue = document.getElementById("q");
	if(objValue.value=="Forum Name/Keywords"){objValue.value = "";}
}
function timestop(){setTimeout("ysetCreateValues()",200);}
function ysetCreateValues(){
    objValue = document.getElementById("q");
    if(objValue.value==""){objValue.value = "Forum Name/Keywords";}
    document.getElementById("keysearch").style.display="none";
}
var rowNo=-1;
function keywordsearch(evt,str){
    evt=(evt)?evt:((window.event) ? window.event:"");
    var key=evt.keyCode?evt.keyCode:evt.which;
    if(key==8){
        objValue = document.getElementById("q").value;
        if(objValue.length==0){
            document.getElementById("searchs").innerHTML="";
            document.getElementById("keysearch").style.display="none";
            return;
        }
        xmlHttp=GetXmlHttpObject();
        if(xmlHttp==null){return;}
        var url="findforumbykeyword.cfm";
        url=url+"?key="+objValue;
        url=url+"&sid="+Math.random();
        xmlHttp.onreadystatechange=stateChanged;
        xmlHttp.open("GET",url,true);
        xmlHttp.send(null);
        //document.getElementById("keysearch").style.display="block";
    }
    if(key==38){
        var message=document.getElementById("keymessage");
        if(message == null){
        }else{
            var lis=message.getElementsByTagName("li");
            for(var k=0;k<lis.length;k++){
                message.getElementsByTagName("li")[k].style.backgroundColor="#FFFFFF";
                message.getElementsByTagName("li")[k].style.color='#3399CC';
            }
            if(rowNo <= 0){ rowNo++;}
            if(rowNo==0){
                message.getElementsByTagName("li")[rowNo%lis.length].style.backgroundColor="#6699FF";
            }else{
                message.getElementsByTagName("li")[--rowNo%lis.length].style.backgroundColor="#6699FF";
            }
            message.getElementsByTagName("li")[rowNo%lis.length].style.color='#000000';
            document.getElementById("q").value=trim(message.getElementsByTagName("li")[rowNo%lis.length].title); 
        }
    }else if(key==40){	
        var message=document.getElementById("keymessage");
        if(message == null){
        }else{
            var lis=message.getElementsByTagName("li");
            for(var k=0;k<lis.length;k++){
                message.getElementsByTagName("li")[k].style.backgroundColor="#FFFFFF";
                message.getElementsByTagName("li")[k].style.color='#3399CC';
            }
            message.getElementsByTagName("li")[++rowNo%lis.length].style.backgroundColor="#6699FF";
            message.getElementsByTagName("li")[rowNo%lis.length].style.color='#000000';
            document.getElementById("q").value=trim(message.getElementsByTagName("li")[rowNo%lis.length].title); 
        }
    }else{
        if(str.length==0){
        }else{
            xmlHttp=GetXmlHttpObject();
            if(xmlHttp==null){
                return;
            }
            var url="findforumbykeyword.cfm";
            url=url+"?key="+str;
            url=url+"&sid="+Math.random();
            xmlHttp.onreadystatechange=stateChanged;
            xmlHttp.open("GET",url,true);
            xmlHttp.send(null);
            //document.getElementById("keysearch").style.display="block";
        }
    }
}
function stateChanged(){
    if(xmlHttp.readyState==4){
        if(trim(xmlHttp.responseText) == "null"){
            document.getElementById("keysearch").style.display="none";
            return;
        }
		if(xmlHttp.responseText != "")
		{
        	document.getElementById("searchs").innerHTML=xmlHttp.responseText;
			document.getElementById("keysearch").style.display="block";
		}
    }
}
function chooseit(str){
    var str=str.replace(/`/g,"'");
    objValue = document.getElementById("q");
    objValue.value = str;
    document.getElementById("keysearch").style.display="none";
    document.csesearch.submit();
}
