function setOtherHiddenFields(event, val) {
}

function doSubmit(pageEvent) {
    doSubmitWithDisabledButtons(pageEvent, null);
}

function doSubmit(pageEvent, val) {
    doSubmitWithDisabledButtons(pageEvent, val);
}

function doSubmitWithDisabledButtons(event, val) {
	var form = document.forms[0];
	var disabledButtons = true;

	setOtherHiddenFields(event, val);

	if(event == "confirmAdd"){
		if(!confirmConfirmAdd("")){
			return false;	
		}
	}

	if (event == "exit" ) {

//		if (!confirmExit("")) {
//			return false;
//		}
	}

	if(event == "delete"){
		if(!confirmDelete("")){
			return false;
		}
	}
	
	if((event != null) && ((event.substring(0, 6) == "export") || (event.substring(0, 8) == "download") || (event.substring(0, 5) == "print"))) {
		disabledButtons = false;
	}

	if(disabledButtons){
		var sItems = document.getElementsByTagName('input');

		for (i=0; i< sItems.length; i++) {
			if (sItems[i].type == 'button') {
				sItems[i].disabled = true;
			}
		}
	}

	document.forms[0].pageEvent.value = event;
	if (val != null) {
		document.forms[0].pageEventSrc.value = val;
	}
	document.forms[0].submit();
}

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);

function MM_findObj(n, d) { //v4.01
	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]; 
	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);
	if(!x && d.getElementById) 
		x=d.getElementById(n); 
	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_goToURL() { //v3.0
	var i, args=MM_goToURL.arguments; 
	document.MM_returnValue = false;
	for (i=0; i<(args.length-1); i+=2) 
		eval(args[i]+".location='"+args[i+1]+"'");
}

function showMenu(mno) {
	var eMenu = document.getElementById('Layer'+mno);
	eMenu.style.visibility = 'visible';
	var sItems = document.getElementsByTagName('SELECT');
	for (i=0; i<sItems.length; i++) {
		if (isOverLap(sItems[i],eMenu))
			sItems[i].style.visibility = 'hidden';
	}
}

function hideMenu(mno) {
	var eMenu = document.getElementById('Layer'+mno);
	eMenu.style.visibility = 'hidden';
	var sItems = document.getElementsByTagName('SELECT');
	for (i=0; i<sItems.length; i++) {
		if (sItems[i].style.visibility == 'hidden')
			sItems[i].style.visibility = 'visible';
	}
}

function isOverLap(ele,sMenu) {
	var left = 0;
	var top = 0;
	var width = ele.offsetWidth;
	var height = ele.offsetHeight;
	while (ele) {
		left += ele.offsetLeft;
		top += ele.offsetTop;
		ele = ele.offsetParent;
	}
	sLeft = sMenu.offsetParent.offsetLeft+sMenu.offsetLeft;
	sRight = sLeft + sMenu.offsetWidth;
	sTop = sMenu.offsetParent.offsetTop+sMenu.offsetTop;
	sBottom = sTop + sMenu.offsetHeight;
	return ((left < sRight) && (left + width > sLeft) && (top < sBottom) && (top + height > sTop));
}

function popup_msg() {
	var answer = window.confirm('Caller from : 50'+'\n'+'Ready to answer?');
	if(answer){this.location.href='custprofileselect_1.htm'};
}

function doProtect(val) {
	var sItems = document.getElementsByTagName('input');
	for (i=0; i < sItems.length; i++) {
		if(sItems[i].type == 'text'){
			sItems[i].readOnly= true;
		} else if(sItems[i].type == 'button'){
			sItems[i].style.visibility = "hidden";
		} else if(sItems[i].type == 'reset'){
			sItems[i].style.visibility = "hidden";
		} else if(sItems[i].type == 'submit'){
			sItems[i].style.visibility = "hidden";
		} else if (sItems[i].type == 'checkbox'){
			sItems[i].disabled = true;
		} else if (sItems[i].type == 'radio'){
			sItems[i].disabled = true;
		} else if (sItems[i].type == 'image'){
			sItems[i].disabled = true;
		}
	}
	sItems = document.getElementsByTagName('textarea');
	for (i=0; i < sItems.length; i++) {
		sItems[i].readOnly = true;
		//sItems[i].style.color = "#808080";
	}
	sItems = document.getElementsByTagName('select');
	for (i=0; i < sItems.length; i++) {
		sItems[i].disabled = true;
	}
}

