// JavaScript Document


// Flash Player Version Detection
// Detect Client Browser type
// Copyright 2005-2008 Adobe Systems Incorporated.  All rights reserved.
var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;
function ControlVersion()
{
	var version;
	var axo;
	var e;
	// NOTE : new ActiveXObject(strFoo) throws an exception if strFoo isn't in the registry
	try {
		// version will be set for 7.X or greater players
		axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
		version = axo.GetVariable("$version");
	} catch (e) {
	}
	if (!version)
	{
		try {
			// version will be set for 6.X players only
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
			
			// installed player is some revision of 6.0
			// GetVariable("$version") crashes for versions 6.0.22 through 6.0.29,
			// so we have to be careful. 
			
			// default to the first public version
			version = "WIN 6,0,21,0";
			// throws if AllowScripAccess does not exist (introduced in 6.0r47)		
			axo.AllowScriptAccess = "always";
			// safe to call for 6.0r47 or greater
			version = axo.GetVariable("$version");
		} catch (e) {
		}
	}
	if (!version)
	{
		try {
			// version will be set for 4.X or 5.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
			version = axo.GetVariable("$version");
		} catch (e) {
		}
	}
	if (!version)
	{
		try {
			// version will be set for 3.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
			version = "WIN 3,0,18,0";
		} catch (e) {
		}
	}
	if (!version)
	{
		try {
			// version will be set for 2.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
			version = "WIN 2,0,0,11";
		} catch (e) {
			version = -1;
		}
	}
	
	return version;
}
// JavaScript helper required to detect Flash Player PlugIn version information
function GetSwfVer(){
	// NS/Opera version >= 3 check for Flash plugin in plugin array
	var flashVer = -1;
	
	if (navigator.plugins != null && navigator.plugins.length > 0) {
		if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
			var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
			var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;
			var descArray = flashDescription.split(" ");
			var tempArrayMajor = descArray[2].split(".");			
			var versionMajor = tempArrayMajor[0];
			var versionMinor = tempArrayMajor[1];
			var versionRevision = descArray[3];
			if (versionRevision == "") {
				versionRevision = descArray[4];
			}
			if (versionRevision[0] == "d") {
				versionRevision = versionRevision.substring(1);
			} else if (versionRevision[0] == "r") {
				versionRevision = versionRevision.substring(1);
				if (versionRevision.indexOf("d") > 0) {
					versionRevision = versionRevision.substring(0, versionRevision.indexOf("d"));
				}
			}
			var flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
		}
	}
	// MSN/WebTV 2.6 supports Flash 4
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4;
	// WebTV 2.5 supports Flash 3
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3;
	// older WebTV supports Flash 2
	else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2;
	else if ( isIE && isWin && !isOpera ) {
		flashVer = ControlVersion();
	}	
	return flashVer;
}
// When called with reqMajorVer, reqMinorVer, reqRevision returns true if that version or greater is available
function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision)
{
	versionStr = GetSwfVer();
	if (versionStr == -1 ) {
		return false;
	} else if (versionStr != 0) {
		if(isIE && isWin && !isOpera) {
			// Given "WIN 2,0,0,11"
			tempArray         = versionStr.split(" "); 	// ["WIN", "2,0,0,11"]
			tempString        = tempArray[1];			// "2,0,0,11"
			versionArray      = tempString.split(",");	// ['2', '0', '0', '11']
		} else {
			versionArray      = versionStr.split(".");
		}
		var versionMajor      = versionArray[0];
		var versionMinor      = versionArray[1];
		var versionRevision   = versionArray[2];
        	// is the major.revision >= requested major.revision AND the minor version >= requested minor
		if (versionMajor > parseFloat(reqMajorVer)) {
			return true;
		} else if (versionMajor == parseFloat(reqMajorVer)) {
			if (versionMinor > parseFloat(reqMinorVer))
				return true;
			else if (versionMinor == parseFloat(reqMinorVer)) {
				if (versionRevision >= parseFloat(reqRevision))
					return true;
			}
		}
		return false;
	}
}
function AC_AddExtension(src, ext)
{
  if (src.indexOf('?') != -1)
    return src.replace(/\?/, ext+'?'); 
  else
    return src + ext;
}
function AC_Generateobj(objAttrs, params, embedAttrs) 
{ 
  var str = '';
  if (isIE && isWin && !isOpera)
  {
    str += '<object ';
    for (var i in objAttrs)
    {
      str += i + '="' + objAttrs[i] + '" ';
    }
    str += '>';
    for (var i in params)
    {
      str += '<param name="' + i + '" value="' + params[i] + '" /> ';
    }
    str += '</object>';
  }
  else
  {
    str += '<embed ';
    for (var i in embedAttrs)
    {
      str += i + '="' + embedAttrs[i] + '" ';
    }
    str += '> </embed>';
  }
  if(arguments[3]) 
	return(str);
  else  document.write(str);
}
function AC_FL_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".swf", "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
     , "application/x-shockwave-flash"
    );

  return(AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs,true));
}
function AC_SW_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".dcr", "src", "clsid:166B1BCA-3F9C-11CF-8075-444553540000"
     , null
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs,true);
}
function AC_GetArgs(args, ext, srcParamName, classid, mimeType){
  var ret = new Object();
  ret.embedAttrs = new Object();
  ret.params = new Object();
  ret.objAttrs = new Object();
  for (var i=0; i < args.length; i=i+2){
    var currArg = args[i].toLowerCase();    
    switch (currArg){	
      case "classid":
        break;
      case "pluginspage":
        ret.embedAttrs[args[i]] = args[i+1];
        break;
      case "src":
      case "movie":	
        args[i+1] = AC_AddExtension(args[i+1], ext);
        ret.embedAttrs["src"] = args[i+1];
        ret.params[srcParamName] = args[i+1];
        break;
      case "onafterupdate":
      case "onbeforeupdate":
      case "onblur":
      case "oncellchange":
      case "onclick":
      case "ondblclick":
      case "ondrag":
      case "ondragend":
      case "ondragenter":
      case "ondragleave":
      case "ondragover":
      case "ondrop":
      case "onfinish":
      case "onfocus":
      case "onhelp":
      case "onmousedown":
      case "onmouseup":
      case "onmouseover":
      case "onmousemove":
      case "onmouseout":
      case "onkeypress":
      case "onkeydown":
      case "onkeyup":
      case "onload":
      case "onlosecapture":
      case "onpropertychange":
      case "onreadystatechange":
      case "onrowsdelete":
      case "onrowenter":
      case "onrowexit":
      case "onrowsinserted":
      case "onstart":
      case "onscroll":
      case "onbeforeeditfocus":
      case "onactivate":
      case "onbeforedeactivate":
      case "ondeactivate":
      case "type":
      case "codebase":
      case "id":
        ret.objAttrs[args[i]] = args[i+1];
        break;
      case "width":
      case "height":
      case "align":
      case "vspace": 
      case "hspace":
      case "class":
      case "title":
      case "accesskey":
      case "name":
      case "tabindex":
        ret.embedAttrs[args[i]] = ret.objAttrs[args[i]] = args[i+1];
        break;
      default:
        ret.embedAttrs[args[i]] = ret.params[args[i]] = args[i+1];
    }
  }
  ret.objAttrs["classid"] = classid;
  if (mimeType) ret.embedAttrs["type"] = mimeType;
  return ret;
}

