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;
}

//set autopostback features(manually)
function myPostBack(eventTarget) {
    var eventArgument;
    eventArgument = '';
    var theform;
    if (window.navigator.appName.toLowerCase().indexOf("microsoft") > -1) {
        theform = document.Form1;
    }
    else {
        theform = document.forms["Form1"];
    }
    
    theform.__EVENTTARGET.value = eventTarget.split("$").join(":");
    theform.__EVENTARGUMENT.value = eventArgument;
    theform.submit();
}

//set control's limitation
function SetDataLimitation()
{
	var datacontrol;
	var textsize;
	datacontrol=document.getElementById(arguments[0]);
	textsize=arguments[1];
	
	if(datacontrol.value.length>=textsize)
	{
		return false;
	}
}

//check browser
var detect = navigator.userAgent.toLowerCase();
var OSBrowser;

function checkIt(string)
{
	place = detect.indexOf(string) + 1;
	thestring = string;
	return place;
}

function checkBrowser()
{
	if (!OSBrowser)
	{
		if (checkIt('linux')) OSBrowser = "Linux";
		else if (checkIt('x11')) OSBrowser = "Unix";
		else if (checkIt('mac')) OSBrowser = "Mac"
		else if (checkIt('win')) OSBrowser = "Windows"
		else OSBrowser = "an unknown operating system";
	}
}

function validfloat(txtid, ev) {
	var dblvalue;
	dblvalue=document.getElementById(txtid).value;
	
	ev.returnValue = ((ev.keyCode>=48 && ev.keyCode<=57) || ev.keyCode==46 && dblvalue.indexOf('.') == -1);
}

function validpercentage(txtid, ev) {
	var dblvalue;
	dblvalue=document.getElementById(txtid).value;
	
	ev.returnValue = ((ev.keyCode>=48 && ev.keyCode<=57) || ev.keyCode==46 && dblvalue.indexOf('.') == -1 || ev.keyCode==45 && dblvalue.indexOf('.') == -1);
}

function validnumber(txtid, ev) {
	var dblvalue;
	dblvalue=document.getElementById(txtid).value;
	
	ev.returnValue = ((ev.keyCode>=48 && ev.keyCode<=57));
}

function MaxWindowSize()
{
	window.moveTo(0,0);
	window.resizeTo(window.screen.availWidth,window.screen.availHeight);
}

String.prototype.trim = function()    //// trims white space off both ends of this string
{
		return( (ar=/^\s*([\s\S]*\S+)\s*$/.exec(this)) ? ar[1] : "" ); 
}
	
function CheckAllFields() 
{
	var blnValid=true;
	
	for(var i=0; i< Page_Validators.length; i++ ) {
			ValidatorValidate(Page_Validators[i]);

			if (!Page_Validators[i].isvalid) {
					//t = eval("document.getElementById('" + Page_Validators[i].controltovalidate + "')");
					t = eval("document.getElementById('" + Page_Validators[i].controltovalidate + "')");
					//t = eval("document.all." + Page_Validators[i].controltovalidate);
					t.focus();
					t.select();
					//alert(Page_Validators[i].controltovalidate);
					window.location.href='#' + Page_Validators[i].controltovalidate ;//bookmark
					blnValid=false
					break;
			}
		}
		
	return blnValid;	
}	

function OpenSaveDialog() 
{ 
	var retval=""; 
	var win=arguments[0];
	var winproperty=arguments[1];
	//var buttonid=arguments[2];

	retval=window.showModalDialog(win,'',winproperty); 

	if(retval!="" && retval!=null) 
	{ 
		//window.execScript("__doPostBack('confirmaction', '" + retval + "')","JavaScript"); 
		//__doPostBack(buttonid,'confirmaction')
		return true;
	}
	else{
		return false;
	}
} 

