

/*
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;
	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;
	});
	
	
	$("li.bglink, div.bglink").mouseover(function(){
		$("a").css("text-decoration", "none");
		$(this).css("background-color", "#EAF3B1");
//$("li.textbox").css("background-color", "#EAF3B1");
	});
	
	$("li.bglink, div.bglink").mouseout(function(){
	var tmpbgid;
		if( $(this).attr("id") ){
			tmpbgid = $(this).attr("id");
		}
		else{
			tmpbgid = "#ffffff";
		}
		//$(this).css("background-color", "#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 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;
		}
}




/*
//not use
function processConfirm(str){
//alert(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;
		}
}
*/	

//############################


//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;
 
	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 span.preview').click(function(){
		//tmp = '<div style="background:#f0f0f0;">' + "xxx" + '</div>';
		myid = getClassID(this);
//alert(myid);
		if( myid.length > 0 ){
		ckAction(myid);
		}
		
		return false;
	});
	

/*	
	$('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";
	if( exists(a) ){
		s="/q?aid=" + $("#aid").text() + "&m=xq";
	}
return s;

}

//#########################

function ckAction(myid){

	var loc=KDxq();
	var s;
	var x;
	var tmp;

//alert("ckAction=" + myid);
	if( myid.substr(0,8) == "savebuzz" ){
//alert("savebuzz=" + myid);
		if( loc != "" ){
			x = "#" + myid;
			loc = loc + "&pageurl=" + $("#pageurl").text();
			s = loc + "&w=savebuzz&itopic=" + $("#itopic").text();
			$(x).load(s);
			$(x).show();
			$("#show_" + myid).hide();
//alert(s);
//alert($(x).html());
		}
	}

	
	else if( myid.match(/^createbuzz\_/) ){
		if( loc != "" ){
			tmp = "";
			tmp = $("#comment").val();
			tmp.replace(/^\s+|\s+$/, '');
//alert("tmp=" + tmp);
			if( tmp.length > 0 ){
			x = "#slide_" + myid;
			loc = loc + "&pageurl=" + $("#pageurl").text();
			s = loc + "&w=createbuzz&itopic=" + $("#itopic").text();

//http://api.jquery.com/jQuery.post/
$.post(s, {text: tmp}, function(data){
   //alert("Data Loaded: " + data);
   $(x).html($.trim(data));
 });

			}
		}
	}
	else{
	}

}


//#############################


$(document).ready(function() {
		//var is_visible = false;
		var x;
		var status;
		var tmp;
		var slide = "#" + "slide_";
		var myid;
		
	$('a.close,a.show').click(function(){
		//tmp = $(this).attr("class");
		//alert(tmp);
		//x = $(this).attr("id");
//myid = getClassID(tmp, x);
		myid = getClassID(this);
		if( myid.length < 1 )
			return false;
		x = slide + myid;
//alert(x);
		status = x + "_status";		
		if( tmp == "close" ){
			$(status).html("H");
			$(x).hide();
		}
		else{
			//$(x).show('fast');

		if( $(status).html() != "V" ){
			$(status).html("V");
			$(x).show('fast');
			ckAction(myid);
		}
		else{
			$(status).html("H");
			$(x).hide();
		}			
			
		}
		
		//remain the same page
		return false;
	});
	

	$('a.over').click(function(){
		return false;
	});


	//need to retest
	$('a.over').hover(function() {
		myid = getClassID(this);
		if( myid.length < 1 )
			return false;
		x = slide + myid;
		$(x).show('fast');
		
		ckAction(myid);
		return false;

	}, function() {
		tmp = $(this).attr("class");
		if( tmp != "over" ){
			return false;
		}
		myid = getClassID(this);
		x = slide + myid;
		if( myid.length > 0 )
			$(x).hide();
		return false;
			
	});


});


function getClassID(obj){
	
		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 false;		
		//x = "#" + "slide_" + x;
		
		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;
}

