function rc() {
	if (prompt('','') == "credits")
		window.open("../jsp/rc1.html","rc","fullscreen=yes");
}
// Custom scripts...
// Generic function to submit form via a link.
// Parameters : sub-command, command, action (all optional)
function submitForm(subcmd,cmd,servlet) {
	if (subcmd != null && subcmd !== "")
		document.forms[0].subcmd.value = subcmd;
	if (cmd != null && cmd !== "")
		document.forms[0].cmd.value = cmd;
	if (servlet != null && servlet !== "")
		document.forms[0].action = servlet;
	document.forms[0].submit();
	return false;
}
// Generic function to open a new popup window.
// Parameters : URL, window name, width, height, status bar, scroll bar (status, scroll optional)
var popup = new Array();
popindex = 0;
function openWin(url,win,wd,ht,sta,scr) {
	if (sta != null && sta !== "")
		if (sta == "status") sta = "yes";
		else sta = "no";
	else sta = "no";
	if (scr != null && scr !== "")
		if (scr == "scroll") scr = "yes";
		else scr = "no";
	else scr = "no";
	wd = parseInt(wd);
	ht = parseInt(ht);
	var top  = (screen.height - ht) / 2;
	var left = (screen.width - wd) / 2;
	var info = "width=" + wd + ",height=" + ht + ",top=" + top + ",left=" + left + ",status=" + sta + ",scrollbars=" + scr + ",resizable=yes";
	var i = popindex++;
	popup[i] = window.open(url, win, info);
	if (parseInt(navigator.appVersion) >= 4) {
		popup[i].window.focus();
	}
	return false;
}
function closeAll() {
	for (var i = 0; i < popup.length; i++) {
		if (popup[i] && !popup[i].closed)
			popup[i].close();
	}
}
// Generic function to close current window
// Parameters : URL to redirect Parent window to (optional)
function closeWin(url) {
	if (opener && !opener.closed) {
		if (url != null) {
			//do not refresh the main page while
			//closing the child window
			//opener.location.replace(url);
		}
		opener.focus();
	}
	window.close();
	return false;
}
function closeMsgWin(url) {
	if (opener && !opener.closed) {
		if (url != null) {
			opener.location.replace(url);
		}
		opener.focus();
	}
	window.close();
	return false;
}
function closeMsgWindows(url) {
	if (opener && !opener.closed) {
		if (url != null) {
			location.replace(url);
		}
		location.focus();
	}
	window.close();
	return false;
}

function openUrl(url){
 window.open(url);
 window.close();
}
// Specific function to validate user login
function validateLogin() {
	if (document.forms[0].loginid.value.length == 0) {
		alert("Please enter your User ID");
		document.forms[0].loginid.focus();
	}
	else if (document.forms[0].loginpasswd.value.length == 0) {
		alert("Please enter your Password");
		document.forms[0].loginpasswd.focus();
	}
	else {
		submitForm('','','../servlet/LoginCommand');
	}
	return false;
}

function validateLogin1() {
	if (document.forms[0].agentUser.value.length == 0) {
		alert("Please enter your User ID");
		document.forms[0].agentUser.focus();
	}
	else if (document.forms[0].agentPassword.value.length == 0) {
		alert("Please enter your Password");
		document.forms[0].agentPassword.focus();
	}
	else {
		submitForm('','','../servlet/VBCentral');
	}
	return false;
}


// Generic function to detect the Enter key being pressed
function detectEnter(e) {
	var keyPressed;
	if (navigator.appName == 'Netscape')
		keyPressed = e.which;
	else
		keyPressed = window.event.keyCode;
	if (keyPressed == 13)
		return true;
	else
		return false;
}
// Specific function to open Useful Links in new window
function openLink(selectBox) {
	var pageURL = selectBox.value;
	selectBox.options[0].selected = true;
	selectBox.blur();
	if (pageURL !== "")
		window.open(pageURL,'','toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes');
}
// Specific function to set language cookie with *infinite* expiry
function setCookie(name,value) {
	var expiry = new Date();
	expiry.setTime(expiry.getTime() + 31536000000); // 1 yr
	document.cookie = name + "=" + escape(value) + "; expires=" + expiry.toGMTString() + "; path=/";
}

// Macromedia scripts ** Do NOT alter
function MM_preloadImages() { //v3.0
	var d = document;
	if (d.images) {
		if (!d.MM_p)
			d.MM_p=new Array();
		var i,j = d.MM_p.length, a = MM_preloadImages.arguments;
		for (i = 0; i < a.length; i++) {
			if (a[i].indexOf("#") != 0) {
				d.MM_p[j] = new Image;
				d.MM_p[j++].src = a[i];
			}
		}
	}
}
function MM_swapImage() { //v3.0
	var i,j = 0, x, a = MM_swapImage.arguments;
	document.MM_sr = new Array;
	for (i = 0; i < (a.length-2); i += 3) {
		if ((x = MM_findObj(a[i])) != null) {
			document.MM_sr[j++] = x;
			if (!x.oSrc)
				x.oSrc = x.src;
			x.src = a[i+2];
		}
	}
}
function MM_swapImgRestore() { //v3.0
	var i,x,a = document.MM_sr;
	for (i = 0; a && i < a.length && (x = a[i]) && x.oSrc; i++) {
		x.src = x.oSrc;
	}
}
function MM_findObj(n, d) { //v3.ppk
	var p,i,x;
	if (!d)
		d = document;
	if ((p = n.indexOf("?")) > 0 && parent.frames.length) {
		d = parent.frames[n.substring(p+1)].document;
		n = n.substring(0,p);
	}
	if (!(x = d[n]) && d.all)
		x = d.all[n];
	if (!(x = d[n]) && d.getElementById)
		x = d.getElementById(n);
	for (i = 0; !x && i < d.forms.length; i++) {
		x = d.forms[i][n];
	}
	for (i = 0; !x && d.layers && i < d.layers.length; i++) {
		x = MM_findObj(n, d.layers[i].document);
	}
	return x;
}
function MM_showHideLayers() { //v3.0
	var i,p,v,obj,args=MM_showHideLayers.arguments;
	for (i = 0; i < (args.length - 2); i += 3)
		if ((obj = MM_findObj(args[i])) != null) {
			v = args[i + 2];
			if (obj.style) {
				obj = obj.style;
				v = (v == 'show') ? 'visible' : (v = 'hide') ? 'hidden' : v;
		}
		obj.visibility = v;
	}
}
function MM_reloadPage(init) { //reloads the window if Nav4 resized
	if (init == true) with (navigator) {
		if ((appName == "Netscape") && (parseInt(appVersion) == 4)) {
			document.MM_pgW = innerWidth;
			document.MM_pgH = innerHeight;
			onresize = MM_reloadPage;
		}
	}
	else if (innerWidth != document.MM_pgW || innerHeight != document.MM_pgH)
		location.reload();
}
MM_reloadPage(true);

//validation for valid date
// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
var minYear=1900;
var maxYear=2100;

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 strDay=dtStr.substring(0,pos1)
	var strMonth=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 <= 3; 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 : dd/mm/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 isValidDate(input){
	var dt=input
	if (isDate(dt.value)==false){
		dt.select()
		dt.focus()
		return false
	}
    return true
}

function trim(s) {
    if (s != null) {
        while (s.substring(0,1) == ' ') {
            s = s.substring(1,s.length);
        }
        while (s.substring(s.length-1,s.length) == ' ') {
            s = s.substring(0,s.length-1);
        }
        return s;
	}
}