function showEmail(beforeAt, afterAt)
{
	return beforeAt + "@" + afterAt;
}

var starOn = new Image();

var starOff = new Image();

function writeStars(q, postId)
{
	starOn.src = "${contextPath}/templates/${templateName}/images/star_on.gif";
	starOff.src = "${contextPath}/templates/${templateName}/images/star_off.gif";
	
	for (var i = 0; i < 5; i++) {
		var name = "star" + postId + "_" + i;
		document.write("<img name='" + name + "' alt='*' />");
		document.images[name].src = q > i ? starOn.src : starOff.src;
	}
}
function writeNickels(q, src)
{
	//alert(src);
	//alert(nickel.src);
	//alert(q);
	if( q> 5)
	{
		document.write("<img name='nickel_1' alt='*' />");
		document.images['nickel_1'].src = src;
		document.write("...");
		document.write("<img name='nickel_2' alt='*' />");
		document.images['nickel_2'].src = src;
	}
	else if(q >0 && q <= 5)
	{
		for (var i = 0; i < q; i++) {
			//alert(i);
			var name = "nickel_'"+i;
			document.write("<img name='"+name+"' alt='*' src='"+src+"' />");
			//document.images[name].src = src;
		}
	}
}

function addBookmark(path, relationType, relationId)
{
	var w = window.open(path, 'bookmark_add', 'width=700, height=200, scrollbars=0, resizable=0');
	w.focus();
}

function supportAjax()
{
	if (typeof(AjaxUtils) != 'undefined') {
		if (window.ActiveXObject) {
			var r = new ActiveXObject("Microsoft.XMLHTTP");
			return r != undefined;
		}
		else if (window.XMLHttpRequest) {
			return true;
		}
	}

	return false;
}

function isValidEmail(who) 
{
	var email = new RegExp("^[A-Za-z0-9]+([_\.-][A-Za-z0-9]+)*@[A-Za-z0-9]+([_\.-][A-Za-z0-9]+)*\.([A-Za-z]){2,4}$","i");
	return(email.test(who));
}

function isValidUsername(who) 
{
	var name=new RegExp("^[A-Za-z0-9]+([_\.][A-Za-z0-9]+)*$","i");
	return(name.test(who));
}

function expandCollapseqod(name,path)
{
	s = document.getElementById("table_" + name);
	i = document.getElementById("image_" + name);

	if (s.style.display == 'none')
	{
		s.style.display = 'inline';
	   	i.src = path+"/nav_minus.gif";
	}
	else if (s.style.display == 'inline')
	{
		s.style.display = 'none';
	   	i.src = path+"/nav_plus.gif";
	}

}

function expandCollapseWithImageName(name,path,openedimage,closedimage)
{
	for(all=2;all<18;all++)
	{
		if(all!=name)
		{
			s = document.getElementById("table_" + all);
			i = document.getElementById("image_" + all);
			s.style.display = 'none';
			i.src = path+"/"+openedimage;
		}
	}
	s = document.getElementById("table_" + name);
	i = document.getElementById("image_" + name);
	if (s.style.display == 'none')
	{
		s.style.display = 'inline';
	   	i.src = path+"/"+closedimage;
	}
	else if (s.style.display == 'inline')
	{
		s.style.display = 'none';
	   	i.src = path+"/"+openedimage;
	}
}

function expandCollapse(name,path)
{
	expandCollapseWithImageName(name,path,'nav_plus.gif','nav_minus.gif')
}

function expandCollapseFolders(name,path)
{
	expandCollapseWithImageName(name,path,'folder.gif','folderOpen.gif')
}

function openFAQ(anchors)
{
    window.open("${contextPath}/templates/${templateName}/html/faqs.html#"+anchors,"FAQs","top=200,left=250,scrollbars=1,width=800,height=400,resizable=1");
}

function openFAQPath(path, anchors)
{
    window.open(path+"/html/faqs.html#"+anchors,"FAQs","top=200,left=250,scrollbars=1,width=800,height=400,resizable=1");
}

