var submitRolls = new Object();
var newWind,ptly_help,req_help;
var lastButt;
var _domainName=location.hostname;

//image2 = new Image();
//image2.src = "images/disablehelp.gif";
//image3 = new Image();
//image3.src = "/images/helpbox.gif";

//menuImageNames = new Array('images/main','images/search','images/update','images/bulletin','images/cal','images/details','images/log');

var yesterday;var lastE;

function show_mess (mess_no,bull_name,code,rem,subDir)
{
	var scroll;
	if(mess_no)
		scroll='no';
	else
		scroll='yes';
	if(subDir)
		popUp (385,690,scroll,0,0,0,'http://'+ _domainName +'/'+ subDir +'/ocd.aspx?action=check_bulletin&code=' + code + '&bulletin_name=' + bull_name + '&remote=on&mess_no=' + mess_no + '&reminder=' + rem)
	else
		popUp (385,690,scroll,0,0,0,'ocd.aspx?action=check_bulletin&code=' + code + '&bulletin_name=' + bull_name + '&remote=on&mess_no=' + mess_no + '&reminder=' + rem)
	window.name='ptly_main';
}

function set_today()
{
	var today = new Date();
	var cell= 'cal'+ today.getDate() + '' + (today.getMonth()+1);
	if(yesterday!=cell)
	{
		if (yesterday)
		{
			findObj(yesterday).style.border = '';
			findObj(yesterday).style.cssText = '';
		}
		findObj(cell).style.cssText = 'FONT-WEIGHT: bold';
		findObj(cell).style.border = '#000000 1px solid';
		yesterday=cell;
	}
	setTimeout('set_today()',300000);
}

function tinyMCEinit(areaName)
{
	tinyMCE.idCounter=0;
	tinyMCE.execCommand('mceAddControl', false, areaName);
}

function myCustomExecCommandHandler(editor_id, elm, command, user_interface, value) {
	var linkElm, imageElm, inst;
	switch (command) {
		case "mceLink":
			inst = tinyMCE.getInstanceById(editor_id);
			linkElm = tinyMCE.getParentElement(inst.selection.getFocusElement(), "a");
			if (linkElm)
				alert("Link dialog has been overriden. Found link href: " + tinyMCE.getAttrib(linkElm, "href"));
			else
				alert("Link dialog has been overriden.");
			return true;
		case "mceImage":
			inst = tinyMCE.getInstanceById(editor_id);
			imageElm = tinyMCE.getParentElement(inst.selection.getFocusElement(), "img");
			if (imageElm)
				alert("Image dialog has been overriden. Found image src: " + tinyMCE.getAttrib(imageElm, "src"));
			else
				alert("Image uploading is currently in development.");
			return true;
	}
	return false; // Pass to next handler in chain
}
function submitAjax(modName,formName,postBody,code,onC,keepContainer,fn,loadingTarget,targetURL)
{
	var post='';
	var fnText='';
	if(!targetURL) targetURL='ocd.aspx'
	if((!modName || !$(modName)) && formName) //if nowhere to put the result, try just submitting the form
	{
		document.forms[formName].submit();
		return;
	}
	if(keepContainer && $(modName).style)
	{
		$(modName).style.height=$(modName).getHeight()+'px';
		$(modName).style.width=$(modName).getWidth()+'px';
		if(loadingTarget)//target should be within modName container
		{
			$(loadingTarget).style.height=$(loadingTarget).getHeight()+'px';
			$(loadingTarget).style.width=$(loadingTarget).getWidth()+'px';
		}
	}
	if(code)
		post='code='+code;
	if(formName)
	{
		if(post!='') post+='&'
		post+=getFormData(formName);
	}
	if(postBody)
	{
		if(post!='') post+='&'
		post+=postBody;
	}
	post+='&ajax=on';
	if(loadingTarget=$(loadingTarget?loadingTarget:modName)) loadingTarget.innerHTML='<div style="text-align:center"><br><br><div style="display:inline-block;width:70px;text-align:center"><img src="/images/modules/loading.gif"><br>loading...</div></div>';

	if(onC)
		new Ajax.Updater(modName, targetURL, {asynchronous:true,evalScripts:true,method:'post',postBody:post,onComplete:function(){setTimeout('if(typeof('+onC+')!="undefined")'+onC+'();',1000)} });//
	else if(keepContainer)
		new Ajax.Updater(modName, targetURL, {asynchronous:true,evalScripts:true,method:'post',postBody:post,onComplete:function(){$(modName).style.height='';$(modName).style.width='';}});
	else
		new Ajax.Updater(modName, targetURL, {asynchronous:true,evalScripts:true,method:'post',postBody:post});
}


function addOnload(func) {
	if(window.isLoaded)
	{
		func();
		return;
	}
	var oldOnload = window.onload;
 
	if (typeof oldOnload == "function") {
		window.onload = function() {
			if (oldOnload) {
				oldOnload();
			}
			func();
		}
	}
	else {
		window.onload = func;
	} 
}
	
