function showpageinwawindow(url)
{
	window.open(url,"wa");
}

function ValidatorTrim(s) {
    var m = s.match(/^\s*(\S+(\s+\S+)*)\s*$/);
    return (m == null) ? "" : m[1];
}

function checkvalidscreenname(alphane)
{
	var str = alphane;
	for(var j=0; j<str.length; j++)
	{
		var alphaa = str.charAt(j);
		var chrcode = alphaa.charCodeAt(0);
		if((chrcode > 47 && chrcode<59) || (chrcode > 64 && chrcode<91) || (chrcode > 96 && chrcode<123) || chrcode==95)
		{
		}
		else
		{
			return false;
		}
	}
	return true;
}

var dtCh= "-";
var minYear=1950;
var maxYear=2050;
function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 2; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : mm-dd-yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date")
		return false
	}
return true
}

function checkEmail(strng)
{
	var error = "";
	if (strng == "") 
		{
		error = "You didn't enter an email-address.\n";
		}
	var emailFilter=/^.+@.+\..{2,3}$/;
	if (!(emailFilter.test(strng))) 
		{ 
		error = "Please enter a valid email address.\n";
		}
	var illegalChars= /[\(\)\<\>\,\;\:\\\/\"\[\]]/;
	if (strng.match(illegalChars))
		{
		error = "The email address contains illegal characters.\n";
		}
	return error;
}

function openbenzwin()
{
	var h,w;
  	h = screen.height;
  	w = screen.width;
  	var l,t;
  	l = parseInt((w-550)/2);
  	t = parseInt((h-450)/2);
  	window.open("wabenz.php","WABenz","toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=584,height=450,left="+l+",top="+t);
}

function chkselectedids(formname,objname)
{
	var chkflg,strmessageid,url,returl;
	strmessageid="";
	chkflg=false;
	for(j=0; j<document.forms.length;j++)
	{
		if(document.forms[j].name==formname)
		{
			for (i=0;i<document.forms[j].elements.length;i++)
			{
				if (document.forms[j].elements[i].name==objname) 
				{
					if (document.forms[j].elements[i].checked)
					{							
						chkflg=true;
						break;
					}
				}
			}			
		}	
	}
	return chkflg;	
}
function addbookmark()
{
	bookmarkurl="http://www.judged.com/";
	bookmarktitle="JUDGED";
	if (document.all)
		window.external.AddFavorite(bookmarkurl,bookmarktitle);
	if (window.sidebar) // firefox
		window.sidebar.addPanel(bookmarktitle, bookmarkurl,"");	
}

/*******************************************************************************/
//added by Nitin
//purpose: creates modaldialog for passed url
var ModalDialogWindow;
var ModalDialogInterval;
var ModalDialog = new Object;
ModalDialog.value = '';
ModalDialog.eventhandler = '';

function popupModalDialog(popupurl,width,height)
{
	if(typeof(width)=='undefined') width=500;
	if(typeof(height)=='undefined') height=500;

	if(window.showModalDialog)
	{
		window.showModalDialog(popupurl,window,'width='+width+',height='+height+',scrollbars=yes,location=no,status=no');
	}
	else
	{
		ModalDialogWindow=window.open(popupurl,window,'width='+width+',height='+height+',scrollbars=yes,location=no,status=no');
		ModalDialogInterval = window.setInterval("ModalDialogMaintainFocus()",1);
	}
}

function ModalDialogMaintainFocus()
{
	try
	{
		if (ModalDialogWindow.closed)
		{
			window.clearInterval(ModalDialogInterval);
			return;
		}
		ModalDialogWindow.focus();
	}
	catch (everything) {   }
}

function isInt(varvalue)
{
	var regexpINT = /\D/;
	return !regexpINT.test(varvalue);
}

function srchfirmvalidation(form)
{           
	var err="";
    if (ValidatorTrim(form.clswasearch_searchvalue.value)=="") err+="Search text is required field.\n";
    if (err!="") 
    {
		alert(err);
        form.clswasearch_searchvalue.focus();
        return false;
    }
    return true;
}

function srchvalidation(form)
{
	var err="";
	if(ValidatorTrim(form.clswasearch_keywords.value)=="" && ValidatorTrim(form.clswasearch_begindate.value)=="" && ValidatorTrim(form.clswasearch_enddate.value)=="" && ValidatorTrim(form.clswasearch_screenname.value)=="")
	err+="Some Search criteria is required \n";
	
	if (err!=""){
		alert(err);
		return false;
	}
	else
	{
		if( form.clswasearch_begindate.value != "")
		{
			if(isDate(form.clswasearch_begindate.value)==false)
			{
				form.clswasearch_begindate.focus();
				return false;
			}
		}
		if( form.clswasearch_enddate.value != "")
		{		
			if(isDate(form.clswasearch_enddate.value)==false)
			{
				form.clswasearch_enddate.focus();	
				return false;
			}
		}
		form.clswasearch_hdnaction.value="Search";
		return true;
	}
}

var expDays = 14; // number of days the cookie should last
var page = "http://www.judged.com/jdexitpopup.php";
var windowprops = "width=400,height=130,location=no,toolbar=no,menubar=no,scrollbars=yes,resizable=yes";

function GetCookie (name) {
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen) {
var j = i + alen;
if (document.cookie.substring(i, j) == arg)
return getCookieVal (j);
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
}
return null;
}
function SetCookie (name, value) {
var argv = SetCookie.arguments;
var argc = SetCookie.arguments.length;
var expires = (argc > 2) ? argv[2] : null;
var path = (argc > 3) ? argv[3] : null;
var domain = (argc > 4) ? argv[4] : null;
var secure = (argc > 5) ? argv[5] : false;
document.cookie = name + "=" + escape (value) +
((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
((path == null) ? "" : ("; path=" + path)) +
((domain == null) ? "" : ("; domain=" + domain)) +
((secure == true) ? "; secure" : "");
}
function DeleteCookie (name) {
var exp = new Date();
exp.setTime (exp.getTime() - 1);
var cval = GetCookie (name);
document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}
var exp = new Date();
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));
function amt(){
var count = GetCookie('count')
if(count == null) {
SetCookie('count','1')
return 1
}
else {
var newcount = parseInt(count) + 1;
DeleteCookie('count')
SetCookie('count',newcount,exp)
return count
}
}
function getCookieVal(offset) {
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}

function checkCount() {
var count = GetCookie('count');
if (count == null) {
count=1;
SetCookie('count', count, exp);

window.open(page, "", windowprops);

}
else {
count++;
SetCookie('count', count, exp);
}
}

window.onunload = checkCount