// JavaScript Document
var array1
//-------------------------------------------------------------------------------------------------------------
//  Function to move options from one select box to another removing the options from the original select box
//--------------------------------------------------------------------------------------------------------------
	function RemoveDuplicates(from,to)
	{
		var Obj1 =document.getElementById(from);
		var Obj2 =document.getElementById(to);
		
		for (var j=0;j<Obj1.options.length;j++)
		{
			for (var i=0;i<Obj2.options.length;i++)
			{
				if(Obj1.options[j].value == Obj2.options[i].value)
				{
					Obj1.remove(j);
					//j--;
					continue;
					
				}
			}
		}
	}

	function reloadfunc()
	{
		for(var i=0;i<document.getElementsByName("reloadfns").length;i++)
			eval(document.getElementsByName("reloadfns")[i].value);
	}

	function copyremoveselect(from,to)
	{
		var j;
		var Obj1 = document.getElementById(from);
		var Obj2 = document.getElementById(to);
		for(var i=0;i<Obj1.options.length;i++)
		{
			if(Obj1.options[i].selected)
			{
				Obj2.options.length ++;
				Obj2.options[Obj2.options.length-1].text = Obj1.options[i].text;
				Obj2.options[Obj2.options.length-1].value = Obj1.options[i].value;
				Obj2.options[Obj2.options.length-1].selected = true;
				Obj1.remove(i);
				i--;
			}
		}
	}
//--------------------------------------------------------------------------------------	
// remote scripting function that calls page and puts contents of the page in an element
//--------------------------------------------------------------------------------------
	/*function filespage(url, containerid)
	{
		var page_request = false
		if (window.XMLHttpRequest) // if Mozilla, Safari etc
			page_request = new XMLHttpRequest()
		else if (window.ActiveXObject)
		{ // if IE
			try 
			{
				page_request = new ActiveXObject("Msxml2.XMLHTTP")
			} 	
			catch (e)
			{
				try
				{
					page_request = new ActiveXObject("Microsoft.XMLHTTP")
				}
				catch (e){}
			}
		}
		else
			return false
		page_request.onreadystatechange=function()
		{
			loadpage(page_request, containerid)
		}
		page_request.open('GET', url, true)
		page_request.send(null)
	}*/
	function LoadDocument(Dir,filename)
	{
		newwindow = window.open(Dir+'/'+ filename);
	}	
	
