
String.prototype.trim = function () {
    return this.replace(/^\s*/, "").replace(/\s*$/, "");
}

function SetCharLimitation() {
	var datacontrol;
	var charcontrol;
	var textsize;
	
	datacontrol=document.getElementById(arguments[0]);
	charcontrol=document.getElementById(arguments[1]);//display characters leave
	textsize=arguments[2];
	
  if (datacontrol.value.length > textsize) {
    datacontrol.value = datacontrol.value.substring(0, textsize);
    charcontrol.value=textsize;
  }
  else{
	charcontrol.value=parseInt(textsize)-parseInt(datacontrol.value.length);
  }	
}


function validfloat(txt, ev) {
	ev.returnValue = ((ev.keyCode>=48 && ev.keyCode<=57) || ev.keyCode==46 && txt.value.indexOf('.') == -1);
}

function validfloatByPrecision(txt, ev, precision) {  
    if (txt.value.indexOf('.') == -1) {
        ev.returnValue = (ev.keyCode>=48 && ev.keyCode<=57 || ev.keyCode==46);
    }
    else if (txt.value.indexOf('.') > -1 && txt.value.indexOf('.') == txt.value.lastIndexOf('.')) {
        if (txt.value.length - txt.value.lastIndexOf('.') - 1 != precision) {
            ev.returnValue = (ev.keyCode>=48 && ev.keyCode<=57);
        }
        else{ev.returnValue = '';}
    }
    else{ev.returnValue = '';}
}

function validnumber(ev) {
	ev.returnValue = (ev.keyCode>=48 && ev.keyCode<=57); 
}

function isInteger(num) {
    return (("" + parseInt(num)) == num);
}

function isFloat(num) {
    return ((num/num == 1 || num == 0) && num != "");
}

function formatCurrency(num)
{
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num)) num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10) cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
		num = num.substring(0,num.length-(4*i+3)) + ',' + num.substring(num.length-(4*i+3));
	return (((sign)?'':'-') + num + '.' + cents);
}

function emptytozero(txt) {
	if (txt.value.length == 0) txt.value = "0";
}

function addalllist(lstavail,lstselected,hidden) {
	lstselected.length = 0;
	for (var i=0;i<lstavail.length;i++) {
		lstselected.options[lstselected.length] = new Option(lstavail.options[i].text,lstavail.options[i].value);
	}
	captureanswer(lstselected,hidden);
	clearselect(lstavail,lstselected);
}

function addlist(lstavail,lstselected,hidden) {
	for (var i=0;i<lstavail.length;i++) {
		if (lstavail.options[i].selected == true) {
			var blnExist = false;
			for (var j=0;j<lstselected.length;j++) {
				if (lstselected.options[j].value == lstavail.options[i].value) blnExist = true;
			}
			if (!blnExist) lstselected.options[lstselected.length] = new Option(lstavail.options[i].text,lstavail.options[i].value);
		}
	}
	captureanswer(lstselected,hidden);
	clearselect(lstavail,lstselected);
}

function dellist(lstavail,lstselected,hidden) {
	for (var i=lstselected.length-1;i>=0;i--) {
		if (lstselected.options[i].selected == true)
			lstselected.options[i] = null;
	}
	captureanswer(lstselected,hidden);
	clearselect(lstavail,lstselected);
}

function delalllist(lstavail,lstselected,hidden) {
	lstselected.length = 0;
	captureanswer(lstselected,hidden);
	clearselect(lstavail,lstselected);
}

function clearselect(lstavail,lstselected) {
	lstavail.selectedIndex = -1;
	lstselected.selectedIndex = -1;
}

function frameredirect(url) {
	parent.location.href='../' + url;
	parent.document.getElementById('fmeMenu').style.visibility='hidden';
}

function checkall(chk)	{
	for (var i=0;i<document.forms[0].elements.length;i++) {
		if (document.forms[0].elements[i].type == "checkbox" && document.forms[0].elements[i].name.indexOf(":_") >= 0) {
			if (document.forms[0].elements[i].disabled == false)
				document.forms[0].elements[i].checked = (chk.checked == true);
		}
	}
}