function openNewsRoom(path)
{
    window.open(path+"/html/press_13122006.html","goiit","top=200,left=250,scrollbars=1,width=360, height=700,resizable=0");
}

function sendDailyMailerToAll(path) 
{
	if (confirm("send daily mailer to everyone?")) {
		window.open(path, 'mailsent', 'width=750, height=400, scrollbars=0, resizable=1');
	}
}

function reloadAdvertisement(path) 
{
	if (confirm("Reload Advertisements?")) {
		window.open(path, 'ads_reloaded', 'width=750, height=400, scrollbars=0, resizable=1');
	}
}
function reloadProducts(path) 
{
	if (confirm("Reload Product Cache?")) {
		window.open(path, 'products_reloaded', 'width=750, height=400, scrollbars=0, resizable=1');
	}
}

function awardBoink(path)
{
	var wx = window.open(path, 'award_boink', 'width=700, height=200, scrollbars=0, resizable=0');
	wx.focus();
}

function awardBoinkSave(path) 
{
	if (confirm("comfirm sending the boink request to admin?")) {
		window.open(path, 'boink request sent', 'width=700, height=200, scrollbars=0, resizable=0');
	}
}

function viewResult(path)
{
	var wx = window.open(path, 'view_result', 'width=700, height=200, scrollbars=1, resizable=1');
	wx.focus();
}

function expandCollapseDiv(name,path)
{
	s = document.getElementById("table_" + name);
	i = document.getElementById("image_" + name);
	if (s.style.display == 'none')
	{
		s.style.display = 'inline';
	   	i.src = path+"/nav_minus.gif";
	}
	else if (s.style.display == 'inline')
	{
		s.style.display = 'none';
	   	i.src = path+"/nav_plus.gif";
	}

}

function emailPost(path)
{
	var w = window.open(path, 'email_link', 'width=620, height=270, scrollbars=0, resizable=0');
	w.focus();
}

function isInteger(val){
        if (isBlank(val)){return false;}
        for(var i=0;i<val.length;i++){
            if(!isDigit(val.charAt(i))){return false;}
        }
        return true;
    }

function isBlank(val){
    if(val==null){return true;}
    for(var i=0;i<val.length;i++) {
        if ((val.charAt(i)!=' ')&&(val.charAt(i)!="\t")&&(val.charAt(i)!="\n")&&(val.charAt(i)!="\r")){return false;}
    }
    return true;
}

function isDigit(num) {
    if (num.length>1){return false;}
    var string="1234567890";
    if (string.indexOf(num)!=-1){return true;}
    return false;
}

//Latest cut from header file and pasted here..
function validateEmailForm()
{	
	var f = document.getElementById("emailForm");
	if (f.email.value == "") 
	{
		alert("Yipeee!!...Please fill the Email Address field");
		f.email.focus();
		return false;
	}
	if(!isValidEmail(f.email.value))
	{
		alert("Yipess!...Email Address is not valid");
		f.email.focus();
		return false;
	}
}
function submitSearch()
{	
	var searchForm =document.getElementById('formSearch')
	searchForm.submit();	
}
function setSubscribe(divID, iState)
{
	if(document.layers)    //NN4+
	{
		document.layers[divID].visibility = iState ? "show" : "hide";
	}
	else if(document.getElementById)   //gecko(NN6) + IE 5+
	{
		var obj = document.getElementById(divID);
		obj.style.display = iState ? "block" : "none";
	}
	else if(document.all)    // IE 4
	{
		document.all[divID].style.visibility = iState ? "visible" : "hidden";
	}
}
function setBackText(tbText,defaultText) {
	 if ((tbText==null) || (tbText.value == "" ))
	  {
		 tbText.value = defaultText;
		 tbText.style.color ='#000000';
	 }
 }


function doClearText(tbText,defaultText) {
	 if (tbText.value == defaultText)
	  {
		 tbText.value = "";
	 }
 }