function OpenChildDetailsDialog() 
{ 
	var retval=""; 
	var win=arguments[0];
	var winproperty=arguments[1];
	var listbox=arguments[2];//listbox
	var hid=arguments[3];//hidden
	
	retval=window.showModalDialog(win,'',winproperty); 

	if(retval!="" && retval!=null) 
	{ 
		document.getElementById(listbox).options[document.getElementById(listbox).length] = new Option(retval,retval);
		captureanswer(document.getElementById(listbox),document.getElementById(hid));
	}
	else{
		return false;
	}
} 

function OpenResetDialog() 
{ 
	var retval=""; 
	var win=arguments[0];
	var winproperty=arguments[1];
	var buttonid=arguments[2];
	var frmName=document.getElementById(arguments[3]);
	
	retval=window.showModalDialog(win,'',winproperty); 

	if(retval!="" && retval!=null) 
	{ 
		//reset form objects
		var intCnt;
				
		for(intCnt=0;intCnt<frmName.length;intCnt++)
		{
			switch(frmName.elements[intCnt].type)
			{
				case 'hidden':{
					//if(frmName.elements[intCnt].id.indexOf('hid')==0)
						frmName.elements[intCnt].value='';
				}
				case 'text':frmName.elements[intCnt].value='';
				case 'textarea':frmName.elements[intCnt].value='';
				case 'radio':frmName.elements[intCnt].checked=false;
				case 'select-one':frmName.elements[intCnt].selectedIndex=0;	
				case 'checkbox':frmName.elements[intCnt].checked=false;
			}
			
			//clear listbox
			if(frmName.elements[intCnt].id.indexOf('lst')==0)//listbox prefix
			{
				document.getElementById(frmName.elements[intCnt].id).length = 0;
			}
		}
		return false;
	}
	else{
		return false;
	}
} 

function OpenConfirmDialog() 
{ 
	var retval=""; 
	var win=arguments[0];
	var winproperty=arguments[1];
	var buttonid=arguments[2];

	retval=window.showModalDialog(win,'',winproperty); 

	if(retval!="" && retval!=null) 
	{ 
		//window.execScript("__doPostBack('confirmaction', '" + retval + "')","JavaScript"); 
		__doPostBack(buttonid,'confirmaction')
	}
	else{
		return false;
	}
} 

function resizeImages()
{
	var maxWidth= 100;
	var maxHeight=100;
	var arg;
	var ratio;
	
	arg=arguments[0];//index string
	
	var obj=document.images;
	
	for(i=0;i<obj.length;i++)
	{
		if(obj[i].id.indexOf(arg)>-1){
			ratio=obj[i].offsetWidth/obj[i].offsetHeight; /* width/height */
			
			if(obj[i].offsetWidth>maxWidth && obj[i].offsetHeight>maxHeight)
			{
				if(obj[i].offsetWidth>obj[i].offsetHeight)
				{
					obj[i].width = maxWidth;
					obj[i].setAttribute("width",maxWidth);
					obj[i].height = maxWidth/ratio;
					obj[i].setAttribute("height",maxWidth/ratio);
				}
				else
				{
					obj[i].height = maxHeight;
					obj[i].setAttribute("height",maxHeight);
					obj[i].width = maxHeight*ratio;
					obj[i].setAttribute("width",maxHeight*ratio);
				}
			}
			else if(obj[i].offsetWidth>maxWidth)
			{
				obj[i].width = maxWidth;
				obj[i].setAttribute("width",maxWidth);
				obj[i].height = maxWidth/ratio;
				obj[i].setAttribute("height",maxWidth/ratio);
			}
			else if(obj[i].offsetHeight>maxHeight)
			{
				obj[i].height = maxHeight;
				obj[i].setAttribute("height",maxHeight);
				obj[i].width = maxHeight*ratio;
				obj[i].setAttribute("width",maxHeight*ratio);
			}
		}
	}	
}

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);
	*/
	
	for (var i=0;i<lstavail.length;i++) {
		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);
			}
	}
}

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);
}