function clearall() {
	for (var i=0;i<document.forms[0].elements.length;i++) {
		if (document.forms[0].elements[i].type == "text" || document.forms[0].elements[i].type == "textarea")
			document.forms[0].elements[i].value = "";		
		else if (document.forms[0].elements[i].type == "select-one")
			document.forms[0].elements[i].selectedIndex = 0;
		else if (document.forms[0].elements[i].type == "checkbox")
			document.forms[0].elements[i].checked = false;
	}
}

function moveorder(listbox,hidden,order) {
	var selected = listbox.selectedIndex;
	if (selected >= 0) {
		var target = selected + order;
		if (target >= 0 && target < listbox.length) {
			var temptext = listbox.options[target].text;
			var tempvalue = listbox.options[target].value;
			listbox.options[target].text = listbox.options[selected].text;
			listbox.options[target].value = listbox.options[selected].value;
			listbox.options[selected].text = temptext;
			listbox.options[selected].value = tempvalue;
			listbox.options[target].selected = true;
			captureanswer(listbox,hidden);
		}
	}
}
function moveorderreport(listbox,hidden,order) {
	var selected = listbox.selectedIndex;
	if (selected >= 0) {
		var target = selected + order;
		if (target >= 0 && target < listbox.length) {
			var temptext = listbox.options[target].text;
			var tempvalue = listbox.options[target].value;
			listbox.options[target].text = listbox.options[selected].text;
			listbox.options[target].value = listbox.options[selected].value;
			listbox.options[selected].text = temptext;
			listbox.options[selected].value = tempvalue;
			listbox.options[target].selected = true;
			captureanswerreport(listbox,hidden);
		}
	}
}
function captureanswerreport(listbox,hidden) {
	var temp="";
	for (var i=0;i<listbox.length;i++) {
		temp += listbox.options[i].value + "|";
	}	
	hidden.value = temp;
}

function additem(textbox,listbox,hidden) {
	if (textbox.value.length > 0) {
		listbox.options[listbox.length] = new Option(textbox.value,textbox.value);
		textbox.value = "";
		captureanswer(listbox,hidden);
	}
}

function removeitem(listbox,hidden) {
	var selected = listbox.selectedIndex;
	if (selected >= 0) {
		listbox.options[listbox.selectedIndex] = null;
		if (selected > 0) listbox.options[selected-1].selected = true;
		captureanswer(listbox,hidden);
	}		
}

function captureanswer(listbox,hidden) {
	var temp="";
	for (var i=0;i<listbox.length;i++) {
		temp += listbox.options[i].value + "|";
	}	
	hidden.value = temp.substring(0,temp.length-1);
}