/***********************************************
* Drop Down/ Overlapping Content- © Dynamic Drive (www.dynamicdrive.com)
* This notice must stay intact for legal use.
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

function getposOffset(overlay, offsettype){
var totaloffset=(offsettype=="left")? overlay.offsetLeft : overlay.offsetTop;
var parentEl=overlay.offsetParent;
while (parentEl!=null){
totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
parentEl=parentEl.offsetParent;
}
return totaloffset;
}

function overlay(curobj, subobjstr, opt_position){
if (document.getElementById){
var subobj=document.getElementById(subobjstr)
subobj.style.display=(subobj.style.display!="block")? "block" : "none"
var xpos=getposOffset(curobj, "left")+((typeof opt_position!="undefined" && opt_position.indexOf("right")!=-1)? -(subobj.offsetWidth-curobj.offsetWidth) : 0) 
var ypos=getposOffset(curobj, "top")+((typeof opt_position!="undefined" && opt_position.indexOf("bottom")!=-1)? curobj.offsetHeight : 0)
subobj.style.left=xpos+"px"
subobj.style.top=ypos+"px"
return false
}
else
return true
}

function overlayclose(subobj){
document.getElementById(subobj).style.display="none"
}

function goToAnotherPage(max, recordsPerPage, contextPath, moduleName, action, id, extension)
{
	goToAnotherPageWithParam(max, recordsPerPage, contextPath, moduleName, action, id, extension, null);
}

function goToAnotherPageWithParam(max, recordsPerPage, contextPath, moduleName, action, id, extension, requestParams)
{
	var page = document.getElementById("pageToGo").value * 1;

	if (!isNaN(page) && page <= max && page > 0) {
		var path = contextPath + "/" + moduleName + "/" + action + "/" + ((page - 1) * recordsPerPage) + "/";
		
		if (id == '-1') {
			path += extension;
		}
		else {
			path += id + extension;
		}
		if(requestParams != null)
		{
			path += '?' + requestParams;
		}
		
		document.location = path;
	}
}

function goToAnotherPageSearch(max, recordsPerPage, baseUrl)
{
	var page = document.getElementById("pageToGo").value * 1;

	if (!isNaN(page) && page <= max && page > 0) {
		document.location = baseUrl + "&start=" + ((page - 1) * recordsPerPage);
	}
}

function changeVideoLocation(serverName)
{
	document.location = "http://"+serverName+"/"+document.getElementById('selectedVideoTag').value+".htm";
}

function disableItem( itemID, disabled )
{
    var color = ( (disabled)? "#999" : "#000" );
	var theItem = document.getElementById( itemID );
	if ( theItem != null ) {
		theItem.disabled = disabled;
		theItem.style.color = color;
	}
}
/* count remaining characters*/

charCount = 1;
maxCharCount = 2000;

function displayRemLength(fieldName) {
	remField = document.getElementById(fieldName);
	remField.innerHTML = (maxCharCount - charCount > 0) ? maxCharCount - charCount : 0;
}

function evalEntryLength(curField, maxLimit, discardXtra, errClass, normalClass) {
	maxCharCount = maxLimit;
	var fieldLength = getCharCount(curField);
	
	if (fieldLength > maxLimit) {
		if (errClass != "") {
			curField.className = errClass;
		}
		if (discardXtra) {
			showAllowedLength(curField, maxLimit);
		}
	} else if (normalClass != "") {
		curField.className = normalClass;
	}
}

function getCharCount(curField) {
	charCount = curField.value.length;
	
	return charCount;
}

function showAllowedLength(curField, maxLimit) {
	curField.value = curField.value.substr(0, maxLimit);
	window.status = curField.value;
}

function updateRateInfo(msg,id)
{
	var divID = document.getElementById("rateMsg_"+id);
	divID.style.display = 'inline';
	divID.innerHTML = '<span class=gensmall>'+msg+'</span>';
}
function cleanRateInfo(id)
{
	var msg = document.getElementById("rateMsg_"+id);
	msg.style.display = 'none';
}