function changeToBox(box,width,height)
{
	height=height?height:5;
	width=width?width:29;
	var name=box.name?box.name:'S1';
	box.outerHTML='<textarea rows="' + height + '" name="'+ name +'" cols="' + width + '">'+ box.value +'</textarea>';
}

/*imgArray = new Array();
for(var i=0;menuImageNames[i];i++)
{
	imgArray[i] = new Image();
	imgArray[i].src=menuImageNames[i] + '02.gif';	
}*/		

// Decide browser version
var ns4 = (document.layers)? true:false;
var ns6 = (document.getElementById)? true:false;
var ie4 = (document.all)? true:false;
var ie5;
var ie7=false;
if (window.XMLHttpRequest)
	ie7=true;
	
if (ie4) {
	if ((navigator.userAgent.indexOf('MSIE 5') > 0) || (navigator.userAgent.indexOf('MSIE 6') > 0) || (navigator.userAgent.indexOf('MSIE 7') > 0)) {
		ie5 = true;
	}
	if (ns6) {
		ns6 = false;
	}
}

function submitMenu(a,vn,vv)
{
	if(a) document.forms['menuForm'].siteAction.value=a;
	if(vn) document.forms['menuForm'].siteValue.name=vn;
	if(vv) document.forms['menuForm'].siteValue.value=vv;
	document.forms['menuForm'].submit();
}

function debugObj(obj, parent) {
   if(!obj) alert('END');
   for (var i in obj) {
      if (parent) { var msg = parent + "." + i + "\n" + obj[i]; } else { var msg = i + "\n" + obj[i]; }
      if (!confirm(msg)) { return; }
      if (typeof obj[i] == "object") { 
         if (parent) { dumpProps(obj[i], parent + "." + i); } else { dumpProps(obj[i], i); }
      }
   }
}


function imageSwap(objImage,image1,image2)
{
	if(objImage.src.match(image2))
		objImage.src = image1;
	else
		objImage.src = image2;
}


function LimitAttach(form)
{
	var fileN=form.attach.value;
	if (!fileN) return;
	while (fileN.indexOf("\\") != -1)
		fileN = fileN.slice(fileN.indexOf("\\") + 1);
	ext = fileN.slice(fileN.indexOf(".")).toLowerCase();
	if (".jpg" == ext || ".jpeg" == ext) {
		form.submit();
		return;}
	else
		alert("Please only upload files that end in .jpg or .jpeg");
	return;
}