function undoProtect(val) {
	var sItems = document.getElementsByTagName('input');
	for (i=0; i < sItems.length; i++) {
		if(sItems[i].type == 'text'){
			sItems[i].readOnly= false;
		} else if(sItems[i].type == 'button'){
			sItems[i].style.visibility = "visible";
		} else if(sItems[i].type == 'reset'){
			sItems[i].style.visibility = "visible";
		} else if(sItems[i].type == 'submit'){
			sItems[i].style.visibility = "visible";
		} else if (sItems[i].type == 'checkbox'){
			sItems[i].disabled = false;
		} else if (sItems[i].type == 'radio'){
			sItems[i].disabled = false;
		} else if (sItems[i].type == 'image'){
			sItems[i].disabled = false;
		}
	}
	sItems = document.getElementsByTagName('textarea');
	for (i=0; i < sItems.length; i++) {
		sItems[i].readOnly = false;
	}
	sItems = document.getElementsByTagName('select');
	for (i=0; i < sItems.length; i++) {
		sItems[i].disabled = false;
	}
}

function getCookie(nameOfCookie) {

	// First we check to see if there is a cookie stored.
	// Otherwise the length of document.cookie would be zero.

	if (document.cookie.length > 0) {

		// Second we check to see if the cookie's name is stored in the
		// 'document.cookie' object for the page.

		// Since more than one cookie can be set on a
		// single page it is possible that our cookie
		// is not present, even though the 'document.cookie' object
		// is not just an empty text.
		// If our cookie name is not present the value -1 is stored
		// in the variable called 'begin'.

		begin = document.cookie.indexOf(nameOfCookie+'=');
		if (begin != -1)  { // Note: != means 'is not equal to'
			// Our cookie was set.
			// The value stored in the cookie is returned from the function.

			begin += nameOfCookie.length+1;
			end = document.cookie.indexOf(';', begin);
			if (end == -1) end = document.cookie.length;
			return unescape(document.cookie.substring(begin, end));
		}
	}
	return null;

	// Our cookie was not set.
	// The value 'null' is returned from the function.
}

function setCookie(nameOfCookie, value, expiredays) {

	// Three variables are used to set the new cookie.
	// The name of the cookie, the value to be stored,
	// and finally the number of days until the cookie expires.
	// The first lines in the function convert
	// the number of days to a valid date.

	var ExpireDate = new Date ();
	ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));

	// The next line stores the cookie, simply by assigning
	// the values to the 'document.cookie' object.
	// Note the date is converted to Greenwich Mean time using
	// the 'toGMTstring()' function.

	document.cookie = nameOfCookie + '=' + escape(value) +
		((expiredays == null) ? '' : '; expires=' + ExpireDate.toGMTString());
}

function delCookie (nameOfCookie) {

	// The function simply checks to see if the cookie is set.
	// If so, the expiration date is set to Jan. 1st 1970.

	if (getCookie(nameOfCookie)) {
		document.cookie = nameOfCookie + '=; expires=Thu, 01-Jan-70 00:00:01 GMT';
	}
}

function goReportMain(){
	window.location.href = "reportmain.jsp";
}

function goMasterListMain(){
	window.location.href = "masterList.jsp";
}

function goEnquiryMain(){
	window.location.href = "enquiryList.jsp";
}

function doTwoRadioWithValue(cbName,idx,val1,val2) {
	firstVal = val1;
	secondVal = val2;
	doTwoRadio(cbName,idx);
	firstVal = '0';
	secondVal = '1';
}
function doTwoRadio(cbName,idx) {
	var aInput = document.getElementsByName(cbName);
	if (aInput.length) {
		selectedObj = aInput[idx];
		if (aInput.length == 1)
			selectedObj = aInput[0];
	} else {
		selectedObj = aInput;
	}
	if (selectedObj.value != null && selectedObj.value == firstVal)
		selectedObj.value = firstVal;
	else
		selectedObj.value = secondVal;
}

// autofill parameters
var autofill_prefix = "srch";
var autofill_suffix_fr = "Fr";
var autofill_suffix_to = "To";

function autofill_init(prefix, suffix_fr, suffix_to) {
	var elms = document.getElementsByTagName("input");
	
	if (typeof(prefix) != 'undefined' && prefix != '')
		autofill_prefix = prefix;
	
	if (typeof(suffix_fr) != 'undefined' && suffix_fr != '')
		autofill_suffix_fr = suffix_fr;
		
	if (typeof(suffix_to) != 'undefined' && suffix_to != '')
		autofill_suffix_to = suffix_to;
	
	for (var i = 0; i < elms.length; i++) {
		var e = elms[i];

		if (e.getAttribute('autofill')) {
			if (e.getAttribute('autofill').toLowerCase() == 'true')
				e.onblur = autofill;
			continue;
		}
			
		if (e.type == 'text' && e.name.substr(0, autofill_prefix.length) == autofill_prefix && e.name.substr(e.name.length - autofill_suffix_fr.length, autofill_suffix_fr.length) == autofill_suffix_fr)
			e.onblur = autofill;
	}
}