//Cross Browser getElement function
function getElement(n, d) { // original: MM_findObj 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=getElement(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function is_object(){
	if(arguments[0].toString().indexOf("[object Object]") != -1) return(true);
	else return(false);
}

function in_array(obj,targetarray){ 
    return new RegExp('(^|\,)'+obj+'(\,|$)','gi').test(targetarray);
  } 

/* Javascript Job Queue */
/*var currentjobQueueID = 1;
var jobList = ObjectList();
*/





//Object list handlers

function ObjectList(){
	this.pointer = 0;
	this.objectType = null;
	this.items = new Array();
	this.loaded = false;
	this.Next = Next;
	this.Clear = function(){
		this.items = new Array();
		}
	this.Previous = Previous;
	this.First = First;
	this.Last = Last;
	this.getItem = getItem;
	this.GetItem = getItem;
	this.findItem = findItem;
	this.FindItem = findItem;
	this.IsEmpty = IsEmpty;
	this.Count = Count;
//	this.LoadList = LoadList;
	this.Insert = Insert;
	this.Delete = DeleteItem;
	this.getPointer = function(){
		return(parseInt(this.pointer));
		}
	this.setPointer = function(){
		this.pointer=arguments[0];
		}
	this.Current = Current;
	
	function Insert(){
		this.items[this.items.length] = new Item(arguments);
		this.pointer = this.items.length-1;
		return(this.items[this.pointer]);
		}

	function DeleteItem(){
		/*Deletes item at pointer*/
		this.items.splice(this.pointer,1);
		if(this.pointer >= this.items.length) this.pointer--;
		}
	function findItem(att,val){
		var i = 0;
		if(this.items.length){
			for(i=0; i< this.items.length; i++){
				if(this.items[i].getProperty(att)==val){ 
					this.setPointer(i);
					return(this.items[i]);
					}
				}
			}
		return(false);
	}
	function getItem(itemNo){
		if(this.items[itemNo-1]){
			this.pointer = itemNo-1;
			return(this.items[this.pointer]);
			}
		else return(false);
		}
	function Current(){
		if(this.items[this.pointer])
		return(this.items[this.pointer]);
		else return(false);
		}
	function First(){
		this.pointer = 0;
		return(this.items[this.pointer]);
		}
	function Last(){
		this.pointer = this.items.length-1;
		return(this.items[this.pointer]);
		}
	function IsEmpty(){
		if(this.items.length>0) return(0);
		else return(1);
		}
	function Reset(){
		this.items = null;
		this.items = new Array();
		return(1);
	}
	function Next(){
		if(this.pointer < (this.items.length-1)){
			this.pointer++;
			return(this.items[this.pointer]);
			}
		else return(false);
		}
	
	function Previous(){
		if(this.pointer>0){
			this.pointer--;
			return(this.items[this.pointer]);
			}
		else return(false);
		}
	function Count(){
		return(this.items.length);
	}
} // End of class ObjectList


