	var strSeparator = " $$$$$$ ";

Checker.prototype.checkYearMonth = function(input, msg)
{
	var val  = this.valueOf(input)
	var yyyy = parseInt(val / 100)
	var mm   = a0(val % 100)
	var y0   = new Date().getFullYear()
	var m0   = new Date().getMonth() + 1

	if (val && (yyyy > y0 || (yyyy == y0 && mm > m0)))
		return this.appendErr(input, msg);

	return true;
}

//this function is to select a row
function clickRow(row){
	var tableRow = row.parentNode.childNodes;
	if(tableRow.length==null){
		tableRow.style.backgroundColor="";
	}else{
		for(i=0;i<tableRow.length;i++){
			tableRow[i].style.backgroundColor="";
		}
	}

	row.style.backgroundColor="#cccc66";
}

function assignFormValue(frm, values)
{
	var pairs = values.split("\t")

	for (var i in pairs)
	{
		var nvp = pairs[i].split("=")
		f.elements[nvp[0]].value = nvp[1]
	}
}

// <!-- Preview
document.write('<div id=previewDiv style="display:none; z-index:110; position:absolute; border:#000 1px solid; background:#fff; overflow:hidden;"></div>');

function showPreview(url, title, w, h)
{
	timer = setTimeout("openPreview('"+url+"','"+title+"',"+w+","+h+");", 200);
}

function hidePreview()
{
	clearTimeout(timer);
	gE("previewDiv").style.display= "none";
	document.onmousemove = _mouseoverHdlr
}

var offsetfrommouse=[8,8]; //image x,y offsets from cursor position in pixels. Enter 0,0 for no offset
var timer=null
var _mouseoverHdlr=null