//convert to valid date(once onblur event)
//------------------------------------------------------------------------------------------------

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. 
    alert(a);   
    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 validdate()
		{
			var objControl=arguments[0];
			var objVal=objControl.value;
			var daysInMonth = DaysArray(12)
			var imonth;
			
			if(objVal!='')
			{
				var objDate;
				var strSplitter;
				var day,month,year;
				
				if(objVal.indexOf('/')!=-1){
					strSplitter='/';
				}else if(objVal.indexOf('-')!=-1){
					strSplitter='-';
				}else if(objVal.indexOf('.')!=-1){
					strSplitter='.';
				}else{
					//strSplitter='-';
					//alert('Invalid date.');
					objControl.select();	
					return false;
				}

				objDate=objVal.split(strSplitter);						
				
				try
				{
					day=objDate[0];
					if(isNaN(parseInt(day))){
						//alert('Invalid date.');
						objControl.select();						
						return false;
					}							
																
					month=objDate[1];																											
					if(isNaN(parseInt(month))){
						switch (month.toUpperCase()){
							case 'JAN':
							case 'JANUARY':
								month='Jan';
								imonth=1;
								break;
							case 'FEB':
							case 'FEBRUARY':
								month='Feb';
								imonth=2;
								break;
							case 'MAR':
							case 'MARCH':
								month='Mar';
								imonth=3;
								break;
							case 'APR':
							case 'APRIL':
								month='Apr';
								imonth=4;
								break;
							case 'MAY':
								month='May';
								imonth=5;
								break;
							case 'JUN':
							case 'JUNE':
								month='Jun';
								imonth=6;
								break;
							case 'JUL':
							case 'JULY':
								month='Jul';
								imonth=7;
								break;
							case 'AUG':
							case 'AUGUST':
								month='Aug';
								imonth=8;
								break;
							case 'SEP':
							case 'SEPTEMBER':
								month='Sep';
								imonth=9;
								break;
							case 'OCT':
							case 'OCTOBER':
								month='Oct';
								imonth=10;
								break;
							case 'NOV':
							case 'NOVEMBER':
								month='Nov';
								imonth=11;
								break;
							case 'DEC':
							case 'DECEMBER':
								month='Dec';
								imonth=12;
								break;
							default:return false;	
						}
					}
					else{
						if((parseInt(month,10)>=1)&&(parseInt(month,10)<=12)){
							switch(parseInt(month,10))
							{
								case 1:	
									month='Jan';
									imonth=1;
									break;
								case 2:	
									month='Feb';
									imonth=2;
									break;
								case 3:	
									month='Mar';
									imonth=3;
									break;
								case 4:	
									month='Apr';
									imonth=4;
									break;
								case 5:	
									month='May';
									imonth=5;
									break;
								case 6:	
									month='Jun';
									imonth=6;
									break;
								case 7:	
									month='Jul';
									imonth=7;
									break;
								case 8:	
									month='Aug';
									imonth=8;
									break;
								case 9:	
									month='Sep';
									imonth=9;
									break;
								case 10:	
									month='Oct';
									imonth=10;
									break;
								case 11:	
									month='Nov';
									imonth=11;
									break;
								case 12:	
									month='Dec';
									imonth=12;
									break;
							}
						}
						else{	
							//alert('Invalid date.');
							objControl.select();
							return false;
						}	
					}
					
					if (day<1 || day>31 || (imonth==2 && day>daysInFebruary(year)) || day > daysInMonth[imonth]){
						//alert('Invalid date.');
						objControl.select();						
						return false;												
					}	
						
					year=objDate[2];
					if(isNaN(parseInt(year))){
						//alert('Invalid date.');
						objControl.select();
						return false;
					}else if(year.length > 4){
						//alert('Invalid date.');
						objControl.select();
						return false;
					}else{
						if(parseInt(year)<1000){
							year=parseInt(year)+1900;
						}
					}
					day=day.length<2?"0"+day:day;
					objControl.value=day+'-'+month+'-'+year;
					return true;								
				}catch(e){}
			}
		}
//-----------------------------------------------------------------------------------------------------

// Date Picker
var nowDate = new Date();
var timeout=0,timeoutC=0,timeoutM=0,timeoutY=0;
var monthname = new Array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
var daysofmth = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
var daysofmthl = new Array(31,29,31,30,31,30,31,31,30,31,30,31);
var cYear,cMonth,txt;

function getDaysOfMonth(mth,yr) {
	if (yr%4 == 0) {
		if (yr%100 == 0 && yr%400 != 0)
			return daysofmth[mth];
		return daysofmthl[mth];
	} else
		return daysofmth[mth];
}

function calMonthYear(mth,yr,incr) {
	var arr = new Array();
	if (incr == -1) {
		if (mth == 0) {
			arr[0] = 11;
			arr[1] = parseInt(yr)-1;
		}
		else {
			arr[0] = parseInt(mth)-1;
			arr[1] = parseInt(yr);
		}
	} else if (incr == 1) {
		if (mth == 11) {
			arr[0] = 0;
			arr[1] = parseInt(yr)+1;
		}
		else {
			arr[0] = parseInt(mth)+1;
			arr[1] = parseInt(yr);
		}
	}
	return arr;
}

function formatToday(dy) {
	if (dy == nowDate.getDate() && cMonth == nowDate.getMonth() && cYear == nowDate.getYear())
		return '<font color="red">' + dy + '</font>';
	else
		return dy;
}