function Item(){
	this.properties = new Array();
	this.setProperty = setProperty;
	this.addListProperty = addListProperty;
	this.getProperty = getProperty;	
	this.ajaxSetProperties = ajaxSetProperties;
	this.populate = populateItem;
	this.printProperties = printProperties;
	this.displayProperty = displayProperty;
	this.display = displayItem;
	this.Display = displayItem;
	this.Hide = hideElement;
	function populateItem(iProperties){
		if(iProperties.length>0){
			this.properties = iProperties;
			return(0);
			}
			else return(-1);
		}	
	function setProperty(pName,pValue){
		var oPropertyIndex = null;
		var i = 0;
		//alert('setting property '+pName+', current property count is '+properties.length);
		if(this.properties && this.properties.length){
			for(i=0;((i < this.properties.length) && (oPropertyIndex==null));i++){
				if(this.properties[i][0] == pName){
					oPropertyIndex = i;
					}
				}
			}
		else if(this.properties == null || this.properties =='undefined') this.properties = new Array();
		if(oPropertyIndex==null)	this.properties[this.properties.length] = new Array(pName,pValue);
		else this.properties[oPropertyIndex][1] = pValue;
	
	}
	function addListProperty(listName){
		var oPropertyIndex = null;
		var i = 0;
		//alert('setting property '+pName+', current property count is '+properties.length);
		if(this.properties && this.properties.length){
			for(i=0;((i < this.properties.length) && (oPropertyIndex==null));i++){
				if(this.properties[i][0] == listName){
					oPropertyIndex = i;
					}
				}
			}
		else if(this.properties == null || this.properties =='undefined') this.properties = new Array();
		if(oPropertyIndex==null){
			this.properties[this.properties.length] = new Array(listName,new ObjectList());
			oPropertyIndex = this.properties.length-1;
			}
		else this.properties[oPropertyIndex][1] = new ObjectList();
		return(this.properties[oPropertyIndex][1]);
	}
	function findProperty(pName,pValue){
		/*var propertyFound = false;
		var i = 0;
		
		if(this.properties[0]){
			do	{
				if(this.properties[i][0] == pName)
					if(this[properties[i][1] == pValue){
						propertyFound = true;
						return(t
				}while(this.properties[++i] && propertyFound == false);
			}
		*/	
		}
	function getProperty(pName){
		//alert('getting property ' + pName);
		var oProperty = null;
			var i = 0;
			if(this.properties[0])
			do{
				//alert('property '+i+':'+this.properties[i][0]);
				if(this.properties[i].length)
				if(this.properties[i][0] == pName){
				//	alert('found property' +pName);
					return(this.properties[i][1]);
				}
			}while(this.properties[++i]);
		return(-1);
	}
	function ajaxSetProperties(){
		if(arguments[0]){
			for(arg in arguments[0]){
			/*	if (JSON.parse(arguments[0][arg]))
				this.setProperty(arg,JSON.parse(arguments[0][arg]));
				else*/ this.setProperty(arg,arguments[0][arg]);
				}
			}
	}
	function printProperties(){
	var aText = '';
	var i = 0;
	if(this.properties[0])
			do{
				if(this.properties[i].length)
				 aText = aText + this.properties[i][0]+' = '+this.properties[i][1]+'\n';
				
			}while(this.properties[++i]);
		alert(aText);
		return(1);
	}
	
	function displayProperty(pName,dField){
		if(getElement(dField)){
			if((arguments[2]) && (this.getProperty(pName).length>arguments[2]))getElement(dField).innerHTML = this.getProperty(pName).substring(0,arguments[2])+'..';
			else getElement(dField).innerHTML = this.getProperty(pName);
		}
		}	
	
	function displayItem(){
		var sibling = false;
		if(this.getProperty('objectID')==-1 && this.getProperty('target')!=-1) this.setProperty('objectID',this.getProperty('target'));
		if(this.getProperty('objectID')!=-1 && getElement(this.getProperty('objectID'))){
			//alert('displaying element'+this.getProperty('objectID'));
			
			if(sibling = firstSibling(getElement(this.getProperty('objectID')))){
				sibling = firstSibling(getElement(this.getProperty('objectID')));
				do{
				
					if(sibling != null){
						if(sibling.id != this.getProperty('objectID')){
							sibling.style.display='none';
							sibling.style.visibility='hidden';
							}
						}
					}while(sibling = nextSibling(sibling));
					
				}
			displayElement(this.getProperty('objectID'));
			}
		else statusmessages.Add('could not display item, no objectID found');
		}
}// END of class Item