function findIndex(src) {
	var elms = document.getElementsByName(src.name);

	for (var i = 0; i < elms.length; i++) {
		if (elms[i] == src)
			return i;
	}
	
	return -1;
}

function autofill() {
	var e =	this;
	var name = e.name;
	var idx = findIndex(e);
	var ts = document.getElementsByName(e.name.substr(0, e.name.length - autofill_suffix_fr.length) + autofill_suffix_to);
	
	if (idx == -1 || e.value == '')
		return;
	
	if (e.name.substr(0, autofill_prefix.length) == autofill_prefix && ts.length > 0) {
		var to = ts[idx];			
		
		if (to.value != '')
			return;
					
		to.value = to.value.length == 0 ? e.value : to.value;
		var tr = to.createTextRange();
		tr.select();
	}
}

function doTickWithValue(cbName,idx,val1,val2) {
	tickVal = val1;
	untickVal = val2;
	doTick(cbName,idx);
	tickVal = '0';
	untickVal = '1';
}

function doTick(cbName,idx) {
	var aInput = document.getElementsByName(cbName);
	if (aInput.length) {
		selectedObj = aInput[idx];
		if (aInput.length == 1)
			selectedObj = aInput[0];
	} else {
		selectedObj = aInput;
	}
	if (selectedObj.value != null && selectedObj.value == tickVal)
		selectedObj.value = untickVal;
	else
		selectedObj.value = tickVal;
}


function doViewRemark(name, idx, title1, value1, title2, value2, remarkTitle){
	var form = document.forms[0];
	var val="";
	var queryStr = "";
	var doc;
	//var stylePath = "<%=request.getContextPath()%>";

	if(form.elements[name]){
		if(form.elements[name].length){
			val = form.elements[name][idx].value;
		} else {
			val = form.elements[name].value;
		}
	}

	if(remarkWin && remarkWin.open && !remarkWin.closed){
		remarkWin.close();
	}

	remarkWin = window.open('remarkView.do','remarkWin','width=750,height=550,resizable=yes,menubar=no,scrollbars=yes,status=no');
	if(remarkWin && remarkWin.open && !remarkWin.closed){
		remarkWin.moveTo(0, 0);

		var content = "";
		content += "<head>" + "\n";
		content += "<title>View Remark</title>" + "\n";
		content += "<link rel=\"stylesheet\" href=\""+stylePath+"/css/style.css\" type=\"text/css\">" + "\n";
		content += "<script language=\"javascript\">" + "\n";
		content += "<!--" + "\n";
		content += "function doLoad() {" + "\n";
		content += "	window.resizeTo(750, 550);" + "\n";
		content += "	window.moveTo(0, 0);" + "\n";
		content += "}" + "\n";
		content += "-->" + "\n";
		content += "</script>" + "\n";
		content += "</head>" + "\n";
		content += "<body onLoad=\"javascript:doLoad();\" bgcolor=\"#ffffff\">" + "\n";
		content += "<table bgcolor=\"#E0E6E7\" border=1 bordercolor=\"#C1C1C1\" cellpadding=0 cellspacing=0 width=100%>" + "\n";
		if(!(title1 == null || title1 == "")){
			content += "	<tr valign=\"top\">" + "\n";
			content += "<td bgcolor=\"#637ACB\" class=\"t2b\">"+title1+"</td>" + "\n";
			content += "<td class=\"t2\">"+value1+"</td>" + "\n";
			content += "	</tr>" + "\n";
		}
		if(!(title2 == null || title2 == "")){
			content += "	<tr valign=\"top\">" + "\n";
			content += "<td bgcolor=\"#637ACB\" class=\"t2b\">"+title2+"</td>" + "\n";
			content += "<td class=\"t2\">"+value2+"</td>" + "\n";
			content += "	</tr>" + "\n";
		}
		content += "<tr valign=\"top\">" + "\n";
		content += "	<td bgcolor=\"#637ACB\"></td>" + "\n";
		content += "	<td>" + "\n";
		content += "	<input name=\"btn_close\" type=\"button\" value=\"close\" onClick=\"javascript:window.close();\" class=\"b1\">" + "\n";
		content += "	</td>" + "\n";
		content += "</tr>" + "\n";
		content += "<tr valign=\"top\">" + "\n";
		content += "	 <td bgcolor=\"#637ACB\" class=\"t2b\">" + "\n";
		content += remarkTitle;
		content += "	 </td>" + "\n";
		content += "	 <td>" + "\n";
		content += "<textarea rows=\"25\" cols=\"75\" styleClass=\"t2\" readonly>"+val+"</textarea>" + "\n";
		content += "	 </td>" + "\n";
		content += "</tr>" + "\n";
		content += "</table>" + "\n";
		content += "</body>" + "\n";

		remarkWin.document.write(content);
	}
}