function formatDate(dy) {
	var formatday = (dy.toString().length<2) ? "0" + dy : dy;
	return formatday + "-" + monthname[cMonth] + "-" + cYear;
}

function hideObject() {
	parent.document.getElementById('fmeCal').style.visibility = "hidden";
}

function clearObject(txt) {
	parent.document.getElementById(txt).value = "";
	hideObject();
}

function monthOut() {
	document.getElementById('divMonth').style.visibility = "hidden";
}

function yearOut() {
	document.getElementById('divYear').style.visibility = "hidden";
}

function calendarOut() {
	document.getElementById('fmeCal').style.visibility = "hidden";
}

function incYear() {
	for	(i=0; i<5; i++) {
		var ddlYear = parseInt(document.getElementById('y'+i).innerText);
		if (this.gYear == ddlYear)
			document.getElementById('y'+i).innerHTML = '<b>' + ddlYear+1 + '</b>';
		else
			document.getElementById('y'+i).innerHTML = ddlYear+1;
	}
}

function decYear() {
	for	(i=0; i<5; i++) {
		var ddlYear = parseInt(document.getElementById('y'+i).innerText);
		if (this.gYear == ddlYear)
			document.getElementById('y'+i).innerHTML = '<b>' + ddlYear-1 + '</b>';
		else
			document.getElementById('y'+i).innerHTML = ddlYear-1;
	}
}

function buildMonth() {
	var selmonth = '<div id="divMonth" style="position:absolute;visibility:hidden;left:24;top:23;" onmouseover="clearTimeout(timeoutM)">' +
		'<table width="60" class="monthyear" style="font-size:7pt" cellspacing="0" onmouseover="clearTimeout(timeout)" onmouseout="timeout=setTimeout(\'monthOut()\',200);"><tr><td width="50%" ';
	for (var i=0;i<12;i++) {
		selmonth += ' onmouseover="this.style.backgroundColor=\'#316AC5\'" onmouseout="this.style.backgroundColor=\'\'" onclick="buildCal(\'' + txt + '\',' + i + ',' + cYear + ')">';
		if (cMonth == i)	
			selmonth += '<font style="font-size:8pt"><b>' + monthname[i].toUpperCase() + '</font></b>';
		else
			selmonth += monthname[i].toUpperCase();
		if (i%2 == 0)
			selmonth += '</td><td ';
		else if (i == 11)
			selmonth += '</td></tr>';		
		else
			selmonth += '</td></tr><tr><td ';
	}
	selmonth += '</table></div>';
	return selmonth;
}

function buildYear() {
	var selyear = '<div id="divYear" style="position:absolute;visibility:hidden;left:68;top:23;" onmouseover="clearTimeout(timeoutY)">' +
		'<table width="41" class="monthyear" cellspacing="0" onmouseover="clearTimeout(timeout);" onmouseout="timeout=setTimeout(\'yearOut()\',200)">' +
		'<tr><td align="center" onmouseover="this.style.backgroundColor=\'#316AC5\'" onmouseout="clearTimeout(timeout);this.style.backgroundColor=\'\'" onmousedown="timeout=setInterval(\'decYear()\',30)" onmouseup="clearTimeout(timeout);">-</td></tr>';
	var j=0;
	for (var i=parseInt(cYear)-2;i<=parseInt(cYear)+2;i++) {
		selyear += '<tr><td id="y' + j + '" align="center" onmouseover="this.style.backgroundColor=\'#316AC5\'" onmouseout="this.style.backgroundColor=\'\'" onclick="buildCal(\'' + txt + '\',' + cMonth + ',this.innerText)">';
		if (cYear == i)	
			selyear += '<b>' + i + '</b>';
		else
			selyear += i;
		selyear += '</td></tr>';
		j++;
	}
	selyear += '<tr><td align="center" onmouseover="this.style.backgroundColor=\'#316AC5\'" onmouseout="clearTimeout(timeout);this.style.backgroundColor=\'\'" onmousedown="timeout=setInterval(\'incYear()\',30)" onmouseup="clearTimeout(timeout);">+</td></tr></table></div>';
	return selyear;
}