function JobQueue(){
	//this.queueID = currentjobQueueID++;
	this.jobs = new ObjectList();
	this.execute = runJob;
	this.stop = stopQueue;
	this.wait = pauseJob;
	this.pause = pauseJob;
	this.start = startQueue; 
	this.timeoutID = null;
	this.addJob = addJob;
	this.iCounter = 0;
	function pauseJob(){
		if(!this.jobs.IsEmpty()){	
			var currentJob = this.jobs.First();
			if(this.timeoutID != null){
				if(currentJob.waitStatus == true )setTimeout("jobqueue.pause()",currentJob.getProperty('interval'));
				else setTimeout("jobqueue.execute()",currentJob.getProperty('interval'));
			}
		}
	}
	function addJob(functionName,waitForEnd,maxIteration,interval){
		var job = this.jobs.Insert();
		job.waitStatus = false;
		job.setProperty('jobName',functionName ? functionName : false);
		job.setProperty('interval',interval ? interval : 50);
		job.setProperty('maxIteration',maxIteration ? maxIteration : 50);
		job.setProperty('waitForEnd',waitForEnd ? waitForEnd : false); 
		//job.printProperties();
		if(this.timeoutID == null) this.start();
	}

	function runJob(){
	//	alert('counter:'+iCounter);
		if(this.timeoutID!=null){
			if(!this.jobs.IsEmpty()){	
				var currentJob = this.jobs.First();
			
				var result = eval(currentJob.getProperty('jobName'));
				
				if(currentJob.getProperty('waitForEnd')==true){
					currentJob.waitStatus = true;
					++this.iCounter;
					}
				if((currentJob.getProperty('waitForEnd')==false) || (this.iCounter >= currentJob.getProperty('maxIteration')) || (result==true)) {
					//Delete job from queue
					this.jobs.Delete();
					this.iCounter = 0;
					}
				if(!this.jobs.IsEmpty()){
					currentJob = this.jobs.First(); 
					if(this.timeoutID != null) setTimeout("jobqueue.execute()",currentJob.getProperty('interval'));
					}
				else this.stop();
				}
			else{
				this.stop();
				}
			}
		}
	function stopQueue(){
		this.jobStatus = false;
		this.timeoutID = null;
		}
		
	function startQueue(){
		if(!this.jobs.IsEmpty()){	
			var currentJob = this.jobs.First();
			
			if(this.timeoutID==null){
				this.jobStatus = true;
				//alert('starting job queue');
				this.timeoutID = setTimeout("jobqueue.execute()",currentJob.getProperty('interval'));
			}
		}
	}
}//end of class jobqueue
var jobqueue = new JobQueue();


	function firstChild(startParent){	
		var tempObj = startParent.firstChild;
		while(tempObj.nodeType!=1 && tempObj.nextSibling!=null){		
			tempObj = tempObj.nextSibling;	
			}	
		return (tempObj.nodeType==1)?tempObj:false;
		}
	function nextSibling(startBrother){  
		var tempObj = startBrother.nextSibling;  
		if(tempObj){
			while(tempObj.nodeType!=1 && tempObj.nextSibling!=null){
				if(tempObj)
				tempObj = tempObj.nextSibling;	  
				}  
			return (tempObj.nodeType==1)?tempObj:false;
			}
		else return false;
		}
	function firstSibling(node){  
		var tempObj=node.parentNode.firstChild;  
		while(tempObj.nodeType!=1 && tempObj.nextSibling!=null){    
			tempObj=tempObj.nextSibling;  
			}  
		return (tempObj.nodeType==1)?tempObj:false;
		}
	function lastSibling(node){  
		var tempObj=node.parentNode.lastChild; 
		while(tempObj.nodeType!=1 && tempObj.previousSibling!=null){
			tempObj=tempObj.previousSibling;  
			}
		return (tempObj.nodeType==1)?tempObj:false;
		}
		