function truebody(){
	return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function openPreview(url, title, width, height)
{
	var docwidth  = document.all ? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth - offsetfrommouse[0]
	var docheight = document.all ? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(window.innerHeight)

	if( (navigator.userAgent.indexOf("Konqueror")==-1  || navigator.userAgent.indexOf("Firefox")!=-1 || (navigator.userAgent.indexOf("Opera")==-1 && navigator.appVersion.indexOf("MSIE")!=-1)) && (docwidth>width && docheight>height))
	{
		var dv = gE("previewDiv")
		dv.innerHTML = '<iframe id="previewIfm" name="previewIfm" scrolling="no" frameborder="0" style="width:100%; height:100%;"></iframe>';
		dv.maxW = width+20
		dv.maxH = height+20
		dv.style.width = dv.maxW+"px"
		dv.style.height = dv.maxH+"px"
		gE("previewIfm").src=url;
		_mouseoverHdlr = document.onmousemove
		document.onmousemove=followmouse;
	}
}

function followmouse(e)
{
	var x = offsetfrommouse[0]
	var y = offsetfrommouse[1]
	var dv = gE("previewDiv")
	var maxW = dv.maxW
	var maxH = dv.maxH

	var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15
	var docheight=document.all? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(window.innerHeight)

	if (typeof e != "undefined")
	{
		if (docwidth - e.pageX < maxW + 2*x)
			x = e.pageX - x - maxW; // Move to the left side of the cursor
		else
			x += e.pageX;

		if (docheight - e.pageY < maxH + 2*y)
			y += e.pageY - Math.max(0,(2*y + maxH + e.pageY - docheight - truebody().scrollTop));
		else
			y += e.pageY;
	}
	else if (typeof window.event != "undefined")
	{
		if (docwidth - event.clientX < maxW + 2*x)
			x = event.clientX + truebody().scrollLeft - x - maxW; // Move to the left side of the cursor
		else
			x += truebody().scrollLeft+event.clientX

		if (docheight - event.clientY < (maxH + 2*y))
			y += event.clientY + truebody().scrollTop - Math.max(0,(2*y + maxH + event.clientY - docheight));
		else
			y += truebody().scrollTop + event.clientY;
	}

	dv.style.display = "block";
	dv.style.left=x+"px"
	dv.style.top=y+"px"
}
// Preview -->




/* Bookmark functions */
function bookmarkA(id)
{
	ajaxInvoke(JS_BASEPATH + "/myaccount/_controller.jsp?act=addAdvertiser&id=" + id)
}
function bookmarkC(id)
{
	ajaxInvoke(JS_BASEPATH + "/myaccount/_controller.jsp?act=addCampaign&id=" + id)
}
function bookmarkP(id)
{
	ajaxInvoke(JS_BASEPATH + "/myaccount/_controller.jsp?act=addPublisher&id=" + id)
}
function removeA(id)
{
	if (id && confirm('Are you sure you want to remove the selected Advertisers?'))
		ajaxInvoke(JS_BASEPATH + "/myaccount/_controller.jsp?act=removeAdvertiser&IDs=" + id)
}
function removeC(id)
{
	if (id && confirm('Are you sure you want to remove the selected Campaigns?'))
		ajaxInvoke(JS_BASEPATH + "/myaccount/_controller.jsp?act=removeCampaign&IDs=" + id)
}
function removeP(id)
{
	if (id && confirm('Are you sure you want to remove the selected Publishers?'))
		ajaxInvoke(JS_BASEPATH + "/myaccount/_controller.jsp?act=removePublisher&IDs=" + id)
}
function saveQuery(qry, typ)
{
	ajaxDialog(JS_BASEPATH + "/dialog/save_query.jsp?queryString=" + escape(qry) + "&queryType=" + typ, null, 340, 200)
}
function removeSQ(id)
{
	if (id && confirm('Are you sure you want to remove the selected saved queries?'))
		ajaxInvoke(JS_BASEPATH + "/myaccount/_controller.jsp?act=removeSavedQuery&IDs=" + id)
}



/* export / download excel */
function excelDownload(act, fileName, params){
	gE('ifDl').src = "_controller.jsp?act=" + act + "&saveAs=" + fileName + "&" + params
}
/* printer-friendly */
function printerFriendly(frm){
	var f = document.createElement("form")
	f.action = (location.href + "").replace(/(\.jsp)/, "-print.jsp")
	f.method="post"
	document.body.appendChild(f);

	frm = frm || document.forms.form1
	if (frm)
		f.innerHTML = frm.innerHTML

	f.submit()
}



/* select item for comparing */
function openSelectedDv(typ, bool)
{
	var dv = $("#selectedDv")

	if (bool || dv.css("display") == "none")
	{
		dv.animate({width: "360px", height: "100%", opacity: 1}, 600)
		typ = typ || "A"
		ajaxInclude(JS_BASEPATH + "/myaccount/ajax_loadSelected" + typ + ".jsp?IDs=" + unescape(getCookie("SELECTED-" + typ)), "selectedDv")
	}
	else
		dv.width(0).height(0).css("opacity",0).hide()
}
function deselect(typ, id)
{
	var arr = unescape(getCookie("SELECTED-"+typ) || "").split(",")
	var j = $.inArray(id, arr)

	if (j >= 0)
		arr.splice(j, 1);

	setCookie("SELECTED-"+typ, arr.join(","))
	$("#tr_"+id).hide()
}
function compareNow(obj, name)
{
	var cnt = countSelected(obj)

	if (cnt < 2)
		alert("Sorry, you must select at least 2 " + name + "s to compare.");
	else if (cnt > 5)
		alert("Sorry, you can select max. 5 " + name + "s to compare.");
	else
		jumpTo(JS_BASEPATH + "/" + name + "/compare.jsp?IDs=" + v(obj))
}



/* global css fix */
$(function(){
	$("input[type='checkbox'], input[type='radio']").css("cursor", "pointer")
	$(".data-table .clickable").bind("click", function(e){
		e = (e.srcElement || e.target).firstChild

		if (e.click)
			e.click()
		else
			location.href = e.href
	})
})



// dialogbox.tag
_last_selected = new Object()
function selectRow(obj, id, val)
{
	if (id)
	{
		_last_selected.id = id
		_last_selected.name = val
	}

	if (obj.parentNode._sel)
		obj.parentNode._sel.style.backgroundColor = '';

	(obj.parentNode._sel = obj).style.backgroundColor = '#ccc'
}

function switchTab(obj, tabGroup, id)
{
	$(obj).addClass("tab88on").parent().find("div").not(obj).removeClass("tab88on")
	$("#" + tabGroup + " > .tabpage").hide().eq(id - 1).show()
}
function lightbox(URL)
{
	if (!gE("ajaxdyndiv"))
		$("<div id=ajaxdyndiv style=position:absolute;top:0;left:0;z-index:99;display:none></div>").appendTo(document.body)

	waitforinput(true)
	$("#ajaxdyndiv").html("<img class='lightbox' src='"+URL+"' onclick='waitforinput(0); $(\"#ajaxdyndiv\").hide()' onload='this.parentNode.style.display = \"block\"; this.parentNode.style.left = truebody().scrollLeft + (($.browser.msie ? document.documentElement.offsetWidth : window.innerWidth) - this.width) / 2 + \"px\"; this.parentNode.style.top = truebody().scrollTop + (($.browser.msie ? document.documentElement.offsetHeight : window.innerHeight) - this.height) / 2 + \"px\"'>")
}

function shorterThan() // length, arg1, arg2, arg3...
{
	for(var i=1, l=arguments[0]; i<arguments.length; i++)
		if ($(arguments[i]).val().length >= l) return 0

	return 1
}

MSG_LIMIT_TO_100_RECORD                  = "Please input at least 3 characters in either Advertiser/Publisher Name, Domain or Campaign Keywords field for more accurate search. We will limit the search result to 100 records this time."
MSG_THESE_FIELDS_ARE_TOO_SHORT_FOR_QUERY = "Please input at least 2 characters in either Advertiser/Publisher Name, Domain or Campaign Keywords field for more accurate search and try again."