function showCalendar() {
	var vCode = "";
	var vDate = new Date();
	vDate.setDate(1);
	vDate.setMonth(cMonth);
	vDate.setYear(cYear);
	var vFirstDay=vDate.getDay();
	var vLastDay=getDaysOfMonth(cMonth, cYear);
	var prev = calMonthYear(cMonth,cYear,-1);
	var next = calMonthYear(cMonth,cYear,1);
	
	// Month navigation header
	vCode += '<table id="tblMain" width="133" border="0" cellpadding="0" cellspacing="0" style="border:black 2px solid;"><tr><td>' +
		'<table width="100%" border="0" cellspacing="2" cellpadding="0"><tr>' +
		'<td><img src="..\\Images\\arrowl.gif" style="cursor:hand;" ' +
		'onmouseover="window.status=\'Previous month\';return true;" ' +
		'onmouseout="window.status=\'\';return true;" ' +
		'onclick="buildCal(\'' + txt + '\',' + prev[0] + ',' + prev[1] + ');"></td>';

	vCode += '<td width="39" class="monthyear" ' +
		'onmouseover="clearTimeout(timeoutM);window.status=\'Select month\';return true;" ' +
		'onmouseout="timeoutM=setTimeout(\'monthOut()\',300);window.status=\'\';return true;" ' +
		'onclick="document.getElementById(\'divMonth\').style.visibility=\'visible\'">&nbsp;' + 
		monthname[cMonth].toUpperCase() + ' <font class="dropdown">6</font>' + buildMonth() + '</td>';

	vCode += '<td class="monthyear" ' +
		'onmouseover="clearTimeout(timeoutY);window.status=\'Select year\';return true;" ' +
		'onmouseout="timeoutY=setTimeout(\'yearOut()\',300);window.status=\'\';return true;" ' +
		'onclick="document.getElementById(\'divYear\').style.visibility=\'visible\'">&nbsp;' + 
		cYear + ' <font class="dropdown">6</font>' + buildYear() + '</td>';

	vCode += '<td><img src="..\\Images\\arrowr.gif" style="cursor:hand" ' +
		'onmouseover="window.status=\'Next month\';return true;" ' +
		'onmouseout="window.status=\'\';return true;" ' +
		'onclick="buildCal(\'' + txt + '\',' + next[0] + ',' + next[1] + ');"></td></tr></table>';

	// Week header
	vCode += '<table width="100%" border="0" style="font-size:8pt;"><tr>' +
		'<td width="14%" align="center">S</td>' +
		'<td width="14%" align="center">M</td>' +
		'<td width="14%" align="center">T</td>' +
		'<td width="14%" align="center">W</td>' +
		'<td width="14%" align="center">T</td>' +
		'<td width="14%" align="center">F</td>' +
		'<td width="16%" align="center">S</td></tr>' +
		'<tr><td colspan="7" bgcolor="black"></td></tr>';

	// Days
	vCode = vCode + '<tr>';
	for (var i=0;i<45;i++) {
		if ((i < vFirstDay) || (i-vFirstDay >= vLastDay))
			vCode += '<td>&nbsp;</td>';
		else if (i-vFirstDay <= vLastDay) {
			vCode += '<td align="center">' + 
				'<a href="javascript:void(0);" ' + 
				'onmouseover="window.status=\'Set date to ' + formatDate(i-vFirstDay+1) + '\';return true;" ' +
				'onmouseout="window.status=\' \';return true;" ' +
				'onclick="parent.document.getElementById(\'' + txt + '\').value=\'' + formatDate(i-vFirstDay+1) + '\';hideObject();">' +
				'<font style="font-size:7pt;font-weight:bold;">' + 
				formatToday(i-vFirstDay+1) + '</font></a></td>';
		}
		if ((i+1)%7==0) {
			if (i < (vFirstDay-1) + vLastDay)
				vCode += '</tr><tr>';
			else {
				vCode += '</tr>';
				break;
			}
		}
	}

	// Close and clear button footer
	vCode += "<tr><td colspan='7' bgcolor='black'></td></tr>" +
		"<tr><td colspan='2' align='center'><a href='javascript:void(0);' onclick='hideObject();' onmouseover=\"window.status='Close calendar';return true;\" onmouseout=\"window.status='';return true;\"><font style='text-decoration:underline;'>Close</font></a></td>" +
		"<td colspan='3' align='center'><a href='javascript:void(0);' onclick=\"buildCal('" + txt + "'," + nowDate.getMonth() + "," + nowDate.getYear() + ");\" onmouseover=\"window.status='Go to default date';return true;\" onmouseout=\"window.status='';return true;\"><font style='text-decoration:underline;'>Today</font></a></td>" +
		"<td colspan='2' align='center'><a href='javascript:void(0);' onclick=\"clearObject('" + txt + "');\" onmouseover=\"window.status='Clear date';return true;\" onmouseout=\"window.status='';return true;\"><font style='text-decoration:underline;'>Clear</font></a></td></tr></table></td></tr></table>";
	return vCode;
}