function dellist(lstselected,hidden) {
	for (var i=0;i<lstselected.length;i++) {
		if (lstselected.options[i].selected == true)
			lstselected.options[i] = null;
	}
	captureanswer(lstselected,hidden);
}

function delalllist(lstselected,hidden) {
	lstselected.length = 0;
	hidden.value="";
	//captureanswer(lstselected,hidden);
}

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-2);
}

//validate date dd/mm/yyyy
var dtCh= "/";
var minYear=1900;
var maxYear=3000;

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
}

//mm/yyyy
function isDateShort(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var strMonth=dtStr.substring(0,pos1)
	var strYear=dtStr.substring(pos1+1,dtStr.length)
	strYr=strYear
	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)
	year=parseInt(strYr)
	
	if (pos1==-1){
		//alert("The date format should be : mm/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		//alert("Please enter a valid month")
		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
	}
	
return true
}

//end validate date

//CODE FOR REQUEST QUERYSTRING
/*TITLE: Client-Side Request Object for javascript by Andrew Urquhart (UK)
HOME: http://andrewu.co.uk/tools/request/
COPYRIGHT: You are free to use this script for any use you wish, the only
thing I ask you do is keep this copyright message intact with the script.
Please don't pass it off as your own work, but feel free to enhance it and send
me the updated version. Please don't redistribute - it makes it harder to distribute
new versions of the script. This script is provided as is, with no warranty of any
kind. Use it at your own risk. Copyright Andrew R Urquhart
VERSION: #1.3 2005-05-11 17:52 UTC*/
function RObj(ea) {
	var LS	= "";
	var QS	= new Object();
	var un	= "undefined";
	var x	= null; // On platforms that understand the 'undefined' keyword replace 'null' with 'undefined' for maximum ASP-like behaviour.
	var f	= "function";
	var n	= "number";
	var r	= "string";
	var e1	= "ERROR: Index out of range in\r\nRequest.QueryString";
	var e2	= "ERROR: Wrong number of arguments or invalid property assignment\r\nRequest.QueryString";
	var e3	= "ERROR: Object doesn't support this property or method\r\nRequest.QueryString.Key";

	function Err(arg) {
		if (ea) {
			alert("Request Object:\r\n" + arg);
		}
	}
	function URID(t) {
		var d = "";
		if (t) {
			for (var i = 0; i < t.length; ++i) {
				var c = t.charAt(i);
				d += (c  ==  "+" ? " " : c);
			}
		}
		return unescape(d);
	}
	function OL(o) {
		var l = 0;
		for (var i in o) {
			if (typeof o[i] != f) {
				l++;
			}
		}
		return l;
	}
	function AK(key) {
		var auk = true;
		for (var u in QS) {
			if (typeof QS[u] != f && u.toString().toLowerCase() == key.toLowerCase()) {
				auk = false;
				return u;
			}
		}
		if (auk) {
			QS[key] = new Object();
			QS[key].toString = function() {
				return TS(QS[key]);
			}
			QS[key].Count = function() {
				return OL(QS[key]);
			}
			QS[key].Count.toString = function() {
				return OL(QS[key]).toString();
			}
			QS[key].Item = function(e) {
				if (typeof e == un) {
					return QS[key];
				}
				else {
					if (typeof e == n) {
						var a = QS[key][Math.ceil(e)];
						if (typeof a == un) {
							Err(e1 + "(\"" + key + "\").Item(" + e + ")");
						}
						return a;
					}
					else {
						Err("ERROR: Expecting numeric input in\r\nRequest.QueryString(\"" + key + "\").Item(\"" + e + "\")");
					}
				}
			}
			QS[key].Item.toString = function(e) {
				if (typeof e == un) {
					return QS[key].toString();
				}
				else {
					var a = QS[key][e];
					if (typeof a == un) {
						Err(e1 + "(\"" + key + "\").Item(" + e + ")");
					}
					return a.toString();
				}
			}
			QS[key].Key = function(e) {
				var t = typeof e;
				if (t == r) {
					var a = QS[key][e];
					return (typeof a != un && a && a.toString() ? e : "");
				}
				else {
					Err(e3 + "(" + (e ? e : "") + ")");
				}
			}
			QS[key].Key.toString = function() {
				return x;
			}
		}
		return key;
	}
	function AVTK(key, val) {
		if (key != "") {
			var key = AK(key);
			var l = OL(QS[key]);
			QS[key][l + 1] = val;
		}
	}
	function TS(o) {
		var s = "";
		for (var i in o) {
			var ty = typeof o[i];
			if (ty == "object") {
				s += TS(o[i]);
			}
			else if (ty != f) {
				s += o[i] + ", ";
			}
		}
		var l = s.length;
		if (l > 1) {
			return (s.substring(0, l-2));
		}
		return (s == "" ? x : s);
	}
	function KM(k, o) {
		var k = k.toLowerCase();
		for (var u in o) {
			if (typeof o[u] != f && u.toString().toLowerCase() == k) {
				return u;
			}
		}
	}
	if (window.location && window.location.search) {
		LS = window.location.search;
		var l = LS.length;
		if (l > 0) {
			LS = LS.substring(1,l);
			var preAmpAt = 0;
			var ampAt = -1;
			var eqAt = -1;
			var k = 0;
			var skip = false;
			for (var i = 0; i < l; ++i) {
				var c = LS.charAt(i);
				if (LS.charAt(preAmpAt) == "=" || (preAmpAt == 0 && i == 0 && c == "=")) {
					skip=true;
				}
				if (c == "=" && eqAt == -1 && !skip) {
					eqAt=i;
				}
				if (c == "&" && ampAt == -1) {
					if (eqAt!=-1) {
						ampAt=i;
					}
					if (skip) {
						preAmpAt = i + 1;
					}
					skip = false;
				}
				if (ampAt>eqAt) {
					AVTK(URID(LS.substring(preAmpAt, eqAt)), URID(LS.substring(eqAt + 1, ampAt)));
					preAmpAt = ampAt + 1;
					eqAt = ampAt = -1;
					++k;
				}
			}
			if (LS.charAt(preAmpAt) != "=" && (preAmpAt != 0 || i != 0 || c != "=")) {
				if (preAmpAt != l) {
					if (eqAt != -1) {
						AVTK(URID(LS.substring(preAmpAt,eqAt)), URID(LS.substring(eqAt + 1,l)));
					}
					else if (preAmpAt != l - 1) {
						AVTK(URID(LS.substring(preAmpAt, l)), "");
					}
				}
				if (l == 1) {
					AVTK(LS.substring(0,1),"");
				}
			}
		}
	}
	var TC = OL(QS);
	if (!TC) {
		TC=0;
	}
	QS.toString = function() {
		return LS.toString();
	}
	QS.Count = function() {
		return (TC ? TC : 0);
	}
	QS.Count.toString = function() {
		return (TC ? TC.toString() : "0");
	}
	QS.Item = function(e) {
		if (typeof e == un) {
			return LS;
		}
		else {
			if (typeof e == n) {
				var e = Math.ceil(e);
				var c = 0;
				for (var i in QS) {
					if (typeof QS[i] != f && ++c == e) {
						return QS[i];
					}
				}
				Err(e1 + "().Item(" + e + ")");
			}
			else {
				return QS[KM(e, QS)];
			}
		}
		return x;
	}
	QS.Item.toString = function() {
		return LS.toString();
	}
	QS.Key = function(e) {
		var t = typeof e;
		if (t == n) {
			var e = Math.ceil(e);
			var c = 0;
			for (var i in QS) {
				if (typeof QS[i] != f && ++c == e) {
					return i;
				}
			}
		}
		else if (t == r) {
			var e = KM(e, QS);
			var a = QS[e];
			return (typeof a != un && a && a.toString() ? e : "");
		}
		else {
			Err(e2 + "().Key(" + (e ? e : "") + ")");
		}
		Err(e1 + "().Item(" + e + ")");
	}
	QS.Key.toString = function() {
		Err(e2 + "().Key");
	}
	this.QueryString = function(k) {
		if (typeof k == un) {
			return QS;
		}
		else {
			var k = KM(k, QS);
			if (typeof QS[k] == un) {
				t = new Object();
				t.Count = function() {
					return 0;
				}
				t.Count.toString = function() {
					return "0";
				}
				t.toString = function() {
					return x;
				}
				t.Item = function(e) {
					return x;
				}
				t.Item.toString = function() {
					return x;
				}
				t.Key = function(e) {
					Err(e3 + "(" + (e ? e : "") + ")");
				}
				t.Key.toString = function() {
					return x;
				}
				return t;
			}
			if (typeof k == n) {
				return QS.Item(k);
			}
			else {
				return QS[k];
			}
		}
	}
	this.QueryString.toString = function() {
		return LS.toString();
	}
	this.QueryString.Count = function() {
		return (TC ? TC : 0);
	}
	this.QueryString.Count.toString = function() {
		return (TC ? TC.toString() : "0");
	}
	this.QueryString.Item = function(e) {
		if (typeof e == un) {
			return LS.toString();
		}
		else {
			if (typeof e == n) {
				var e = Math.ceil(e);
				var c = 0;
				for (var i in QS) {
					if (typeof QS[i] != f && ++c == e) {
						return QS[i];
					}
				}
				Err(e1 + ".Item(" + e + ")");
			}
			else {
				return QS[KM(e, QS)];
			}
		}
		if (typeof e == n) {
			Err(e1 + ".Item(" + e + ")");
		}
		return x;
	}
	this.QueryString.Item.toString = function() {
		return LS.toString();
	}
	this.QueryString.Key = function(e) {
		var t = typeof e;
		if (t == n) {
			var e = Math.ceil(e);
			var c = 0;
			for (var i in QS) {
				if (typeof QS[i] == "object" && (++c == e)) {
					return i;
				}
			}
		}
		else if (t == r) {
			var e = KM(e, QS);
			var a = QS[e];
			return (typeof a != un && a && a.toString() ? e : "");
		}
		else {
			Err(e2 + ".Key(" + (e ? e : "") + ")");
		}
		Err(e1 + ".Item(" + e + ")");
	}
	this.QueryString.Key.toString = function() {
		Err(e2 + ".Key");
	}
	this.Version = 1.3;
	this.Author = "Andrew Urquhart (www.andrewu.co.uk)";
}

//mouseover an image and show div by follow mousemove cursor coordinates
	var IE = document.all?true:false;
	var tempX = 0;
	var tempY = 0;
	
	function getMouseXY(e,id) {
		if (IE) { // grab the x-y pos.s if browser is IE
		tempX = event.clientX + document.body.scrollLeft;
		tempY = event.clientY + document.body.scrollTop;
	}
	else {  // grab the x-y pos.s if browser is NS
		tempX = e.pageX;
		tempY = e.pageY;
	}  
	if (tempX < 0){tempX = 0;}
	if (tempY < 0){tempY = 0;}  
	
	document.getElementById(id).style.left = (tempX+10) + "px";
  	document.getElementById(id).style.top  = tempY  + "px";
  	
	return true;
	}
	
	function show(id)
{
	el = document.getElementById(id);
	if (el.style.display == 'none')
	{
		el.style.display = '';
		
	}   	
    	
}
function noneshow(id)
{
	el = document.getElementById(id);
	if (el.style.display == '')
	{
			el.style.display = 'none';	
	}
}

var Request = new RObj(false);

//END CODE