function getHtml(method,formname,url,transition,elementId)
{
	var xmlHttp; 
    //var requestURL = url;
	var browser;
	var browserversion;
	
	
	if (navigator.userAgent.match("MSIE"))
	{
		browser = "MSIE";
		indx = 	navigator.userAgent.indexOf('MSIE');
		browserversion = navigator.userAgent.substr(indx+4,4);
		
	}
	else if (navigator.userAgent.match("Firefox"))
	{
		browser = "Firefox";
		indx = 	navigator.userAgent.indexOf('Firefox');
		browserversion = navigator.userAgent.substr(indx+7,7);
		
	}
    var is_ie = (navigator.userAgent.indexOf('MSIE') >= 0) ? 1 : 0; 
    var is_ie5 = (navigator.appVersion.indexOf("MSIE 5.5")!=-1) ? 1 : 0; 
    var is_opera = ((navigator.userAgent.indexOf("Opera6")!=-1)||(navigator.userAgent.indexOf("Opera/6")!=-1)) ? 1 : 0; 
    //netscape, safari, mozilla behave the same??? 
    var is_netscape = (navigator.userAgent.indexOf('Firefox') >= 0) ? 1 : 0; 
	var is_firefox = navigator.userAgent.match("Firefox");
	
	
	var futdate = new Date();
	if(url.match("\\?"))
		url = url +"&time="+ futdate.getTime()+"&browse="+browser+"&browserversion="+browserversion;
	else
		url = url +"?time="+futdate.getTime()+"&browse="+browser+"&browserversion="+browserversion;
	
    xmlHttp = GetXmlHttpObject(stateChangeHandler); 
    //Send the xmlHttp get to the specified url 
   	if (method == "get")
   		xmlHttp_Get(xmlHttp, url); 
	else if (method =="post")
		xmlHttp_Post(formname,xmlHttp,url);
    else if (method == "file")
	{
		alert("file");
		xmlHTTP_File(formName,xmlhttp,url);
	
	}
	//stateChangeHandler will fire when the state has changed, i.e. data is received back 
    // This is non-blocking (asynchronous) 
    function stateChangeHandler() 
    { 
        //readyState of 4 or 'complete' represents that data has been returned 
        if (xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete')
		{ 
            //Gather the results from the callback 
			var page = document.getElementById(elementId);
			
			if ((transition == "")||(!is_ie))
	     		page.innerHTML= xmlHttp.responseText;
	
			else	 
			{
				
				page.style.filter=transition;
				
    			// Make sure the filter is not playing.
    			if (page.filters.blendTrans.status != 2) 
				{
       	 			//alert("blend");
					page.filters.blendTrans.duration = 1;
					page.filters.blendTrans.apply();
        			page.style.visibility="visible";
        			page.innerHTML= xmlHttp.responseText;
					page.filters.blendTrans.play();
    			}
			
			}
			loadevent();
		} 
    } 
	function removeElement(obj2) 
	{
		var d = obj2.parentNode
  	 	d.removeChild(obj2);	
	}
	function loadevent()
	{
		for(var j=0;j<document.getElementsByName("loadfns").length;j++)
		 {
			var obj3 = document.getElementsByName("loadfns");
			
			if(obj3[j].value !=" ")
			{
				streval = obj3[j].value
				obj3[j].value=" ";
				removeElement(obj3[j]);
				eval(streval);
				
				return;
			}
		}
	}
	// XMLHttp send POST request 
	function xmlHTTP_File(formName,xmlhttp,url)
	{
		alert(formName);
		var form = document.forms[formName];
		var nameValues = getFormInputs(form);
    	xmlhttp.open('POST', url, true);
		xmlhttp.setRequestHeader("Content-Type","multipart/form-data");
		xmlhttp.send(nameValues);
		
		
	}
	function xmlHttp_Post(formName,xmlhttp,url)
	{
		var form = document.forms[formName];
		var nameValues = getFormInputs(form);
    	xmlhttp.open('POST', url, true);
		xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		xmlhttp.send(nameValues);
	}
	// XMLHttp send GET request 
    function xmlHttp_Get(xmlhttp, url) { 
        xmlhttp.open('GET', url, true); 
        xmlhttp.send(null); 
    } 

    function GetXmlHttpObject(handler) { 
        var objXmlHttp = null;    //Holds the local xmlHTTP object instance 

        //Depending on the browser, try to create the xmlHttp object 
        if (is_ie){ 
            //The object to create depends on version of IE 
            //If it isn't ie5, then default to the Msxml2.XMLHTTP object 
            var strObjName = (is_ie5) ? 'Microsoft.XMLHTTP' : 'Msxml2.XMLHTTP'; 
             
            //Attempt to create the object 
            try{ 
                objXmlHttp = new ActiveXObject(strObjName); 
                objXmlHttp.onreadystatechange = handler; 
            } 
            catch(e){ 
            //Object creation errored 
                alert('IE detected, but object could not be created. Verify that active scripting and activeX controls are enabled'); 
                return; 
            } 
        } 
        else if (is_opera){ 
            //Opera has some issues with xmlHttp object functionality 
            alert('Opera detected. The page may not behave as expected.'); 
            return; 
        } 
        else{ 
            // Mozilla | Netscape | Safari 
            objXmlHttp = new XMLHttpRequest(); 
            objXmlHttp.onload = handler; 
            objXmlHttp.onerror = handler; 
        } 
         
        //Return the instantiated object 
        return objXmlHttp; 
    } 
}
	
	
	
	

	function loadpage(page_request,requestMethod, containerid)
	{
		if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
		{	
			document.getElementById(containerid).innerHTML=page_request.responseText;
			/*document.all("finished").value = eval(document.all("finished").value)+1;
			if(eval(document.all("finished").value) == eval(document.all("numreq").value))
			{
				pobj.style.display = "none";
				window.print();
				//document.all("load").style.display = "none";
				window.close();
			}
			*/
		}
	}

/* function getHtml(url, elementId)
{
	// Create Http interface object
	var page_request = createHttpRequest();
	if (page_request != null)
	{
		// Set delegate function for Http state change event
		page_request.onreadystatechange=function()
		{
			// Load response text
			loadpage(page_request, "GET", elementId);
		}
		// Issue GET and return true
		page_request.open('GET', url, true);
		page_request.send(null);
		return true;
	}
	else
	{
		// Indicate failure
		return false;
	}
}
*/
function postHtml(url,formName, elementId)
{
	// Get URL encoded name/value pairs from form
	var form = document.forms[formName];
	var nameValues = getFormInputs(form);
	
	// Get Http request object
	var page_request = createHttpRequest();

	if (page_request != null)
	{
		// Http request created, set delegate function for Http request state change
		page_request.onreadystatechange=function()
		{
			// POST request to page
			loadpage(page_request, "POST", elementId);
		}
		
		// Get destination page name from form
		if (url ==NULL)
			var url = form.getAttribute("action");
		
		// POST form to server and return true
		page_request.open('POST', url, true);
		page_request.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		page_request.send(nameValues);
		return true;
	}
	else
	{
		// Return false to indicate failure
		return false;
	}
}

function createHttpRequest()
{
  // Check for Mozilla, Safari, etc
  var http_request = false;
  if (window.XMLHttpRequest)
	{
		// Attempt to create XMLHttpRequest object
	  http_request = new XMLHttpRequest();
	}
	
	//Check for IE
  else if (window.ActiveXObject)
  {
    try 
    {
			// Attempt to create XMLHTTP object from Msxml2 dll
      http_request = new ActiveXObject("Msxml2.XMLHTTP");
    } 
    catch (e)
    {
      try
      {
				// Atttempt to create Msxml2.XMLHTTP object failed, attempt to create
				// XMLHTTP object from Microsoft dll
        http_request = new ActiveXObject("Microsoft.XMLHTTP");
     }
      catch (e)
			{
				// Unable to create HTTP interface object, return false
				return null;
			}
    }
  }
  else
	{
		// Unrecognized browser, return false
	  return null;
	}
	// Return XMLHttp interface object
	return http_request;
}

/*function loadpage(page_request, requestMethod, elementId)
{
	// Check for request complete state
	
	if (page_request.readyState == 4)
	{
		// Check for successful completion of GET or POST
		if (page_request.status==200 || window.location.href.indexOf("http")==-1)
		{
		// Get page text and check for GET method
			var html = page_request.responseText;
			if (requestMethod == "GET")
			{
				// Response is to a GET request, extract page head section
				var headStart = html.indexOf("<head");
				if (headStart >= 0)
				{
					// Start of head element found, find closing '>'
					var start = html.indexOf(">",headStart);
					if (start >= 0)
					{
						// Closing '>' found, find the end of the element
						var headEnd = html.indexOf("</head>",start + 1);
						if (headEnd >= 0)
						{
							// End of head element found, extract head element children
							var headText = html.substring(start + 1,headEnd);
							var headString = new String(headText);
							
							// Search for any LINK elements in the head
							var regExp = new RegExp("<link.*>","g");
							var links = headString.match(regExp);
							if (links != null)
							{
								// Loop to process LINK elements
								for (var ndx = 0; ndx < links.length; ndx++)
								{
									// Check that LINK element is for a style sheet
									var stylesheetRegExp = new RegExp("rel=stylesheet","g");
									var sheet = stylesheetRegExp.exec(links[ndx]);
									if ((sheet != null) && (sheet.length == 1))
									{
										// Style sheet LINK found, incorporate it into this page
										var styleRegExp = new RegExp("href=\".*\"");
										var styleUrl = new String(styleRegExp.exec(links[ndx]));
										var url = styleUrl.substr(6,styleUrl.length - 7);
										document.createStyleSheet(url);
										delete styleUrl;
										delete styleRegExp;
										sheet = null;
									}
									// Destroy style sheet RegExp object
									delete stylesheetRegExp;
								}
							}
							// Destroy '<link' RegExp object
							delete regExp;
							
							// Search for any script elements
							regExp = new RegExp("<scrip(.+|(.|[\r\n])+)\/script>","g");
							var scripts = headString.match(regExp);
							if ((scripts != null) && (scripts.length > 0))
							{
								// At least one script element found, loop to incorporate script(s) into this page
								//alert(scripts.length + " scripts found.");
								for (var ndx = 0; ndx < scripts.length; ndx++)
								{
									// Get next script node and create new script element
									var nextScript = scripts[ndx];
									//alert("Script: " + nextScript);
									
									// Create 'script' element
									var script = document.createElement("script");
									
									// Search for 'language' attribute
									var langAttrExp = new RegExp("language=\"[a-z]+\"","");
									var langAttr = nextScript.match(langAttrExp);
									if (langAttr != null)
									{
										var langAttrString = new String(langAttr);
										langAttr = langAttrString.substring(10,langAttrString.length - 1);
										//alert("Language attribute: " + langAttr);
									}
									delete langAttrExp;
									
									// Search for 'type' attribute
									var typeAttrExp = new RegExp("type=\"[a-z]+\"","");
									var typeAttr = nextScript.match(typeAttrExp);
									if (typeAttr != null)
									{
										var typeAttrString = new String(typeAttr);
										typeAttr = typeAttrString.substring(6,typeAttrString.length - 1);
										//alert("Type attribute: " + typeAttr);
									}
									delete typeAttrExp;
									
									var textRegExp = new RegExp(">(.*|(.|[\r\n])*)<","g");
									var textObj = nextScript.match(textRegExp);
									if (textObj != null)
									{
										var scriptString = new String(textObj)
										var scriptText = scriptString.substring(1,scriptString.length - 1);
										if (langAttr != null) script.setAttribute("language",langAttr);
										if (typeAttr != null) script.setAttribute("type",typeAttr);
										var elemRef = document.body.appendChild(script);
										if (elemRef != null)
										{
											elemRef.text = scriptText;
										}
										else
										{
											alert("Failed to append script node");
										}
									}
								}
							}
							// Destroy RegExp object
							delete regExp;
							
							// Destroy head String object
							delete headString;
						}
						else
						{
							// End on head element not found, display message
							alert("End of head element not found");
						}
					}
					else
					{
						// Closing '>' for head element not found, display message
						alert("Closing '>' for head element not found");
					}
				}
			}
			var bodyStart = html.indexOf("<body");
			var start = html.indexOf(">",bodyStart);
			var bodyEnd = html.indexOf("</body>",start + 1);
			var bodyText = html.substring(start + 1,bodyEnd);
			document.getElementById(elementId).innerHTML=bodyText;
		}
		else
		{

			alert(page_request.statusText);
		}
  }
	return true;
}*/

function getExceptionMessage(exception)
{
	var msgText = "Exception " + errorCode2Hex(exception.number) + ": ";
	msgText += (exception.description != null) ? exception.description : exception.message;
	return msgText;
}

function errorCode2Hex(ErrorCode)
{
	var baseString = new String("0x00000000");
	var baseText = Int2Hex(ErrorCode);
	var text = baseString.substr(0,10 - baseText.length) + baseText;
	delete baseString;
	return text;
}

function Int2Hex(d)
{
	var hD="0123456789ABCDEF";
	var h = hD.substr(d & 15,1);
	while(d > 15)
	{
		d >>= 4;
		h = hD.substr(d&15,1) + h;
	}
	return h;
}

function getFormInputs(form)
{
	// Check that form element is not null
	var submitContent = '';
	if (form != null)
	{
		// Loop through the form elements to extract element values to be posted to
		// the destination page. Use URLEncode rather than the escape function to 
		// encode the values. The escape function encodes a space character to '%20' 
		// while the URLEncode function encodes a space to a '+'.
		var formElem;
		var lastElemName = '';
		for (i = 0; i < form.elements.length; i++)
		{
			formElem = form.elements[i];
			switch (formElem.type)
			{
				// Text fields, hidden form elements
				case 'file':
					alert(file);
					alert(formElem.name);
				submitContent += formElem.name + '=' + URLEncode(formElem.value) + '&';
					break;
				case 'text':
				case 'hidden':
				case 'password':
				case 'textarea':
				case 'select-one':
					//submitContent += formElem.name + '=' + escape(formElem.value) + '&';
					submitContent += formElem.name + '=' + URLEncode(formElem.value) + '&';
					break;
				case 'select-multiple':
					for (var j=0;j<formElem.length;j++)
					{
						if(formElem.options[j].selected)
						submitContent += formElem.name +'='+URLEncode(formElem[j].value) +'&';
					}

					break;	
				// Radio button
				case 'radio':
					if (formElem.checked)
					{
						//submitContent += formElem.name + '=' + escape(formElem.value) + '&';;
						submitContent += formElem.name + '=' + URLEncode(formElem.value) + '&';;
					}
					break;
					
				// Checkbox
				case 'checkbox':
					if (formElem.checked)
					{
						// Continuing multiple, same-name checkboxes
						if (formElem.name == lastElemName)
						{
							// Strip of end ampersand if there is one
							if (submitContent.lastIndexOf('&') == submitContent.length-1)
							{
								submitContent = submitContent.substr(0, submitContent.length - 1);
							}
							// Append value as comma-delimited string
							//submitContent += ',' + escape(formElem.value);
							submitContent += ',' + URLEncode(formElem.value);
						}
						else
						{
							//submitContent += formElem.name + '=' + escape(formElem.value);
							submitContent += formElem.name + '=' + URLEncode(formElem.value);
						}
						submitContent += '&';
						lastElemName = formElem.name;
					}
					break;
			}
    }
		// Remove trailing separator
		submitContent = submitContent.substr(0, submitContent.length - 1);
  }
	return submitContent;
}
	
function URLEncode(plainText)
{
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";

	// Loop to convert characters to URL encoded format
	var encoded = "";
	for (var i = 0; i < plainText.length; i++ )
	{
		var ch = plainText.charAt(i);
		if (ch == " ") 
		{
			encoded += "+";				// x-www-urlencoded, rather than %20
		} 
		else if (SAFECHARS.indexOf(ch) != -1)
		{
			encoded += ch;
		}
		else 
		{
			var charCode = ch.charCodeAt(0);
			if (charCode > 255)
			{
				//alert( "Unicode Character '" + ch + "' cannot be encoded using standard URL encoding.\n" +
				//	"(URL encoding only supports 8-bit characters.)\n" + "A space (+) will be substituted." );
				encoded += "+";
			} 
			else 
			{
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	} // for
	return encoded;
}
function picton(flag)
{
	if( flag == 1)
	{
		document.onmousemove = MoveHandler;
		document.onclick = getObject;
		document.onmouseup = releaseObject;
	}
	else
	{
		document.onmousemove = null;
		document.onclick = null;
		document.onmouseup = null;
	}
}