/* DOM functions */
function addTR(targetTable,pos){
	var tPos = 0;
	if(pos!='BEGINNING') tPos = -1;
	if(!getElement(targetTable)) return(false);
	var target = getElement(targetTable);
	return(target.insertRow(tPos));
	}
function addTD(targetTable,content,pos,tr){
	var tPos = 0;
	if(pos!='BEGINNING') tPos = -1;
	if(!getElement(targetTable)) return(false);
	var target = getElement(targetTable);
	var row = tr ? tr : target.insertRow(tPos);
	var cell = row.insertCell(-1);
	$(cell).attr('className','alignTop');
	cell.innerHTML = content;
	return(cell);
	
	
}
function deleteTD(targetTable,pos){
 var rows = getElement(targetTable).rows;
 var tPos = 0;
 if(pos!='BEGINNING' && pos !='START'){
	 tPos = rows.length-1;
 	}
 	getElement(targetTable).deleteRow(tPos);
}
function trimTable(targetTable,trimlength,pos){
	if(!getElement(targetTable)) return(false);
	var	rows = getElement(targetTable).rows;
 	while(rows.length > trimlength)
		deleteTD(targetTable,pos);
	}
	
	
function checkEmail(val) {
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(val)){
		return (true);
		}
	else return (false);
	}
function hideElementContents(element){
	var target = getElement(element);
	var coll = target.childNodes;
	var i;
	if(coll.length){
		var currentNode = target.firstChild;
		do{	var attribs = currentNode.attributes;
			
			
			if(currentNode.style){
			currentNode.style.display='none';
			currentNode.style.visibility='hidden';
			}
			}while(currentNode = currentNode.nextSibling);
		
		}
}
function hideElement(element){
	var target = getElement(element);
	if(target){
		target.style.display='none';
		target.style.visibility='hidden';
		}
}
function displayElement(element){
	
	var target = getElement(element);
	if(target){
		target.style.display='block';
		target.style.visibility='visible';
		}
	}
function SQL_TO_JS_Date(sqlDate) {
	if(sqlDate)
return sqlDate.replace(/^(....).(..).(.{11}).*$/, "$1/$2/$3") }
