var Site = {
	
	init:function(){

		$("input").bind("focus", function(){
   		
   		var id = $(this).attr("id");
   		var hint = ($("[@for='"+id+"']").text());
   		
   		if ($(this).val() == hint){ 
   			$(this).val(''); 
   			$(this).bind("blur", function(){
   				if ($(this).val() == ""){ 
   					$(this).val(hint);
   				}
   			});
 			}
   	});
			
		
		$("textarea").bind("focus", function(){
   		
   		var id = $(this).attr("id");
   		var hint = ($("[@for='"+id+"']").text());
   		
   		if ($(this).text() == hint){ 
   			$(this).text(''); 
   			$(this).bind("blur", function(){
   				if ($(this).text() == ""){ 
   					$(this).text(hint);
   				}
   			});
 			}
   	});	
	
	} // End of Start.function
	
	
	
	
};	// End of site


/* Onload Functions 
---------------------------*/

$(document).ready(function(){
	Site.init();
	$("body#homepage #most-popular li div").addClass("imgthumb").wrap("<div class=\"imgwrap\"></div>");
	$("body#homepage #most-popular li div img").each(function() {
		var h =	$(this).height();
		var h = (103 - h) / 2;
		$(this).css({ marginTop: h });
	});
});

$(document).ready(function(){
	$('.btn').each(function(){
	var b = $(this);
	var tt = b.text() || b.val();
	if ($(':submit,:button',this)) {
	b = $('<a>').insertAfter(this). addClass(this.className).attr('id',this.id);
	$(this).remove();
	}
	b.text('').css({cursor:'pointer'}). prepend('<i></i>').append($('<span>').
	text(tt).append('<i></i><span></span>'));
	});
});

function isHidden(s) {
    var e = document.getElementById(s);
    return !e?true:e.style.display != "block";
}


function qsvalidate(sender){
										
	var strval =trimString(document.getElementById(sender).value);
	//alert(sender);	
	var fullStr = strval + " "; 
	var initial_whitespace_rExp = /^[^A-Za-z0-9]+/gi; 
	var left_trimmedStr = fullStr.replace(initial_whitespace_rExp, ""); 
	var non_alphanumerics_rExp = rExp = /[^A-Za-z0-9]+/gi; 
	var cleanedStr = left_trimmedStr.replace(non_alphanumerics_rExp, " "); 
	var splitString = cleanedStr.split(" "); 
	var word_count = splitString.length -1; 
	
	if (strval==null||strval=="" || strval=="Keyword: Type word/s to search for" || strval.length==0){
		alert("Please enter your search keyword!");
		document.getElementById(sender).value ="Keyword: Type word/s to search for";
		return false;
	} else {return true;}
}
function trimString (str) {
str = this != window? this : str;
return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
}

function qscountwords (sender) { 
	var strval = document.getElementById(sender).value;
	var fullStr = strval + " "; 
	var initial_whitespace_rExp = /^[^A-Za-z0-9]+/gi; 
	var left_trimmedStr = fullStr.replace(initial_whitespace_rExp, ""); 
	var non_alphanumerics_rExp = rExp = /[^A-Za-z0-9]+/gi; 
	var cleanedStr = left_trimmedStr.replace(non_alphanumerics_rExp, " "); 
	var splitString = cleanedStr.split(" "); 
	var word_count = splitString.length -1; 
	if (word_count > 3){
		alert("only 3 words allowed in your search");
		document.getElementById(sender).value ="";
		document.getElementById(sender).focus();				
	}
}

function catvalidate(sender){
										
	var strval =trimString(document.getElementById(sender).value);
	//alert(sender);	
	var fullStr = strval + " "; 
	var initial_whitespace_rExp = /^[^A-Za-z0-9]+/gi; 
	var left_trimmedStr = fullStr.replace(initial_whitespace_rExp, ""); 
	var non_alphanumerics_rExp = rExp = /[^A-Za-z0-9]+/gi; 
	var cleanedStr = left_trimmedStr.replace(non_alphanumerics_rExp, " "); 
	var splitString = cleanedStr.split(" "); 
	var word_count = splitString.length -1; 
	
	if (strval==null||strval=="" || strval=="Item Type: Type word/s to search for" || strval.length==0){
		alert("Please enter your search keyword!");
		document.getElementById(sender).value ="Item Type: Type word/s to search for";
		return false;
	} else {return true;}
}

function catcountwords (sender) { 
	var strval = document.getElementById(sender).value;
	var fullStr = strval + " "; 
	var initial_whitespace_rExp = /^[^A-Za-z0-9]+/gi; 
	var left_trimmedStr = fullStr.replace(initial_whitespace_rExp, ""); 
	var non_alphanumerics_rExp = rExp = /[^A-Za-z0-9]+/gi; 
	var cleanedStr = left_trimmedStr.replace(non_alphanumerics_rExp, " "); 
	var splitString = cleanedStr.split(" "); 
	var word_count = splitString.length -1; 
	if (word_count > 3){
		alert("only 3 words allowed in your search");
		document.getElementById(sender).value ="";
		document.getElementById(sender).focus();				
	}
}

function showContent() {
	$("#loader-row").hide();
	$("#content-row").show();
}