function findObj(n, d) {
  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=findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function getFormData(form) {
	var dataString='';
	if(typeof(form)=='string')
		form=findObj(form);

    function addParam(name, value) {
        dataString += (dataString.length > 0 ? "&" : "")
            + escape(name).replace(/\+/g, "%2B") + "="
            + escape(value ? value : "").replace(/\+/g, "%2B");
    }

    var elemArray = form.elements;
    for (var i = 0; i < elemArray.length; i++) {
        var element = elemArray[i];
        var elemType = element.type.toUpperCase();
        var elemName = element.name;
        if (elemName) {
            if (elemType == "TEXT"
                    || elemType == "TEXTAREA"
                    || elemType == "PASSWORD"
                    || elemType == "HIDDEN")
                addParam(elemName, element.value);
            else if (elemType == "CHECKBOX" && element.checked)
                addParam(elemName, 
                    element.value ? element.value : "On");
            else if (elemType == "RADIO" && element.checked)
                addParam(elemName, element.value);
            else if (elemType.indexOf("SELECT") != -1)
                for (var j = 0; j < element.options.length; j++) {
                    var option = element.options[j];
                    if (option.selected)
                        addParam(elemName,
                            option.value ? option.value : option.text);
                }
        }
    }
    return dataString;
}
//contract o1, expand o2
function slideMenu(o1,o2,m,h,first,onComplete)
{
	var obj,obj2,i;
	if(((obj=findObj('c_'+o1+'_'+m))!=null) && ((obj2=findObj('c_'+o2+'_'+m))!=null))
	{
	    if (obj.style)
	    	obj=obj.style;
	    if (obj2.style)
	    	obj2=obj2.style;
//		curr=parseInt(obj2.height);
		if(Math.pow(parseInt(obj2.height)-h,2)<(7*7))
		{
			obj.display='none'
			findObj('hc_'+o1+'_'+m).className='header_container header_collapsed';
			findObj('hc_'+o2+'_'+m).className='header_container header_expanded';
			obj.height='1px';
			obj2.height=h+'px';
//			window['s_'+m]=0;
			eval(onComplete);
			return;
		}
		else if(first)
		{
			obj2.display='';
			obj.height=parseInt(obj.height)-1+'px';
		}
		
		obj.height=parseInt(obj.height)-7+'px';
		obj2.height=parseInt(obj2.height)+7+'px';
		setTimeout('slideMenu('+o1+','+o2+',"'+m+'",'+h+',0,"'+onComplete+'");',1);
	}
	return true;
}

function showHideOb(o,v)
{
	var obj;
	if((obj=findObj(o))!=null)
	{
	    if (obj.style)
	    {
	    	obj=obj.style;
		if(v)
		    v=(v=='show')?'':(v=='hide')?'none':v;
		else
		{
	    	    v=obj.display; 
	    	    v=(v=='none')?'':'none';
		}
	    }
	    else if(!v)
	    	v=(v=='hide')?'':'none';
	    obj.display=v;
	}
}

function showHideObs()
{
	var v,obj,ar=arguments;
	for (var i=0;i<ar.length;i++)
	if((obj=findObj(ar[i]))!=null)
	{
		if (obj.style)
	    	obj=obj.style;
		v=obj.display; 
		v=(v=='none')?'':'none';
		obj.display=v;
	}
}



function showBody(){
 var p;
 if(document.all){
  if(p=document.all.wait) p.style.visibility="hidden";
  if(p=document.all.bodyText) p.style.visibility="visible";
 }
 else if(document.layers){
   if(p=document.layers["wait"]) p.visibility="hidden";
   if(p=document.layers["bodyText"]) p.visibility="visible";
 }
}


// load htmlarea
//  var editor;
  _editor_url = "/Library/HTMLArea3/";
  _editor_lang = "en";
//  _editor_CSS = "/library/HTMLarea3/style.css";


function load_htmlarea()
{
    document.write('<scr' + 'ipt src="' +_editor_url+ 'htmlarea.js"');
    document.write(' language="Javascript1.2"></scr' + 'ipt>');  
}

function run_htmlarea(name)
{
	if (!name || typeof(name)!='string') name="message";
	editor=new HTMLArea('html'+name);
//	editor.stylesheet = '/library/HTMLarea3/style.css';	
	editor.generate();
	setTimeout('check_editor(0,"'+ name +'");',2000);
}

function check_editor(n,name)
{
	if(!editor && n++<5)
	{
		editor=new HTMLArea('html'+name);
//		editor.stylesheet = '/library/HTMLarea3/style.css';	
		editor.generate();
		setTimeout('check_editor('+ n +',"'+ name +'");',500);
	}
}


function insert_htmlarea(name)
{
	document.write('<textarea style="width:100%" rows="20" name="html' + name + '" id="html' + name + '" cols="80"></textarea>')
	document.write('<br><br><span id="textArea"><font size="2"><b>Advanced:</b> the area above uses html (formatted text),<BR>to alter the automatic plain text conversion, <a href="#" onclick="javascript:findObj(\'textArea\').innerHTML=\'plain text<br><textarea rows=15 name=message cols=50></textarea>\';return false;">click here</a></font></span>');
	setTimeout('(editor=new HTMLArea("html'+name+'")).generate();',2000);
//	window.onload=(editor=new HTMLArea("html'+name+'")).generate();

}

function submitHiddenForm() { //form name, then name value combinations
	var ar=arguments;
	thisForm=document.forms[ar[0]];
	for(i=1;i<ar.length;i+=2)
		if(thisForm.elements[ar[i]])
			thisForm.elements[ar[i]].value=ar[i+1]?ar[i+1]:'';
		else
		{
			for(j=0;(temp=thisForm.elements[j]) && i<ar.length;j++)
				if(temp.name=='temp')
				{
					thisForm.elements[j].name=ar[i];
					thisForm.elements[j].value=ar[i+1]?ar[i+1]:'';
					i+=2
				}
			break;
		}
//	if(ar.length>i) need to insert more hidden fields
	if(!thisForm.onsubmit || thisForm.onsubmit())
		thisForm.submit();
}

function initMenu()
{
	if(document.all && document.all['menuBar'] && document.all['floatMenu'] && document.all['replaceMenu'])
	{
			floatY=document.all['menuBar'].offsetTop;
			document.all['floatMenu'].style.position = 'absolute';
			document.all['replaceMenu'].style.posHeight = document.all['menuBar'].offsetHeight;
			adjustMenu();
	}
}


function adjustMenu() {
	if(ie5 && document.all['menuBar'] && document.all['floatMenu'])
	{
		if(document.all['floatMenu'].style.position != 'absolute')
			initMenu();
		if(document.body.scrollTop>floatY)
			document.all['floatMenu'].style.posTop = document.body.scrollTop;
		else
			document.all['floatMenu'].style.posTop = floatY;
		document.all['floatMenu'].style.posLeft = 0;

	} 
}

function loadScript (url) 
{
    if (document.layers)
      window.location.href = url;
    else if (document.getElementById) 
    {
      var script = document.createElement('script');
      script.defer = true;
      script.src = url;
      document.getElementsByTagName('head')[0].appendChild(script);
    }
    else
      alert('This function is only available with Netscape versions 4+ and Internet Explorer 5+');
}

function iFrameWait(name,count)
{
	var Form;
//	alert(count + ' - ' + $('lightwindow_loading').style.display);
	if($('lightwindow_iframe') && $('lightwindow_loading').style.display=='none')
	{
		Form=findObj(name);
		var oldTarget=Form.target;
		Form.target='lightwindow_iframe';
		Form.submit();
		Form.target=oldTarget;
	}
	else if(count<100)
		setTimeout('iFrameWait(\''+ name +'\','+ ++count +');',100);
	return false;
}

function newPopUp(height,width,scroll,form,href,ajax)
{
	if(!name) name='remote';
	if(!height) height=283;
	if(!width) width=581;
	if(!scroll) scroll='no';
	if(ajax==1) ajax= 'page';
	else if(!ajax) ajax= 'external';
var inLW=false;
try
  {
	if((window!=window.parent) && window.parent.myLightWindow)
		inLW=true;
  }
catch(err)
  {
;
  }

	if(inLW)
		popUp(height,width,scroll,null,null,form,href);
	else if(href || form)
	{
		if(myLightWindow== null)
		{
			setTimeout("newPopUp("+height+","+width+",'"+scroll+"','"+form+"','"+href+"','"+ajax+"');",500);
			setTimeout('set_today()',300000);
			return;
		}
		if(!href)
		{	
			if(typeof(form)!='string')
				href='ocd.aspx?'+getFormData(form)+'&r='+Math.floor(Math.random()*10000);//prevent caching
			else if(form.indexOf('=')!=-1) //form name can't contain '='
				href='ocd.aspx?'+form+'&remote=on'+'&r='+Math.floor(Math.random()*10000);
			else
				href='/blank.htm';
		}
		
		myLightWindow.activateWindow({
			href: href,
		    width:width,
		    height:height,
			title: '',
			type: ajax,
			author: ''
		});
		if(!ajax && typeof(form)=='string' && form.indexOf('=')==-1) 
			iFrameWait(form,0);
		return false;
	}
}

function popUp(height,width,scroll,picUrlString,name,form,href)
{
	if(!name) name='remote';
	if(!height) height=283;
	if(!width) width=581;
	if(!scroll) scroll='no';
	
	if(!href)
	{
		if(typeof(form)!='string')
			href='ocd.aspx?'+getFormData(form)+'&r='+Math.floor(Math.random()*10000);//prevent caching
		else if(form.indexOf('=')!=-1) //form name can't contain '='
			href='ocd.aspx?'+form+'&remote=on'+'&r='+Math.floor(Math.random()*10000);
		else
			href='/blank.htm';
	}
	if((href || form) && typeof(myLightWindow)!="undefined" && !((window!=window.parent) && window.parent.myLightWindow))
	{
/*		if(!href)
		{	
			if(typeof(form)!='string')
				href='ocd.aspx?'+getFormData(form)+'&r='+Math.floor(Math.random()*10000);
			else
				href='/blank.htm';
		}*/
		myLightWindow.activateWindow({
			href: href,
		    width:width, 
		    height:height,
			title: '', 
			author: ''
		});
		if(typeof(form)=='string')
			iFrameWait(form,0);
		return false;
	}
	else
	{	
		if(form && !href)
			href='ocd.aspx?'+getFormData(form);
		newWind=window.open(href?href:'', name, 'left=50,top=50,toolbar=no,location=no,directories=no,menubar=no,scrollbars=' + scroll + ',status=no,resizable=yes,width=' + width + ',height=' + height);
		if(!newWind)
		alert('You may have a popup blocker installed, please disable to use this site properly.');

        if (newWind.opener == null)
        {
                newWind.opener = window;
        }
   if(href) return;
  var htmlString = '<html><head><title>Remote Window</title><link REL="StyleSheet" HREF="style.css" TYPE="text/css" MEDIA="screen">'
  htmlString += '\n<SCR' + 'IPT LANGUAGE="javascript">var message="If you wish to make a copy of this photo, please contact the owner or the site administrators.";function clickIE4(){if (event.button==2){alert(message);return false;}}';
  htmlString += 'function clickNS4(e){if (document.layers||document.getElementById&&!document.all){if (e.which==2||e.which==3){alert(message);return false;}}}';
  htmlString += 'if (document.layers){document.captureEvents(Event.MOUSEDOWN);document.onmousedown=clickNS4;}else if (document.all&&!document.getElementById){document.onmousedown=clickIE4;}';
  htmlString += 'document.oncontextmenu=new Function("alert(message);return false")</scr' + 'ipt></head>\n';

  htmlString += '<body marginwidth=0 marginheight=0 leftmargin=0 topmargin=0>'
  if(picUrlString)
	htmlString += '<table border="0" cellpadding="0" cellspacing="0" width="100%" height="100%"><tr><td width="100%" align="center"><A HREF=\"javascript:window.close();\"><IMG SRC=\"' + picUrlString + '\" BORDER=\"0\"></A></td></tr></table>'
  htmlString += '</body></html>'
  newWind.document.clear();
  newWind.document.write();
  newWind.document.writeln(htmlString)
  newWind.focus();
  newWind.document.close();
  return newWind;
}
}

function closeDep() 
{
	  if (!ns6 && newWind && newWind.open && !newWind.closed) newWind.close();
}

function print_years(start,negoffset,posoffset)
{
	if(start || negoffset)
	{
		end=(new Date()).getYear();
		if(end<1000)
			end+=1900;
		if(negoffset)
			start=end-negoffset;
		if(posoffset)
			end+=posoffset;
		for (;end>=start;end--)
		{
			document.write('<option>'+end);
		}
	}
	else
	{
		start=(new Date()).getYear();
		if(start<1000)
			start+=1900;
		end=start+posoffset;
		for (;end>=start;start++)
		{
			document.write('<option>'+start);
		}
	}

}

function tierMenu(objMenu,objImage)
{
         if (objMenu.style.display == "none")
         {
             objMenu.style.display = "";
             if(objImage) objImage.src = "images/minus.gif";
         }
         else
         {
             objMenu.style.display = "none";
             if(objImage) objImage.src = "images/plus.gif";
         }
}

function submitroll(src, oversrc, name, alt, field, value, form_no)
{
	this.src=src;
	this.oversrc=oversrc;
	this.name=name;
	this.alt=alt;
	this.write=submitroll_write;
	this.form_no=form_no;
	this.sendfield=field;
	this.sendvalue=value;
	this.formSubmitted=false;
}

function submitFormOnce(thisOb,sr)
{
   if (thisOb.formSubmitted){
   alert('It is recommended that you wait for the results of your previous request. If you are sure that you wish to submit this form again, you may do so.')
   thisOb.formSubmitted = false;
   return false;
}
else{ 
	if(sr=='accept' && findObj('emailaddr') && !findObj('emailaddr').value)
		if(!confirm('This site functions best if you provide an email address.  Please note that it is not revealed to other users of the site unless you choose.\n\nDo you wish to continue without entering an email address?'))
			return false;
   thisOb.formSubmitted = true;
   return true;
   }
}


function submitroll_write()
{
	var thisform = 'document.forms[\'' + this.name + '\']';
	submitRolls[this.name] = new Object();
	submitRolls[this.name].over = new Image();
	submitRolls[this.name].over.src = this.oversrc;
	submitRolls[this.name].out = new Image();
	submitRolls[this.name].out.src = this.src;

	if(!(document.forms[this.name]))
		if(this.form_no)
			thisform = 'document.forms[' + this.form_no + ']';
		else
			thisform = 'document.forms[' + (document.forms.length - 1) + ']';
		
	document.write
	(
		'<A onClick="return submitFormOnce(this,\''+ this.sendvalue +'\')" onMouseOver="if (document.images)document.images[\'' + this.name + "'].src=submitRolls['" + this.name + '\'].over.src"' +
		' onMouseOut="if (document.images)document.images[\'' + this.name + "'].src=submitRolls['" + this.name + '\'].out.src"' +
		' HREF="javascript:'
	);

	if (this.sendfield)
	{
		if (! this.sendvalue)
			this.sendvalue = 1;
		document.write(thisform, ".elements['", this.sendfield, "'].value='", this.sendvalue, "';");
	}

	document.write(thisform + '.submit();void(0);"');
	if (this.msg)document.write(' onClick="return confirm(\'' , this.msg, '\')"');
	document.write('>');

	document.write('<IMG SRC="' + this.src + '" ALT="' + this.alt + '" BORDER=0 NAME="' + this.name + '"');
	if (this.height)document.write(' HEIGHT=' + this.height);
	if (this.width)document.write(' WIDTH='  + this.width);
	if (this.otheratts)document.write(' ' + this.otheratts);
	document.write('></A>');
	if (this.sendfield && !(document.forms[document.forms.length - 1].elements[this.sendfield]))
	{
		document.write('<INPUT TYPE=HIDDEN NAME="' + this.sendfield + '">');
		document.forms[document.forms.length - 1].elements[this.sendfield].value='';
	}
}

//With no args, prints list with no aus and preselected countries at top.
//If args starts with 'Y' then print aus.
//If second arg is 'y'|'n', first arg is home country (9,'y')
function PrintCountries()
{//
var i,ar=arguments,showH=0,home=9;
if(_domainName.indexOf('eu.')==-1)
{	c = new Array('Afghanistan','Albania','Algeria','Andorra','Angola','Antarctica','Antigua and Barbuda','Argentina','Armenia','Australia','Austria','Azerbaijan','Bahrain','Bangladesh','Barbados','Belarus','Belgium','Belize','Benin','Bhutan','Bolivia','Bosnia and Herzegovina','Botswana','Brazil','Brunei','Bulgaria','Burkina Faso','Burma (Myanmar)','Burundi','Cambodia','Cameroon','Canada','Cape Verde','Cayman Islands','Central African Republic','Chad','Chile','China','Colombia','Comoros','Congo, Republic of','Costa Rica','Cote d\'Ivoire','Croatia','Cuba','Cyprus','Czech Republic','Denmark','Djibouti','Dominica','Dominican Republic','Ecuador','Egypt','El Salvador','Equatorial Guinea','Eritrea','Estonia','Ethiopia','Fiji','Finland','France','French Guiana','Gabon','Georgia','Germany','Ghana','Greece','Greenland (Kalaallit Nunaat)','Grenada','Guatemala','Guinea','Guinea-Bissau','Guyana','Haiti','Honduras','Hong Kong','Hungary','Iceland','India','Indonesia','Iran','Iraq','Ireland','Israel','Italy','Ivory Coast (Cote d\'Ivoire)','Jamaica','Japan','Jordan','Kazakstan','Kenya','Kiribati','Korea, North','Korea, South','Kuwait','Kyrgyzstan','Laos','Latvia','Lebanon','Lesotho','Liberia','Libya','Liechtenstein','Lithuania','Luxembourg','Macedonia','Madagascar','Malawi','Malaysia','Maldives','Mali','Malta','Marshall Islands','Mauritania','Mauritius','Mexico','Micronesia','Moldova','Monaco','Mongolia','Morocco','Mozambique','Myanmar','Namibia','Nauru','Nepal','Netherlands','New Zealand','Nicaragua','Niger','Nigeria','Norway','Oman','Pakistan','Palau','Panama','Papua New Guinea','Paraguay','Peru','Philippines','Poland','Portugal','Qatar','Romania','Russia','Rwanda','Sain','Saint Kitts and Nevis','Saint Lucia','Saint Vincent and the Grenadines','Samoa','San Marino','Sao Tome and Principe','Saudi Arabia','Senegal','Serbia and Montenegro','Seychelles','Sierra Leone','Singapore','Slovakia (Slovak Republic)','Slovenia','Solomon Islands','Somalia','South Africa','Spain','Sri Lanka','Sudan','Suriname','Swaziland','Sweden','Switzerland','Syria','Taiwan','Tajikistan','Tanzania','Thailand','The Bahamas','The Gambia','Togo','Tonga','Trinidad and Tobago','Tunisia','Turkey','Turkmenistan','Tuvalu','Uganda','Ukraine','United Arab Emirates','United Kingdom','United States of America','Uruguay','Uzbekistan','Vanuatu','Vatican City','Venezuela','Vietnam','Yemen','Zambia','Zimbabwe')
	t = new Array(9,31,60,75,127,189);
}
else
{
	c = new Array('Afghanistan','Albania','Algeria','American Samoa','Andorra','Angola','Anguilla','Antigua and Barbuda','Argentina','Armenia','Aruba','Australia','Austria','Azerbaijan','Bahamas','Bahrain','Bangladesh','Barbados','Belarus','Belgium','Belize','Benin','Bermuda','Bhutan','Bolivia','Bosnia and Herzegovina','Botswana','Brazil','Brunei Darussalam','Bulgaria','Burkina Faso','Burundi','Cambodia','Cameroon','Canada','Cape Verde','Cayman Islands','Central African Republic','Chad','Chile','China','Christmas Island','Colombia','Comoros','Congo','Congo, The Democratic Republic of the','Cook Islands','Costa Rica','Cote d\'Ivoire','Croatia','Cuba','Cyprus','Czech Republic','Denmark','Djibouti','Dominica','Dominican Republic','Ecuador','Egypt','El Salvador','Equatorial Guinea','Eritrea','Estonia','Ethiopia','Falkland Islands (Malvinas)','Faroe Islands','Fiji','Finland','France','French Guiana','French Polynesia','Gabon','Gambia','Georgia','Germany','Ghana','Gibraltar','Greece','Greenland','Grenada','Guadeloupe','Guam','Guatemala','Guernsey','Guinea','Guinea-Bissau','Guyana','Haiti','Holy See (Vatican City State)','Honduras','Hong Kong','Hungary','Iceland','India','Indonesia','Iran, Islamic Republic of','Iraq','Ireland','Isle of Man','Israel','Italy','Jamaica','Japan','Jersey','Jordan','Kazakhstan','Kenya','Kiribati','Korea, Democratic People\'s Republic of','Korea, Republic of','Kuwait','Kyrgyzstan','Lao People\'s Democratic Republic','Latvia','Lebanon','Lesotho','Liberia','Libyan Arab Jamahiriya','Liechtenstein','Lithuania','Luxembourg','Macao','Macedonia','Madagascar','Malawi','Malaysia','Maldives','Mali','Malta','Marshall Islands','Martinique','Mauritania','Mauritius','Mayotte','Mexico','Micronesia, Federated States of','Moldova, Republic of','Monaco','Mongolia','Montenegro','Montserrat','Morocco','Mozambique','Myanmar','Namibia','Nepal','Netherlands','Netherlands Antilles','New Caledonia','New Zealand','Nicaragua','Niger','Nigeria','Niue','Norfolk Island','Norway','Oman','Pakistan','Palau','Palestinian Territory','Panama','Papua New Guinea','Paraguay','Peru','Philippines','Pitcairn','Poland','Portugal','Puerto Rico','Qatar','Reunion','Romania','Russian Federation','Rwanda','Saint Helena','Saint Kitts and Nevis','Saint Lucia','Saint Pierre and Miquelon','Saint Vincent and the Grenadines','Samoa','San Marino','Sao Tome and Principe','Saudi Arabia','Senegal','Serbia','Seychelles','Sierra Leone','Singapore','Slovakia','Slovenia','Solomon Islands','Somalia','South Africa','South Georgia and the South Sandwich Islands','Spain','Sri Lanka','Sudan','Suriname','Svalbard and Jan Mayen','Swaziland','Sweden','Switzerland','Syrian Arab Republic','Taiwan','Tajikistan','Tanzania, United Republic of','Thailand','Timor-Leste','Togo','Tonga','Trinidad and Tobago','Tunisia','Turkey','Turkmenistan','Turks and Caicos Islands','Tuvalu','Uganda','Ukraine','United Arab Emirates','United Kingdom','United States','Uruguay','Uzbekistan','Vanuatu','Venezuela','Vietnam','Virgin Islands, British','Virgin Islands, U.S.','Western Sahara','Yemen','Zambia','Zimbabwe');
}

	if((showH=(ar[0]=='Y' || ar[0]=='y')) || ar[0]=='N' || ar[0]=='n') i=1;
	else if((showH=(ar[1]=='Y' || ar[1]=='y')) || ar[1]=='N' || ar[1]=='n'){
		home=ar[0];
		i=2;}
	else i=(showH=0);
			//If no arguements, print default pre-list
	if(i==ar.length){ for(i=0;t[i];i++) if (t[i]!=home || showH) document.write('<option>'+c[t[i]]);}
	else for (i; i < ar.length; i++) document.write('<option>'+c[ar[i]]);
	document.write('<option>-----------------------------------');
	for(i=0;c[i];i++) if (i!=home || showH) document.write('<option>'+c[i]);
}

function printpage() {
window.print();  
}

function CheckAll(f)
{
	if(!f)
		f=document.createMessage;
	for (var i=0;i<f.elements.length;i++)
	{
		var e = f.elements[i];
		if (e.name!='allbox' && e.name!='includeBulkMail')
			e.checked = f.allbox.checked;
	}
}

function adminPopUp(admin,user,fname,lname,fyear)
{
	
	newwin=window.open('', 'admin_remote', 'left=50,top=50,toolbar=no,location=no,directories=no,menubar=no,scrollbars=auto,status=no,resizable=yes');
   newwin.document.write('<HEAD>');
   newwin.document.write('<title>Admin Edit</title><base target="main">');
   newwin.document.write('</HEAD>');
   newwin.document.write('<FRAMESET ROWS=25,*>');
   newwin.document.write('   <FRAME src="" NAME="adminHeader" scrolling="no" noresize target="adminBody">');
   newwin.document.write('   <FRAME src="" NAME="adminBody">');
   newwin.document.write('</FRAMESET>');
   newwin.document.close();
   newwin.adminHeader.document.write('<html>');
   newwin.adminHeader.document.write('<HEAD>');
   newwin.adminHeader.document.write('<TITLE>Admin Header</TITLE>');
   newwin.adminHeader.document.write('<link REL="StyleSheet" HREF="style.css" TYPE="text/css" MEDIA="screen"><base target="main"></HEAD>');
   newwin.adminHeader.document.write('<body marginwidth=0 marginheight=0 leftmargin=0 topmargin=0>');
   newwin.adminHeader.document.write('<center><b>You are currently logged in as ' +fname+ ' ' +lname+ ' (' +fyear+'), <a href="#" onclick="document.forms[0].submit();top.setTimeout(\'top.close()\',2000);">click here</a> to log out.</b></center><form method="post" action="ocd.aspx"><input type="hidden" name="action" value="logout"><input type="hidden" name="code" value="'+user+'"></form></body></html>');
	newwin.adminHeader.document.close();

   newwin.adminBody.document.write('<html>');
   newwin.adminBody.document.write('<HEAD>');
   newwin.adminBody.document.write('<TITLE>Admin Edit Body</TITLE>');
   newwin.adminBody.document.write('</HEAD>');
   newwin.adminBody.document.write('<body marginwidth=0 marginheight=0 leftmargin=0 topmargin=0 onload="document.forms[0].submit();">');
   newwin.adminBody.document.write('<form method="POST" action="ocd.aspx"><input type="hidden" name="login" value="'+user+'"><input type="hidden" name="code" value="'+admin+'"><input type="hidden" name="action" value="admin_edit"></form></body></html>');
	newwin.adminBody.document.close();
	newwin.focus();
	return false;
}

function setDataType(cValue)
  {
    // THIS FUNCTION CONVERTS DATES AND NUMBERS FOR PROPER ARRAY
    // SORTING WHEN IN THE SORT FUNCTION
    var isDate = new Date(cValue);
    if (isDate == "NaN")
      {
        if (isNaN(cValue))
          {
            // THE VALUE IS A STRING, MAKE ALL CHARACTERS IN
            // STRING UPPER CASE TO ASSURE PROPER A-Z SORT
            cValue = cValue.toUpperCase();
            return cValue;
          }
        else
          {
            // VALUE IS A NUMBER, TO PREVENT STRING SORTING OF A NUMBER
            // ADD AN ADDITIONAL DIGIT THAT IS THE + TO THE LENGTH OF
            // THE NUMBER WHEN IT IS A STRING
            var myNum;
            myNum = String.fromCharCode(48 + cValue.length) + cValue;
            return myNum;
          }
        }
  else
      {
        // VALUE TO SORT IS A DATE, REMOVE ALL OF THE PUNCTUATION AND
        // AND RETURN THE STRING NUMBER
        //BUG - STRING AND NOT NUMERICAL SORT .....
        // ( 1 - 10 - 11 - 2 - 3 - 4 - 41 - 5  etc.)
        var myDate = new String();
        myDate = isDate.getFullYear() + " " ;
        myDate = myDate + isDate.getMonth() + " ";
        myDate = myDate + isDate.getDate(); + " ";
        myDate = myDate + isDate.getHours(); + " ";
        myDate = myDate + isDate.getMinutes(); + " ";
        myDate = myDate + isDate.getSeconds();
        //myDate = String.fromCharCode(48 + myDate.length) + myDate;
        return myDate ;
      }
  }

function sortTable(col, tableToSort)
  {
    var iCurCell = col + tableToSort.cols;
    var totalRows = tableToSort.rows.length;
    var bSort = 0;
    var colArray = new Array();
    var oldIndex = new Array();
    var indexArray = new Array();
    var bArray = new Array();
    var newRow;
    var newCell;
    var i;
    var c;
    var j;

    document.body.style.cursor = "wait";

    // ** POPULATE THE ARRAY colArray WITH CONTENTS OF THE COLUMN SELECTED
    for (i=1; i < tableToSort.rows.length; i++)
      {
        colArray[i - 1] = setDataType(tableToSort.cells(iCurCell).innerText);
        iCurCell = iCurCell + tableToSort.cols;
      }
    // ** COPY ARRAY FOR COMPARISON AFTER SORT
    for (i=0; i < colArray.length; i++)
      {
        bArray[i] = colArray[i];
      }
    // ** SORT THE COLUMN ITEMS
    //alert ( colArray );
    colArray.sort();
    //alert ( colArray );
    for (i=0; i < colArray.length; i++)
      { // LOOP THROUGH THE NEW SORTED ARRAY
        indexArray[i] = (i+1);
        for(j=0; j < bArray.length; j++)
          { // LOOP THROUGH THE OLD ARRAY
            if (colArray[i] == bArray[j])
              {  // WHEN THE ITEM IN THE OLD AND NEW MATCH, PLACE THE
                // CURRENT ROW NUMBER IN THE PROPER POSITION IN THE
                // NEW ORDER ARRAY SO ROWS CAN BE MOVED ....
                // MAKE SURE CURRENT ROW NUMBER IS NOT ALREADY IN THE
                // NEW ORDER ARRAY
                for (c=0; c<i; c++)
                  {
                    if ( oldIndex[c] == (j+1) )
                    {
                      bSort = 1;
                    }
                      }
                      if (bSort == 0 && !oldIndex[i])
                        {
                          oldIndex[i] = (j+1);
                        }
                          bSort = 0;
                        }
          }
    }
  // ** SORTING COMPLETE, ADD NEW ROWS TO BASE OF TABLE ....
  for (i=0; i<oldIndex.length; i++)
    {
      newRow = tableToSort.insertRow();
      for (c=0; c<tableToSort.cols; c++)
        {
          newCell = newRow.insertCell();
          newCell.innerHTML = tableToSort.rows(oldIndex[i]).cells(c).innerHTML;
          newCell.style.display = tableToSort.rows(oldIndex[i]).cells(c).style.display;
	  newCell.className = 'cell';
        }
      }
  //MOVE NEW ROWS TO TOP OF TABLE ....
  for (i=1; i<totalRows; i++)
    {
      tableToSort.moveRow((tableToSort.rows.length -1),1);
    }
  //DELETE THE OLD ROWS FROM THE BOTTOM OF THE TABLE ....
  for (i=1; i<totalRows; i++)
    {
      tableToSort.deleteRow();
    }
    document.body.style.cursor = "";

  }

function hideRow (rowIndex) {
  var table = document.all ? document.all.logTable :
              document.getElementById('logTable');
  for (var c = 0; c < table.cols; c++)
    table.rows[rowIndex].cells[c].style.display = 'none';

}
function showAll () {
  var table = document.all ? document.all.logTable :
              document.getElementById('logTable');
  for (var r = 0; r < table.rows.length; r++)
	  for (var c = 0; c < table.cols; c++)
	    table.rows[r].cells[c].style.display = '';

}

function filter(colIndex,thisSelect)
{
  var table = document.all ? document.all.logTable :
              document.getElementById('logTable');

	if(thisSelect.selectedIndex>0)
	  for (var r = 1; r < table.rows.length; r++)
	  {
	  	if(document.all.filterMode[1].checked==true)
		{
		    if(table.rows[r].cells[colIndex].innerText.toUpperCase()!=thisSelect.value.toUpperCase())
	   		 	hideRow(r);
	  	}
	  	else
		{
		    if(table.rows[r].cells[colIndex].innerText.toUpperCase()==thisSelect.value.toUpperCase())
	   		 	hideRow(r);
	   	}
     }
   else
   	showAll();
}