function buildCal(source,mth,yr) {
	cMonth = mth;
	cYear = yr;
	txt = source;
	
	if (document.getElementById('overDiv') == null) {
		document.fmeCal.document.getElementById('overDiv').innerHTML=showCalendar();	
		document.getElementById('fmeCal').height = document.fmeCal.document.getElementById('tblMain').offsetHeight;
	}
	else {
		document.getElementById('overDiv').innerHTML=showCalendar();	
		parent.document.getElementById('fmeCal').height = document.getElementById('tblMain').offsetHeight;
	}
}

function popupCal() {
	buildCal(arguments[0],nowDate.getMonth(),nowDate.getYear());

	var obj = document.getElementById(txt);
	var objLeft = obj.offsetLeft;
	var objTop = obj.offsetTop;
	var objParent = obj.offsetParent;

	while(objParent.tagName.toUpperCase() != 'BODY') {
		objLeft += objParent.offsetLeft;
		objTop += objParent.offsetTop;
		objParent = objParent.offsetParent;
	}
	objTop += obj.offsetHeight + 2;

	document.getElementById('fmeCal').style.visibility = "visible";
	document.getElementById('fmeCal').style.left = objLeft;
	document.getElementById('fmeCal').style.top = objTop;
}
//End Date Picker 	if (navigator.appVersion.indexOf('Mac') != -1)



// Image Swap 
// ==============================================
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_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_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_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];}
}



//-------------------------------
    //Detect Windows Size
//-------------------------------
function getPageSizeWithScroll(){ 
    var y;
    if(typeof(self.outerWidth)=='number') {
        y=self.innerHeight;
    } else {
        y=document.documentElement.clientHeight;
    }    
      
    if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac         
        xWithScroll = document.body.scrollWidth;     
        yWithScroll = document.body.scrollHeight;  
        if (yWithScroll>=y){
            yWithScroll=yWithScroll;            
        }else{
            yWithScroll=y;
        }     
    } 
    else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari         
        xWithScroll = document.body.scrollWidth;       
        yWithScroll = document.body.offsetHeight; 
        if (yWithScroll>=y){
            yWithScroll=yWithScroll;            
        } else{
            yWithScroll=y;
        }     
    } 
        
    arrayPageSizeWithScroll = new Array(xWithScroll,yWithScroll);
    return arrayPageSizeWithScroll; 
} 

//-----------------------------
    //div Show and Hide
//-----------------------------
function overlay() {
    
    divP = document.getElementById('divParent');                
    divC = document.getElementById('divCtrl'); 
    divB = document.getElementById('divBlack');
    
    scrollingDetector()
    if (divP.style.visibility == 'visible') {
        divP.style.visibility = 'hidden';
        divC.style.visibility = 'hidden';
        divB.style.width = 0;
        divB.style.height = 0;
        divB.style.display = 'none';
        
        var iframe = document.getElementById('iframetop');
        iframe.style.display = 'none';
        iframe.style.width = 0;
        iframe.style.height = 0;
        iframe.style.left = 0;
        iframe.style.top = 0;
    }else{
        divP.style.visibility = 'visible';
        divC.style.visibility = 'visible';        
        var arrPageSizeWithScoll = getPageSizeWithScroll();
        divB.style.width = arrPageSizeWithScoll[0];
        divB.style.height = arrPageSizeWithScoll[1]; 
        divB.style.display = 'block';
        var iframe = document.getElementById('iframetop');
        iframe.style.display = 'block';
        iframe.style.width = divB.offsetWidth-5;
        iframe.style.height = divB.offsetHeight-5;
        iframe.style.left = divB.offsetLeft;
        iframe.style.top = divB.offsetTop;
    }     
}

