/*
http://www.webdesignerwall.com/tutorials/jquery-tutorials-for-designers/
http://codylindley.com/blogstuff/js/jquery/#
http://www.learningjquery.com/2009/02/slide-elements-in-different-directions
*/

/*
function trim(s)
{
  return s.replace(/^\s+|\s+$/, '');
}
*/


function escapequotes(s){
s.replace(/(\\\')|(\\\")/g, "'");
//alert(s);
return s;
}

function isEmpty(x){
	x=$.trim(x);
	if( x.length > 0 && x != "" && x != null ){
		return false;
	}
	else
		return true;
}

//only for input value
function exists(id){

	if( $(id).val() == null ){
	return false;
	}
	else{
	return true;
	}

}

function myConfirm(tmp){
	if( ! isEmpty(tmp) ){
		return confirm(tmp);
	}
	
	return true;
}

function redirectPage(loc){
alert("loc=" + loc);

	//window.location.href(loc);
	myPopup(loc);
	
return true;
}


function update_counter(ctr, char_elem, max_len)
{
    var ctrElem = document.getElementById(ctr);
    var charElem = document.getElementById(char_elem);
    var len = charElem.value.length;
    var val = max_len - charElem.value.length;
    ctrElem.innerHTML = val; 
}


function ugmt(){
var dt = new Date();
var tz = dt.getTimezoneOffset();
var x = "/q?m=xq";
x = x + "&ugmt=" +  getTzOffset();
$.get(x);
}

//###############################

$(document).ready(function(){ 
    $("#country").change(function(){
		var x = $("#country").val();
//alert(x);
		if( ! isEmpty(x) ){
			var k = "#select_state";
			if( exists(k) ){

			var loc = "/q?m=xq&w=allstates&country=" + x;
			
			var k1 = "#optall";
			if( exists(k1) ){
				loc = loc + "&optall=t";
			}
//alert(loc);
			$(k).load(loc);
//alert($(k).html());
			}
		}
	
	
	});
});

//###############################
/*
	$(document).ready(function(){	
		$("a").easyTooltip();
	});
*/	
	

/*
$(document).ready(function(){

	var x = ".listbox";
	
	$(x).hover(function(){
		return false;
    }, function(){	
		return false;
    });
});
*/

$(document).ready(function(){
	var x;
	var tmp;


	$("a").click(function(){
//alert($(this).attr("id"));
		$(this).css("outline", "none");
	});

	$("a").mouseover(function(){
//alert($(this).attr("class"));	
//alert($(this).attr("id"));
		if( $(this).attr("id") == "buttonlink" 
		|| $(this).attr("class") == "submitbutton"
		|| $(this).attr("class") == "noeffect"
		){
			$(this).css("text-decoration", "none");

		}

		else{

			$(this).css("text-decoration", "underline");
	
		}

	});
	
	$("a").mouseout(function(){
		$(this).css("text-decoration", "none");

	});
	


	$("div.itemlink").hover(function(){
		var x1 = $(this).attr("id");
		$(this).css("text-decoration", "none");
		$(this).css("background-color", "#EAF3B1");
		return false;
	}, function() {
		var x1 = $(this).attr("id");	
		$(this).css("background-color", x1);
		return false;
	});
	

	x="li.bglink, div.bglink, td.bglinkpg";
	$(x).hover(function(){
		$("a").css("text-decoration", "none");
		$(this).css("background-color", "#EAF3B1");
	}, function() {
	var tmpbgid;
	tmpbgid = $(this).attr("class");
//<span id="bglink" style="display:none;">#FFFFFF</span>
		tmpbgid = $("span#" + tmpbgid).text();
		if( tmpbgid == null ){
			tmpbgid = "#ffffff";
		}

		$(this).css("background-color", tmpbgid);

	});
		
	
	

	//not in use
	$(".menupad").click(function(){
		$("div.menupaddesc").show("normal");
	});
	
	$(".menupaddesc, #menupaddescclose").click(function(){
		$(".menupaddesc").hide();
	});


//alert($(this).attr("src"));
//alert($(this).attr("class"));
	$(".imgbutton").hover(function(){
	var x;
	var tmp;
		x = $(this).attr("src");
		tmp = x.replace(".png", "_bg.png");
//alert(tmp);	
		$(this).attr("src", tmp);		
	}, function(){
		x = $(this).attr("src");
		tmp = x.replace("_bg.png", ".png");	
		$(this).attr("src", tmp);	
	});

	
	//##############################
	
	//x= 'input[type="submit"],input[type="button"],.submitbutton,#buttonlink';
	var x2= 'input[type="submit"],input[type="button"]';
	x2 = x2 + ',.submitbutton';
	x2 = x2 + ',#buttonlink';
	$(x2).mouseover(function(){
		$(this).css("color", "#666666");
	});
	
	$(x2).mouseout(function(){
		$(this).css("color", "#000000");
	});
	

	
});


//##############################

$(document).ready(function() {
	
	//var flipduration = 100;
	var flipduration = 10;
	var x = '#hznav li';
	$(x).prepend("<span></span>");
	
	$(x).each(function() {
		var link = $(this).find("a").html(); //Find the text inside of the a tag
		$(this).find("span").show().html(link); //save the text link in the span tag
	}); 
	
	$(x).hover(function() {
		$(this).find("span").stop().animate({ 
			marginTop: "-40"
		}, flipduration);
		
	}, function() {
		$(this).find("span").stop().animate({
			marginTop: "0"
		}, flipduration);
	});


	var duration = 150;	
	var x1 = '#navside ul li a';
	$(x1).hover(function() {
    $(this).animate({ paddingLeft: '20px' }, duration);
    }, function() {
		$(this).animate({ paddingLeft: '0px' }, duration);
    });
	
	var x2 = '#navhz ul li a';
	$(x2).hover(function() {
    $(this).animate({ paddingLeft: '20px' }, duration);
    }, function() {	
		$(this).animate({ paddingLeft: '2px' }, duration);
    });


	//var duration = 150;
	var x3 = "#dropmenu li";
	$(x3).hover(function(){
	x = $(this).attr("id");
//alert(x);
		$(this).stop().animate({height:x, queue:false, easing:'easeOutBounce'}, duration);
		return false;
    }, function() {
	x = $("#itemlinklen").html() + "px";
		$(this).stop().animate({height:x, queue:false, easing: 'easeOutBounce'}, duration);
		return false;
	 });


});



	//##############################
	
$(document).ready(function(){
	var x;
	var tmp;


	x = '.cancel,.delete';
	$(x).click(function(){
		return processConfirm($(this).attr("class"), $(this).attr("id"));
	});

	
	x = 'input[type="submit"]';
	$(x).click(function(){
//alert($(this).attr("class"));
//alert($(this).attr("id"));
		//return processConfirm($(this).val());
		return processConfirm($(this).val(), $(this).attr("id"));

	});
	
});


function processConfirm(str){

		str = str.toLowerCase();
		//var lower = new Date().toString().toLowerCase();
		
		if(  str == "cancel" ){
			return myConfirm($("#cancelmsg").val());
		}
		else if( str == "delete" ){
			return myConfirm($("#deletemsg").val());
		}
		else{
			return true;
		}
}




$(document).ready(function(){
//radio button

	var x="";


	$('.ckbox').click(function(){
		var itemid=' input#';;
		var ckid=' span#ck';
		
		var myid = $(this).attr("id");
		var tmp = $(this).closest('form');
		tmp = $(tmp).attr("id");
		
		itemid += myid;
		ckid += myid;

//alert(itemid);
//alert(ckid);

		if( tmp != null ){
			formid = "form#" + tmp;
			itemid = formid + itemid;
			ckid = formid + ckid;

//alert($(ckid).text());
//alert($(itemid).is(':checked'));
			if( $(ckid).text() == "true" ){
				$(itemid).attr('checked', false);
				$(ckid).text("false");
			}
			else{
				$(itemid).attr('checked', true);
				$(ckid).text("true");			
			}
		
//alert($(itemid).attr('checked'));
//alert($(ckid).text());		
		}
		
		//must be true in order to check the box.
		return true;
	});

	x='a#selectallckbox,a#deselectallckbox';
	x += ',input#confirmDelarrIndex';
	$(x).click(function(){
	//if these vars are declared globally (above this function), js will remember the last state values.
	//Declare vars here locally, these vars will be reset.
	var setting="";
	var savesetting="";
	var formid="";
	var input_numItemid=' input#numItemid';
	var itemid=' input#itemid';
	var ckid=' span#ckitemid';


	
		var myid = $(this).attr("id");
//alert(myid);			
		var tmp = $(this).closest('form');
		tmp = $(tmp).attr("id");
//alert(tmp);
		if( tmp != null ){
			formid = "form#" + tmp;
			itemid = formid + itemid;
			ckid = formid + ckid;
//itemid = "input#itemid";
//ckid = "span#ckitemid";

			var numItemid = $(formid + input_numItemid).val();
//alert(numItemid);
			
			if( numItemid != null ){
			
		if( myid == "confirmDelarrIndex" ){
//alert(myid);
			var total=0;
				for(var i=0; i<numItemid; i++){
					tmp = itemid + i;
//alert(tmp);
					//tmp = $(tmp).is(':checked');
					//tmp = $(tmp).attr('checked');
					if( $(tmp).is(':checked') == true )
						total++;
				}
//alert(total);
if( total < 1 ){
	alert("You did not check any boxes for deletion.");
	return false;
}
else
	return confirm("Do you want to delete permanently?\n\n" + "Total items: " + total);

		}
	
		
		else if( myid == "selectallckbox" ){
			setting = true;
			savesetting = "true";
		}
		else if( myid == "deselectallckbox" ){
			setting = false;
			savesetting = "false";
		}
		else{

		return false;
		}
			

//form#xxmform input#itemid1
						
				for(var i=0; i<numItemid; i++){
					tmp = itemid + i;
//alert(tmp);
					$(tmp).attr('checked', setting);
					tmp = ckid + i;
//alert(tmp);	
//alert($(tmp).text());				
					$(tmp).text(savesetting);
//alert($(tmp).text());
//alert($("#ckitemid1").text());
				}
				
			}
		}
		
		return false;
	});
	
});

//############################


//display with the same name link if you have more than one listing
// this tells jquery to run the function below once the DOM is ready
$(document).ready(function() {

// choose text for the show/hide link - can contain HTML (e.g. an image)
var showText='+';
var hideText='-';

// initialise the visibility check
var is_visible = false;

var x = ".toggle";
var y = ".toggletitle";

if( ! exists(y) )
	return false;
var title = $(y).html();
showText = title;
hideText = '<span style="background-color:#fff278;color:#000000;">' + title + '</span>';
// append show/hide links to the element directly preceding the element with a class of "toggle"
$(x).prev().append(' <a href="#" class="toggleLink" style="text-decoration:none;outline:none;color:#7A2BF0;">'+showText+'</a>');


// hide all of the elements with a class of 'toggle'
$(x).hide();

// capture clicks on the toggle links
$('a.toggleLink').click(function() {

// switch visibility
is_visible = !is_visible;

// change the link depending on whether the element is shown or hidden
$(this).html( (!is_visible) ? showText : hideText);

// toggle the display - uncomment the next line for a basic "accordion" style
//$('.toggle').hide();$('a.toggleLink').html(showText);
$(this).parent().next(x).toggle('fast');

// return false so any link destination is not followed
return false;

});

});


//#############################

//pg_defaultQT
$(document).ready(function(){
	var w = window.screen.width;
	var h = window.screen.height;

	var myid = "#wrapper";
	var phonew = 310;
	var pcw = 850;

//test
//w=211;
//w=400;

	var x="#screenw";
//$(x).html(null);
//alert($(x).html());
//if( $(x).html() != "" ){
var y="";
y=$(x).attr("value");
//y=$(x).val();
//y="";
//alert(y);
if( y != "" ){
	//alert("set");
	return;
}

//alert("notset");
 
	if( w < phonew ){
		w = phonew;
	}
	else{
		var toobig = pcw;
		if( w > toobig ){
		var x = pcw;
		//var x = phonew;
		w = x;
		}
		
		if( w > (phonew + 200) ){
			$('#panelright').show();
		}
	}
	
	$("#pagewidth").css("width", w + "px");
	

	var s=KDxq();
	if( s != "" ){
		$.get(s + "&w=screen&sw=" + w + "&sh=" + h);
//alert(s);
	}

//alert(x);		
	
});


$(document).ready(function(){

	var tmp = "";
	var x = "";
	var myid = "";
	




/*	
	$('a#floatbox_bottom_show').click(function(){
	//$('input[type="radio"]').show();
	x = '<a href="#" id="floatbox_bottom_hide" class="linkwhite">Cancel</a>';
//alert(x)
	$('#toprightbutton').html(x);
//alert($('#rightbutton').html());
	$('input.delckboxhide').show();
	$('div.floatbox_bottom').show();
	return false;
	});
	
	$('#toprightbutton').click(function(){
//alert("her");alert($('#rightbutton').html());
	checkAllarrIndex(document.mform, 'itemid', false);
	$('input.delckboxhide').hide();
	$('div.floatbox_bottom').hide();
	return false;
	});
*/

/*
	$('a#floatbox').click(function(){alert("her");
	checkAllarrIndex(document.mform, 'itemid', false);
	$('input.delckboxhide').hide();
	$('div.floatbox_bottom').hide();
	return false;
	});		


	$('a#floatbox_bottom_hide').click(function(){alert("her");
	checkAllarrIndex(document.mform, 'itemid', false);
	$('input.delckboxhide').hide();
	$('div.floatbox_bottom').hide();
	return false;
	});		
*/

	//???
	$('a#show_delckbox').click(function(){
//alert("x");
	//$('input[type="radio"]').show();
	$('input.delckboxhide').show();
$('div.delckboxhide').show();
//$('div.floatbox_bottom').show();
//alert($('div.floatbox_bottom').html());
//alert($('input[type="radio"]').val());
	return false;
	});

	$('a#hide_delckbox').click(function(){
	//$('input[type="radio"]').show();
	checkAllarrIndex(document.mform, 'itemid', false);
	$('input.delckboxhide').hide();
$('div.delckboxhide').hide();
//$('div.floatbox_bottom').hide();
//alert($('input[type="radio"]').val());
	return false;
	});	
	

	//scroll the message box to the top offset of browser's scrool bar
	$(window).scroll(function(){
		//$('#floatbox').animate({top:$(window).scrollTop()+"px" },{queue: false, duration: 350});
		$('#floatbox').animate({top:$(window).scrollTop()+"px" },{queue: false, duration: 0});
  
	});
	
	//when the close button at right corner of the message box is clicked
	$('#floatbox_close').click(function(){
	//the messagebox gets scrool down with top property and gets hidden with zero opacity
	$('#floatbox').animate({ top:"+=15px",opacity:0 }, "slow");
	});



/*
	//??not working.
	//################
	x = '.xfloatbox_top';
	y = '.xfloatbox_bottom';
	//scroll the message box to the top offset of browser's scrool bar
	$(window).scroll(function(){

				$(x).stop().animate({top:$(window).scrollTop()+"px" },{'opacity':'1.0'},400);
		
	var el = document.getElementById('test');
	var h = el.scrollHeight;
	var vh = el.scrollTop;// vertical scroll offset from top (of scrollHeight)
	var barh = el.clientHeight; // scroll bar height
	var scrollBottom = h - (vh + barh); // offset of scroll from bottom
	//alert(scrollBottom);
				$(y).stop().animate({bottom:scrollBottom+"px" },{'opacity':'1.0'},400);

		var scrollTop = $(window).scrollTop();
			if(scrollTop != 0){
				//$(x).stop().animate({'opacity':'0.2'},400);
				$(x).stop().animate({top:$(window).scrollTop()+"px" },{'opacity':'0.2'},400);
				$(y).stop().animate({top:$(window).scrollTop()+"px" },{'opacity':'1.0'},400);

			}
			else{
				//$(x).stop().animate({'opacity':'1.0'},400);
				$(x).stop().animate({top:$(window).scrollTop()+"px" },{'opacity':'1.0'},400);
				$(y).stop().animate({top:$(window).scrollTop()+"px" },{'opacity':'0.2'},400);
			}
			
			//$(y).stop().animate({'opacity':'0.2'},400);

	});
					
	$(x).hover(function (e) {
		var scrollTop = $(window).scrollTop();
		if(scrollTop != 0){
			$(x).stop().animate({'opacity':'1'},400);
		}
	},function (e) {
		var scrollTop = $(window).scrollTop();
		if(scrollTop != 0){
			$(x).stop().animate({'opacity':'0.2'},400);
		}

	});
	
*/	



});


//#########################

function KDxq(){

var s="";
	//var a="#aid";
	var a="#KDxq";
	if( exists(a) ){
//alert("h");
		s= $(a).attr("value");
		//s=$(a).val();
		//s= $(a).text();
		//s="/q?aid=" + $("#aid").text() + "&m=xq" + "&dname=" + $("#pagedname").text();
	}
//alert(s);
return s;

}

/*
function KDpageurl(){
	var locpageurl="";
	
	var loc=KDxq();
	
	if( loc != "" ){
		locpageurl = loc + "&pageurl=" + $("#pageurl").text();
	}
	
	return locpageurl;
}
*/

//#########################

//######################


function closebox(myid){
	//alert(myid);
	$(myid).hide();
	return false;
}

function suggestLookup(inputString) {
	var s="";
	var loc=KDxq();
	//var locpageurl=KDpageurl();
	
	var suggest='#suggestions';
	var thelist='#autoSuggestionsList';
	
    if(inputString.length == 0) {
        // Hide the suggestion box.
        $(suggest).hide();
    } else {
	
		var tmpid = $('span.cmp').attr("id");
		if( tmpid == null ){
			return;
		}
		
		var tmp = '&k=' + tmpid;
	
		if( loc != "" ){
			//tmpid = "#" + x;
			s = loc + tmp + "&w=cmp";


        $.post(s, {qstr: ""+inputString+""}, function(data){
            if(data.length >0) {
                $(suggest).show();
                $(thelist).html(data);
//alert(data);
            }
        });
		}
    }
} // lookup

function suggestFill(thisValue) {
    $('#inputString').val(thisValue);
   $('#suggestions').hide();
}


//#########################


function updateDestbox(myid, data){

if( myid == null )
	return;

		var tmpdest = myid + "_dest";
		var tmpbox;
		
 //alert(myid);
tmpbox = $(tmpdest).html();
 $(tmpbox).html(data);
 $(tmpbox).show();
}

function processDestbox(myid, loc, postdata, info){
		var tmp="";
		var tmpbox="";
		var obj = "";
		//#vote_56
		//var myid = $(this).attr("id");

		obj = "#" + myid;
		tmp = $(obj + "_info").text();
//alert(tmp);
//alert(myid);

		//only want to send it once.
		if( tmp == "D" ){
			return;
		}

		if( (tmp != null ) && loc != "" ){
			if( info == "D" )
				$(obj + "_info").text(info);
			s = loc + tmp;

//alert(s);
			tmp=postdata;
$.post(s, {text: tmp}, function(data){
/*
var tmpupdate = x + "_update";
 $(tmpupdate).html($.trim(data));
updateDestbox(x, $(tmpupdate).html());
*/
updateDestbox(obj, $.trim(data));
 //$(obj).hide();
});			
		}

}

function instantAction(myid){

	var s="";
	var x="";
	var tmp;
	var loc=KDxq();
//	var locpageurl=KDpageurl();


//alert("ckAction=" + myid);


	if( myid.match(/^vote_/) ){
//alert("here");
	var postdata = "";
processDestbox(myid, loc, postdata, "D");
	return false;
	}

	else if( myid.match(/^savearticle/) ){
	var postdata = "";
processDestbox(myid, loc, postdata, "D");
		return false;
	
	}
	else{
	}
	
}

function ckAction(myid){

	var s="";
	var x="";
	var tmp;
	var loc=KDxq();
//	var locpageurl=KDpageurl();


//alert("ckAction=" + myid);



	if( myid.match(/^rptabuse/) ){
		//myid = "rptabusearticle_1233333"
		x = "#" + myid;
		var obj = x;
		
		var zt = $(obj + "_zt").text();
		var level = $(obj + "_level").val();
		var desc = $(obj + "_desc").val();

/*		
alert("#" + myid + "_zt");

alert("zt=" + zt + "&level=" + level);
alert("desc=" + desc);
if( level == "" || level == null ){
	alert("nxx");
}
*/
		var y = "#error_" + myid + "_level";
		$(y).html("&nbsp;");
		if( level == "" || level == null ){
			$(y).html("You did not make a selection.");
			$(y).show();
			return false;
		}
		
//return;

		if( loc != "" ){
			tmp = "";
			tmp = desc;
			tmp.replace(/^\s+|\s+$/, '');

		loc = loc + "&zt=" + zt + "&level=" + level;
		processDestbox(myid, loc, tmp, "D");
		}
		return false;

	}

	
	else if( myid.match(/^createarticle\_/) ){
		//preview
		
		if( loc != "" ){
			tmp = "";
			tmp = $("#comment").val();
			tmp.replace(/^\s+|\s+$/, '');
//alert("tmp=" + tmp);
			//x = "#" + myid + "_more";
x = "#" + myid + "_box";
//alert(x);
			if( tmp.length < 1 ){
				$(x).html(tmp);
			}
			else{

/*
			s = locpageurl + "&w=createarticle&itopic=" + $("#itopic").text();
			
//alert(s);
//http://api.jquery.com/jQuery.post/
$.post(s, {text: tmp}, function(data){
   //alert("Data Loaded: " + data);
   $(x).html($.trim(data));
 });
*/
processDestbox(myid, loc, tmp, "");
return false;

			}
		}
	}


	else if( myid.match(/^clear\_createarticle\_/) ){
			tmp = "";
			//remove "clear_"
			x = myid.substr(6);
			//x = "#" + x + "_more";
x = "#" + x + "_box";
//alert(x);
			$(x).html(tmp);
			return false;
	}
	
	else{
	}

}


//#############################




//#############################

$(document).ready(function() {

	var open='showmore.png';
	var close='showmoreclose.png';
	var visible="V";
	var notvisible = "H";
	var gmore="";
	
	var x = "span.showmore";	
	initShowmore(x, open, notvisible);
	
	var y = "span.showmorebut";	
	initShowmore(y, open, notvisible);


	$(x).click(function(){
		gmore = processShowmore(gmore, this, open, close, visible, notvisible);
		return false;
	});
	

	$(y).click(function(){
		gmore = processShowmore(gmore, this, open, close, visible, notvisible);
		return false;
	});
	
});

function initShowmore(pp, open, notvisible){
	var x = pp;
	var open_init = '<img src="/kd/images/pg/' + open + '" width="16" height="16" />&nbsp;';
	
	$(x).prepend("<span></span>");
	$(x).each(function() {
	//var tmp = $(this).attr("title");
	var tmp = $(this).html();
		var tmpid = $(this).attr("id");
		tmp = '<a href="#" style="text-decoration:none;">' + tmp + open_init + '</a>' + '<span style="display:none;" id="' + tmpid + '_status">' + notvisible + '</span>';
		$(this).html(tmp);
		$(this).show();
		//$(this).find("span").show().html(tmp); //save the text link in the span tag
		
		//$(this).attr({ title: ""});
//alert($(this).html());
//alert(tmpid);
	});

}

function processShowmore(gmore, obj, open, close, visible, notvisible){

	//var visible="V";
	//var notvisible = "H";
	//var gmore="";

		var s="";
		var tmp = $(obj).attr("id");
		instantAction(tmp);
//alert(tmp);



		if( tmp != null ){
			tmp = "#" + tmp;
			var link = $(obj).find("a");


			if( $(tmp + "_status").html() == notvisible ){

				if( gmore != "" ){
				if( $(gmore + "_status").html() == visible ){
					$(gmore + "_box").hide();
					$(gmore + "_status").html(notvisible);
			s = $(gmore).html().replace(close, open);
//alert(s);


		$(gmore).html(s);
				}
				}
			


				$(tmp + "_box").fadeIn("2300");
				$(tmp + "_status").html(visible);
				gmore = tmp;
			s = $(link).html().replace(open, close);
//alert(gmore);
			}
			else{

				$(tmp + "_box").hide();
				$(tmp + "_status").html(notvisible);
				gmore = tmp;
			s = $(link).html().replace(close, open);
			}
		$(link).html(s);
		}


		return gmore;
	
}


/*
$(document).ready(function() {

	var open='showmore.png';
	var close='showmoreclose.png';
	var open_init = '<img src="/kd/images/pg/' + open + '" width="16" height="16" />&nbsp;';
	//var open=" + ";
	//var close=" - ";
	//var open_init=" + ";
	var x = "span.showmore";
	var visible="V";
	var notvisible = "H";
	var gmore="";
	
	$(x).prepend("<span></span>");
	$(x).each(function() {
	//var tmp = $(this).attr("title");
	var tmp = $(this).html();
		var tmpid = $(this).attr("id");
		tmp = '<a href="#" style="text-decoration:none;">' + tmp + open_init + '</a>' + '<span style="display:none;" id="' + tmpid + '_status">' + notvisible + '</span>';
		$(this).html(tmp);
		$(this).show();
		//$(this).find("span").show().html(tmp); //save the text link in the span tag
		
		//$(this).attr({ title: ""});
//alert($(this).html());
//alert(tmpid);
	});


	$(x).click(function(){
		var s="";
		var tmp = $(this).attr("id");
		instantAction(tmp);
//alert(tmp);





		if( tmp != null ){
			tmp = "#" + tmp;
			var link = $(this).find("a");


			if( $(tmp + "_status").html() == notvisible ){

				if( gmore != "" ){
				if( $(gmore + "_status").html() == visible ){
					$(gmore + "_box").hide();
					$(gmore + "_status").html(notvisible);
			s = $(gmore).html().replace(close, open);
//alert(s);


		$(gmore).html(s);
				}
				}
			


				$(tmp + "_box").fadeIn("2300");
				$(tmp + "_status").html(visible);
				gmore = tmp;
			s = $(link).html().replace(open, close);
//alert(gmore);
			}
			else{

				$(tmp + "_box").hide();
				$(tmp + "_status").html(notvisible);
				gmore = tmp;
			s = $(link).html().replace(close, open);
			}
		$(link).html(s);
		}


		return false;
	});
});
*/


$(document).ready(function() {
		//var is_visible = false;
		var x;
		//var status;
		var tmp;
		var myid;
		var duration = 1000;


	//####################
	
	x = 'a.preview,a.clear';
	x += ',a.rptabuse';
	$(x).click(function(){
		myid = getClassID(this);
//alert("here" + myid);
		if( myid.length > 0 ){
		ckAction(myid);
		}
		
		return false;
	});
	
	//#################
	
	x = '.descrbold';	
	$(x).click(function(){
//alert("here");
		var myid="";
		var tmp = $(this).attr("id");
		var dbox = "";
		var txt = "";
		
		//alert(tmp);
		myid = "#" + tmp.replace("_bolddest", "");
		tmp = myid + "_boldbox"; 
		txt = $(tmp).val();
//alert(txt);
//alert(myid + "_input");
		dbox = $(myid + "_info").text();
		if( txt != null ){
			txt = '[b]' + txt + '[/b]';
		}
//alert(dbox);
		if( dbox != "" ){
			txt = $(dbox).val() + txt;
//alert(txt);
			$(dbox).val(txt);
		}
		//alert(txt);
		
		return false;
	});
	
	
	x = '.descrhplink';	
	$(x).click(function(){
//alert("here");
		var myid="";
		var tmp = $(this).attr("id");
		var dbox = "";
		var txt = "";
		var url = "";
		
		//alert(tmp);
		myid = "#" + tmp.replace("_hplinkdest", "");
		tmp = myid + "_hplinkbox"; 
		txt = $(tmp).val();
		tmp = tmp + "2";
		url = $(tmp).val();
		if(url.length > 7){
			var test = url.substr(0,7);
			var http = "http://";
			if( test != http ){
				url = http + url;
			}
		}
//alert(txt);
//alert(myid + "_input");
		dbox = $(myid + "_info").text();
//alert(dbox);
		if( dbox != "" ){
		if( txt != "" && (url.length > 8) ){
			//var href = 'url=' + url + '/';
			var href = 'url=' + url;
			txt = '[' + href + ']' + txt + '[/url]';
		
			txt = $(dbox).val() + "" + txt;
//alert(txt);
			$(dbox).val(txt);
		}
		}
		//alert(txt);
		
		return false;
	});

	
});





function getClassID(obj){
	//return id
		var tmp = $(obj).attr("class");
		var x = $(obj).attr("id");
//alert(tmp);
//alert(x);
	
		//var tmp = xclass;
		//var x = xid;
		
		var offset = tmp.length + 1;

		if( x.substr(0,offset) == (tmp + "_") ){
			x = x.substr(offset);
//alert(x);

		}
		else{
			return false;
		}
		
		if( x.length < 1 ){
			return false;
		}

		
		return x;
}






//#############################

//window.onload(myPopup("/"));
function myPopup(url) {
window.open( url, "myWindow", "status=no, height=390, width=300, scrollbars=yes, toolbar=no, locationbar=no, location=no, directories=no, menubar=no, resizable=1, copyhistory=no" );
//window.moveTo(w,0);
//window.onload(myPopup2("/im"));
}

function smallwin(url, w, h,windowname){
/*
//not work
window.innerWidth = 300;
window.innerHeight = 390;
window.screenX = screen.width;
window.screenY = screen.height;
alwaysLowered = true;
*/
//window.open( url, "myWindow", "status=no, height=" + h ", width=" + w + ", scrollbars=yes, toolbar=no, locationbar=no, location=no, directories=no, menubar=no, resizable=1, copyhistory=no" );

//window.resizeTo(w, h);
//window.moveTo(w,0);

		//window.focus();

//alert(window.innerWidth + ":" + window.screenX);
/*
var w = screen.width;
var h = screen.height;
alert("w=" + w + "::h=" + h);
*/

 var width  = w;
 var height = h;
 var left   = (screen.width  - width)/2;
 var top    = (screen.height - height)/2;
 var params = 'width='+width+', height='+height;
 params += ', top='+top+', left='+left;
 params += ', directories=no';
 params += ', location=no';
 params += ', menubar=no';
 params += ', resizable=yes';
 params += ', scrollbars=yes';
 params += ', status=no';
 params += ', toolbar=no';
 newwin=window.open(url,windowname, params);
 if (window.focus) {newwin.focus()}
 return false;


}


//return the difference in minutes between the user's computer and GMT (Greenwich Mean Time) time.
function getTzOffset(){
var Dt = new Date();
var tz = Dt.getTimezoneOffset();
return tz;
}

function getUtime(){
//alert("t");
var Dt = new Date();
//var tz = Dt.getTimezoneOffset();
//document.write('' + (Dt.getMonth() + 1) +"/"+Dt.getDate()+ "/"+Dt.getYear() + ' <br> ');
var H;
var i;
var s;
var period;
H = Dt.getHours();
/*
if (H >= 12) {
period = " P.M.";
}
else {
period = " A.M.";
}

if (H > 12) {
H -= 12;
}

if (H == 0) {
H = 12;
}
*/

if( H < 10 ){
	H = "0" + H;
}

i = Dt.getMinutes();

if (i < 10) {
i = "0" + i;
}

s = Dt.getSeconds();

if (s < 10) {
s = "0" + s;
}


var Y = Dt.getFullYear();
var m = Dt.getMonth();
if (m < 10) {
m = "0" + m;
}
var d = Dt.getDate();
if (d < 10) {
d = "0" + d;
}

var x = Y.toString() + m.toString() + d.toString();
var t = H.toString() + i.toString() + s.toString();
//alert(x + "\n" + t);
//document.write('<B>Todays Time:</b> ' + H + ":" + m + period + '');

//return Dt.getYear() + Dt.getDate() + Dt.getMonth() + " " + H + ":" + i + ":" + s + " " + period;
x = x + t;
return x;
}


//##########################

function createIndex(myid){
	var s;
	var tmp = $(myid).html();
//alert("xy" + tmp);
	if( tmp == null )
		return tmp;
		
	var pgindex = tmp.split(",");

//alert("hh" + pgindex[0]);
	for(var i=0;i<pgindex.length;i++){
		s = $.trim(pgindex[i]);
		if( s != null){
		pgindex[i] = s;
		}
	}

	return pgindex;
}

function getElmID(elm){
	var s;
	var pgindex = [];
	var i=0;
	
	$(elm).prepend("<span></span>");

	$(elm).each(function(){
		var tmpid = $(this).attr("id");
			s = $.trim(tmpid);
		if( s != "null" ){
//alert("here" + i);
			pgindex[i] = s;
//alert(pgindex[i]);
			i++;
		}
//alert(s);

	});
	
	return pgindex;
}

function createAlink(url, csname, i, label){
return '<a href="' + url + '" class="' + csname + '" id="' + i + '">' + label + '</a>';
}

function createVlink(csname, i, label){
return '<a href="#" class="' + csname + '" id="' + i + '">' +  label + '</a>';
}


//##########################


$(document).ready(function() {

	var pgindex = createIndex("#js_hzmenu");


	if( pgindex == null ){
		return false;
	}
//alert(pgindex);
	var barr = pgindex;


	//var flipduration = 100;
	var flipduration = 10;
	var x = '#hzmenu li';
	
	if( barr.length > 0 ){
	x = "";
	}
	else{
		barr[0] = "hzmenu";
	}
	for(var i=0; i<barr.length; i++){
		if( i > 0 ){
			x += ",";
		}

//alert(barr[i]);		
	var tmpid = '#' + barr[i] + ' li';
	x += tmpid;

	$(tmpid).prepend("<span></span>");
	
	$(tmpid).each(function() {

		var type = $(this).attr("class");
		var tmp = $(this).attr("id");

		if( tmp == "hzmenunone" ){
			$(this).find("span").stop().animate({ 
			marginTop: "-40"
			}, flipduration);		
		}

		var link = $(this).find("a").html(); //Find the text inside of the a tag
		$(this).find("span").show().html(link); //save the text link in the span tag
	});
	

tmp = "ul#" + barr[i];	//alert($(tmp).html());
	$(tmp).show();

	}
	

	//x='#hzmenu li,#hzmenu2 li
	var span_rem="";
	var rem="";
	var zmenuid="#zmenu_";
	var curr;
	$(x).hover(function() {
		var tmp="";


		$(this).find("span").stop().animate({marginTop: "-40"}, flipduration);

		//from current element travels up the top of the Dom tree.
		tmp = $(this).closest("ul").find("span");

//span class="n1" to save the curr tab
rem = $(tmp).attr("class");
span_rem = "span." + rem;


		curr=$(this).attr("id");
		$(span_rem).text(curr);
				
		curr = $(span_rem).text();

		$(x).each(function(){
		tmp = $(this).attr("id");
	
		if( curr != tmp && (! tmp.match(/hzmenunone/)) ){
		$(this).find("span").stop().animate({marginTop: "0"}, flipduration);
		$(zmenuid + tmp).hide();		
		}
		
		});
		

		$(zmenuid + curr).show();

	
		return false;

		
	}, function() {

		curr=$(this).attr("id");
		tmp = this;
		
		$("body").click(function(){
//alert($(this).attr("id"));
		$(zmenuid + curr).hide();
		
		$(tmp).find("span").stop().animate({marginTop: "0"}, flipduration);
		

			$("li#hzmenunone").find("span").stop().animate({ 
			marginTop: "-40"
			}, flipduration);
		
		});

		

		
		return false;


	});
	


});


//##########################

$(document).ready(function(){
//myid.match(/^clear\_createarticle\_/)
	var subm = "submitphotocaption_";
	
	$("." + subm).click(function(){
//alert("3");


		var tmp="";
		var myid = $(this).attr("id");
		var url = "." + myid + "_url";
		var itemid = myid.substr(subm.length);
		var imgid = "#photoid";
		//var captionid = "#caption" + itemid;
		//var tagsid = "#tagsid" + itemid;
	
		//tmp = $(photoid).val();
//alert(tmp);
/*
		if( tmp == null || tmp == "" ){
			return false;
		}
*/
//alert($(url).html());exit;
			$(imgid).attr("value", itemid);
			return true;

//return false;

	});

});

//##########################

/*
examples of using array:
	//var barr = ["swappage", "xswappage"];
	var carr = [];
		carr[i] = arr;
		arr.length: does not work.
//alert(carr[plink].curr);
//var plink = arr.plink;
*/
$(document).ready(function(){

	var alink_tag = "div";
	var alink_border = "1px solid #dedede";
	var vlink_border = "1px solid #000000";
	var alink = "#444444";
	var vlink = "#000000";


	
	var elm = "div.swappagecontent";
	var pgindex = getElmID(elm);

	//var pgindex = createIndex("#js_swappage");
	if( pgindex == null ){
		return false;
	}
//alert(pgindex);
	var barr = pgindex;
	var arr;
	var carr = [];
	
	var x = '#swapn1 a';

//alert(barr.length);	
	if( barr.length > 0 ){
	x = "";
	}
	else{
		barr[0] = "swpagen1";
	}
	for(var i=0; i<barr.length; i++){
//alert(i);
		if( i > 0 ){
			x += ",";
		}
	//#swapn1 p
	var tmpid = '#' + barr[i] + ' a';
	x += tmpid;

//alert(barr[i]);
	//var block = $(tmpid).closest("div").html();
//alert(block);
	arr = initSwappage(barr[i], alink, vlink);
//alert("h");	
		if( arr != null ){
		arr.alink_border = alink_border;
		arr.vlink_border = vlink_border;
		carr[i] = arr;
		
autorotateSwappage(arr);
		}

	}
	
//alert(x);	
	$(x).click(function(){

	var tmp = $(this).closest("div.swappagebegin");
	tmp = $(tmp).html();
//alert($(tmp).attr("id"));
	//index
	tmp = $(tmp).attr("id");

	for(var i=0; i<carr.length; i++){
//alert("c:" + carr[i].type);
			if( tmp == carr[i].pid ){
//alert("ma:");
				arr = carr[i];
				break;
			}
	}
	
	//alert("re:" + arr.length);
	//arr = carr[plink];alert(carr[plink].curr);
	if( arr != null ){
		arr.curr = processSwappage(this,arr);
	}	
		return false;
	});	

	$(x).hover(function(){
	alink_border="0px";
	//swimg
	var tmp = $(this).attr("class");
	processSwaptitle(tmp, $(this).text());
	tmp = $(this).closest(alink_tag);
//alert($(tmp).html());
		$(tmp).css("border", vlink_border);
		//$(this).css("border", vlink_border);
		//$(this).css("background-color", "#f0f0f0");
		

		return false;
 	}, function() {
	var tmp = $(this).attr("class");
	tmp = $(this).closest(alink_tag);
	$(tmp).css("border", vlink_border);
		//$(this).css("border", alink_border);
		return false;
	});
	
});


function processSwaptitle(swname, str){
var y1 = swname;
if( y1 == "" ){
	return;
}
//return;
//alert(y1);
	var y2 = "#" + y1 + "_swaptitle";
	var y2box = y2 + "box";
	if( str == null || str == "" ){
		str = null;
	}
	$(y2box).html(str);
}

function autorotateSwappage(a){

	if( a == null ){
		return;
	}
	
	var max = a.max;
	if( max <= 1 ){
		return;
	}

	var p = "#" + a.pid;
	//var pcontent = a.pcontent;
	var plink = a.plink;

	
	var pnext = plink + " a.next";


	var duration = 2000;

   var timeoutId = setInterval(function(){
	//autoswap
		a.curr = processSwappage(pnext, a);
		//return false;
   }, duration);
   //1000 millisecond = 1 sec.


   //stop the clock when this button is clicked
   $(p).hover(function(){
     clearInterval(timeoutId);
 	}, function() {

  timeoutId = setInterval(function(){
	//autoswap
		a.curr = processSwappage(pnext, a);
		//return false;
   }, duration);
	
	});

}



function processSwappage(obj, a){


/*
		var largePath = $(this).attr("href");
		var largeAlt = $(this).attr("title");
		
		//reset attr
		$("#largeImg").attr({ src: largePath, alt: largeAlt });
		
		$("h2 em").html(" (" + largeAlt + ")"); return false;
*/

	if( a == null ){
		return 0;
	}
	

	var p = "#" + a.pid;
	var swname = a.swname;
	var alink_csname = a.alink_csname;
	var plabels = a.plabels;
	var psrc = a.psrc;
	var curr = a.curr;
	var max = a.max;
	var pview = a.pview;
	var plink = a.plink;
	var vlink = a.vlink;
	var alink = a.alink;
	var vlink_border = a.vlink_border;
	var alink_border = a.alink_border;


		var action = $(obj).attr("class");
//alert(action);

	//not working: curr.match(/^\d+$/)
	if( (curr == null) ){
		curr = 0;
	}

//alert(curr);
//alert(max);

		var i=0;
		if( action == "prev" ){
		i = curr - 1;
		}
		else if( action == "next" ){
		i = curr + 1;
		}
		else{
			//action == "sw"

			i = $(obj).attr("id");
//alert("sw=" + i);
//alert($(plabels).html());
//alert($(obj).text());
		}
		
		if( i.length < 1 ){
			i = curr;
		}
		
		if( i < 0 ){ 
		i=0;
		i = max - 1; 
		}
		if( i >= max ){ 
		i=0; 
		//i=max - 1; 
		}
		
//alert("i=" + i + "::curr" + curr);

		//same page
		if( $(p + " span.rem").html() == i ){
			return curr;
		}
		//if( curr == i )
			//return curr;

		
//alert("kkkk=" + i);

	var update="";
	var loc=i;
	i=0;



	//var block = $(psrc).html();
	var block = $(psrc).find("div.src");
//alert(p);
	$(block).each(function() {
//alert(i + ":loc:" + loc + $(this).html());
	
		if( i == loc ){
			curr = i;
			update = $(this).html();
			
//alert(i + "=" + loc + "::found:" + update);
		//break out of the loop: it didn't break the loop???
		//return curr;	
		}
		i++;
	});	
//alert("done");
//alert(update);

	var sep=" &nbsp; ";
	var url="#";
	var csname=swname;
	var label="";
	var tmp="";
	i=0;
	
	var a_csname="a." + csname;
	//var a_csname="div.alink_" + alink_csname;
	var a_csname = alink_csname;

//alert(alink);
//alert(vlink);	
	//set selector elements. so do not use $(x).find("a.sw").html(). Just use the statement w/o .html().
	//var block = $(plink).find("a.sw");
var block = $(plink).find(a_csname);
//alert(block);
	$(block).each(function() {
	label = $(this).html();
//alert(label);


	if( i == loc ){
	/*
		tmp = label.replace(alink, vlink);
		$(this).html(tmp);
	*/
$(this).css("border", vlink_border);
//$(this).css("color", "#000000");
//$(this).css("background-color", "#ff0000");

//alert("m=" + $(this).html());
//alert(swname + ":" + p);
//alert($(this).text());
	processSwaptitle(swname, $(this).text());

	}
	else{
/* 
		tmp = label.replace(vlink, alink);
		$(this).html(tmp);
*/
    $(this).css("border", alink_border);	
	}
	
	i++;
	
	});



//#################

		var x = pview;
		
		$(x).hide();
		$(x).html(update);
		//$(x).fadeIn(1000);
		$(x).slideDown(800);

//$(plabels).html(curr);
	
	
		//$(p + " h2 em").html(" (" + curr + ")");
		$(p + " span.rem").html(curr);
//alert($(p + " span.rem").html());
		return curr;
}

function initSwappage(pid, alink, vlink){

//	var alink = "#0000ff";
//	var vlink = "#000000";
	
	var curr = 0;
	var p = "#" + pid;
//alert(p);
	var pview = p + " div.swappageview";
	var plink = p + " div.swappage";
	var plabels = p + " div.labels";
	var psrc = p + " div.swappagesrc";
	var swname = "sw";
	var sw_width = pid.substr(2);
//alert(pid);
	if( pid.substr(0,5) == "swimg" ){
		swname += "img";
		sw_width = pid.substr(5);
//alert(sw_width);
	}
	var csname=swname;
	var alink_csname="alink_" + csname;


	var pgindex2 = createIndex(plabels);
	if( pgindex2 == null )
		return pgindex2;


	
	var alink_open = '<span style="color:' + alink + ';text-decoration:none;">';
	var alink_close = '</span>';
	var lsstyle= '<div class="' + alink_csname + '" style="width:50px;float:left;padding:0px;border:0px solid #ff0000;background-color:#ffffff;">';
	var lsclose='</div>';
	var clearboth='<br style="clear:both;" /><br />';
	var sep = '<div style="float:left;padding:2px;">' + "" + '</div>';
	var url = "#";
	var label = "";
	var link_add="";
	var j=0;
	var block = $(psrc).find("div.src");
//alert(block);
	var tmp="";
	var row=1;
	var maxcol=4;
	var pagewidth="250px";
	var subtitle="";

	//maxcol for page link box;
	if( swname == "sw" ){
		//not img
		if( sw_width >= 300 ){
//alert(sw_width);
		maxcol=4;
		}
		else{
			maxcol=3;
			pagewidth="170px";
		}
	}
	
	
	$(block).each(function() {
	


//alert("h=" + $(this).html());
		tmp = $(this).html();


		label = pgindex2[j];
		label = createAlink(url, csname, j, alink_open + label + alink_close);


		if(j == curr){
		//curr = j;
		$(pview).html(tmp);
		subtitle = $(pview + " span.swaptitle").text();
		//$(label).css("border", "1px solid #000000");
		 //label = label.replace(alink, vlink);

		}


		label = lsstyle + label + lsclose;

		if( j == (row * maxcol) ){
			label = clearboth + label;
			row++;
		}
		
		if( j > 0 ){
			link_add += sep;
		}

		link_add += label;

		j++;


	});

	var max = j;
	
	var link="";
	var pagelink="";

	if( max > 0 ){
	link += link_add;
	link += clearboth;
	if( max > 1 ){
/*
	pagelink += lsstyle + createAlink(url, "prev", "y", alink_open + '&nbsp;&nbsp;&lt;&lt;&nbsp;&nbsp;' + alink_close) + lsclose;
	//pagelink += sep;
	lsstyle = lsstyle.replace('float:left;','float:right;');
	pagelink += lsstyle + createAlink(url, "next", "y", alink_open + '&nbsp;&nbsp;&gt;&gt;&nbsp;&nbsp;' + alink_close) + lsclose;
*/
lsstyle = lsstyle.replace('#ffffff;','#888888;');
	pagelink += lsstyle + createAlink(url, "prev", "y", alink_open + '<img src="/kd/images/pg/player_arrowl.png" vspace="5" hspace="5" />' + alink_close) + lsclose;
	lsstyle = lsstyle.replace('float:left;','float:right;');
	pagelink += lsstyle + createAlink(url, "next", "y", alink_open + '<img src="/kd/images/pg/player_arrowr.png" vspace="5" hspace="5" />' + alink_close) + lsclose;
	pagelink += clearboth;
	
	link = link + '<center style="border:0px solid #ff0000;padding:10px;width:150px;">' + pagelink + '</center>';

	}

	link = '<div style="padding:10px;width:' + pagewidth + ';">' + link + '</div>';
	

	//subtitle = getUtime();
	//subtitle = subtitle.substr(4,2) + "/" + subtitle.substr(6,2);
	//subtitle = "";
	link += '<div id="' + swname + '_swaptitlebox" style="position:relative;z-index:999;border:0px solid #ff0000;padding:5px;text-align:center;color:#ffffff;font-size:11px;font-weight:bold;">' + subtitle + '</div>';
	}


	//$(plink).append(sep + link);
	$(plink).append(link);
	
	//$(p + " h2").append('<em></em><span class="rem" style="display:none;">' + curr + '</span>');
	$(p + " span.rem").html(curr);
	
	alink_csname = 'div.' + alink_csname;
	return {pid:pid, swname:swname, alink_csname:alink_csname, plabels:plabels, psrc:psrc, curr:curr, max:max, pview:pview, plink:plink, vlink:vlink, alink:alink};

}


//######################