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];}
}

//onmouseshow

String.prototype.startsWith = function(e) {

    // Process either an array of items or single item
    if (typeof e == "object") {
        // Return true if any items in the array are found 
        for (_i = 0; _i < e.length; _i++) {
            if (this.toLowerCase().indexOf(e[_i].toLowerCase()) == 0)
                return true;
        }
        return false;
    }
    else {
        return (this.toLowerCase().indexOf(e.toLowerCase()) == 0);
    }
};

function escapeHTML(str)
{
   var div = document.createElement('div');
   var text = document.createTextNode(str);
   div.appendChild(text);
   return div.innerHTML;
}

function DisplayConfirmation (msg,YesURL)
{

    var blownOutBox = confirm(msg);
    
    if (blownOutBox == true)
    {
        window.location = YesURL;
    }
}
       
function handleEnter (field, event, action) { 
var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode; 
if (keyCode == 13) { 
	var i; 
	var eles = field.id + "\r\n\r\n";
	for (i = 0; i < field.form.elements.length; i++) 
	{
	//eles += field.form.elements[i].id + "\r\n";
		if (field == field.form.elements[i]) 
			break; 
	}
				
	i = (i + 1) % field.form.elements.length;
	//alert(eles + "\r\n\r\n" + field.form.elements[i].name + "." + action + "()");
	eval("field.form.elements[i]." + action + "()"); 
	return false; 
}  
else 
    return true; 
}

var offsetfrommouse=[10,10]; //image x,y offsets from cursor position in pixels. Enter 0,0 for no offset
var displayduration=0; //duration in seconds image should remain visible. 0 for always.
var currentimageheight = 120;	// maximum image size.

if (document.getElementById || document.all){
	document.write('<div id="previewimageid">');
	document.write('</div>');
}

function getpreviewobj(){
    if (document.getElementById)
        return document.getElementById("previewimageid").style
    else if (document.all)
        return document.all.previewimageid.style
}

function getpreviewobjnostyle(){
    if (document.getElementById)
        return document.getElementById("previewimageid")
    else if (document.all)
        return document.all.previewimageid
}

function truebody(){
    return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function showpreview(title,description){
	currentimageheight = 120;

	document.onmousemove=followmouse;

	newHTML = '<dl>';
	newHTML = newHTML + '<dt>' + title + '</dt>';
	newHTML = newHTML + '<dd>' + description + '</dd>';
	newHtml = newHTML + '</dl>'
	getpreviewobjnostyle().innerHTML = newHTML;
	getpreviewobj().visibility="visible";
}
function hidepreview(){
	getpreviewobj().visibility="hidden"
	document.onmousemove=""
	getpreviewobj().left="-500px"
}

function followmouse(e){
	var xcoord=offsetfrommouse[0]
	var ycoord=offsetfrommouse[1]

	var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15
	var docheight=document.all? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(window.innerHeight)

	//if (document.all){
	//	getpreviewobjnostyle().innerHTML = 'A = ' + truebody().scrollHeight + '<br>B = ' + truebody().clientHeight;
	//} else {
	//	getpreviewobjnostyle().innerHTML = 'C = ' + document.body.offsetHeight + '<br>D = ' + window.innerHeight;
	//}

	if (typeof e != "undefined"){
		if (docwidth - e.pageX < 150){
			xcoord = e.pageX - xcoord - 220; // Move to the left side of the cursor
		} else {
			xcoord += e.pageX;
		}
		if (docheight - e.pageY < (currentimageheight + 30)){
			ycoord += e.pageY - Math.max(0,(30 + currentimageheight + e.pageY - docheight - truebody().scrollTop));
		} else {
			ycoord += e.pageY;
		}

	} else if (typeof window.event != "undefined"){
		if (docwidth - event.clientX < 150){
			xcoord = event.clientX + truebody().scrollLeft - xcoord - 220; // Move to the left side of the cursor
		} else {
			xcoord += truebody().scrollLeft+event.clientX
		}
		if (docheight - event.clientY < (currentimageheight + 30)){
			ycoord += event.clientY + truebody().scrollTop - Math.max(0,(30 + currentimageheight + event.clientY - docheight));
		} else {
			ycoord += truebody().scrollTop + event.clientY;
		}
	}

	var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15
	var docheight=document.all? Math.max(truebody().scrollHeight, truebody().clientHeight) : Math.max(document.body.offsetHeight, window.innerHeight)
		if(ycoord < 0) { ycoord = ycoord*-1; }
	getpreviewobj().left=xcoord+"px"
	getpreviewobj().top=ycoord+"px"

}
	
	
var lastControl;

function swap(control, toggle)
{
    // Swap the input field
    if(toggle == "showInput")
    {
        document.getElementById(control).style.display = "none";
        document.getElementById(control + "_inputdiv").style.display = "";
        //document.getElementById(control + "_input").focus();
        //document.getElementById(control + "_input").select();
    }
    else
    {
        // Don't un-select the last control
        if (control != lastControl)
        {
            document.getElementById(control).style.display = "";
            document.getElementById(control + "_inputdiv").style.display = "none";
        }
    }
    
}

function selectText(obj, control)
{
    // Focus on the text
    obj.focus();
    obj.select();
    
    // Copy the data to clipboard
    clipboardCopy(obj.value);
    
    // Un-select the last control
    unSelectControl(lastControl);
    
    // Update the last control
    lastControl = control;
    
    // Un-select the newly selected control in 3 seconds
    setTimeout("unSelectControl('" + control + "');", 3000) 

}

function unSelectControl(control)
{
    if (control != null)
    {
        document.getElementById(control).style.display = "";
        document.getElementById(control + "_inputdiv").style.display = "none";
        
        lastControl = null;
    }
}