function startScrollingDetector(){
    setInterval("scrollingDetector()",50);
}

function scrollingDetector()
{    
    var divP = document.getElementById('divParent');      
   	var divB = document.getElementById('divBlack');
   	var divC = document.getElementById('divCtrl'); 
	var tbC = document.getElementById('tbCtrl'); 
	
        //find screen height
        var xScreen;
        var yScreen;
        var xScreen2;
        var yScreen2;
        if(typeof(self.outerWidth)=='number') {
            xScreen=self.innerWidth;
            yScreen=self.innerHeight;
        } else {
            xScreen=document.documentElement.clientWidth;
            yScreen=document.documentElement.clientHeight;
        } 
        
        xScreen2 = document.body.scrollWidth;    
        yScreen2 = document.body.offsetHeight;  
        //screen X
        if (xScreen2>=xScreen){
            xScreen=xScreen2;            
        } else{
            xScreen=xScreen;
        }   
        //Screen Y
        if (yScreen2>=yScreen){
            yScreen=yScreen2;            
        } else{
            yScreen=yScreen;
        }     
        
        //check the scrolling height	
 	    var y;
	    if (navigator.appName == "Microsoft Internet Explorer"){
		    y = document.body.scrollTop;
	    }else {
		    y = window.pageYOffset;
	    }
    	
	    // detect tbCtrl table width
        var tbX;
        var tbY = tbC.scrollHeight; 
        if (tbC.style.width!=''){
            tbX = tbC.style.width;  
        }else if(tbC.width!=''){
            tbX = tbC.width;
        }else{
            tbX = tbC.offsetWidth;
        }
   	    //divC.style.posTop =	y;
   	    divC.style.width = tbX;
   	    divC.style.left = xScreen/2 - (tbX/2);
   	    divC.style.top = y + ((yScreen/2) - (tbY/2));
   	
   	    //Reset divBlack width and height
   	     
        var arrPageSizeWithScoll = getPageSizeWithScroll();
        divB.style.width = arrPageSizeWithScoll[0];
        divB.style.height = arrPageSizeWithScoll[1];      
}     

function setBtnMessageOk(url)
{
    document.getElementById('btnMessageOk').onclick=function() { overlay(); if (url!=''){location.href=url; }}
}

function captureanswer(listbox,hidden) 
{
	var temp="";
	for (var i=0;i<listbox.length;i++) {
		temp += listbox.options[i].value + "|";
	}	
	hidden.value = temp.substring(0,temp.length-1);
}

function errorFocus(ctrl)
{
	if(document.getElementById(ctrl)!=null){
		document.getElementById(ctrl).focus();
	}
}

function toggle(objName){
    var obj = document.getElementById(objName);
    if(obj != null && obj.style.display != null){
        if(obj.style.display == "" || obj.style.display == "block"){
            obj.style.display = "none";
        }else{
            obj.style.display = "";
        }
    }
}      

function hide(objName){
    var obj = document.getElementById(objName);
    if(obj != null && obj.style.display != null){
            obj.style.display = "none";
    }
}   

function show(objName){
    var obj = document.getElementById(objName);
    if(obj != null && obj.style.display != null){
        obj.style.display = "";
    }
}         

function toggle(objName){
    var obj = document.getElementById(objName);
    if(obj != null && obj.style.display != null){
        if(obj.style.display == "" || obj.style.display == "block"){
            obj.style.display = "none";
        }else{
            obj.style.display = "";
        }
    }
}      


function disable(objName){
    var obj = document.getElementById(objName);
    if(obj != null){                
        obj.disabled = true;                
    }        
} 

