/********** check all start **********/
var checkflag = "false";
function check(field) {
var field = document.getElementsByName(field);
if (checkflag == "false") {
for (i = 0; i < field.length; i++) {
field[i].checked = true;}
checkflag = "true";
return "Uncheck All"; }
else {
for (i = 0; i < field.length; i++) {
field[i].checked = false; }
checkflag = "false";
return "Check All"; }
}
/********** check all end **********/
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];}
}
/****************************************/
//  The "refresh" function 
/* JavaScript1.1
var sURL = unescape(window.location.pathname);
function refresh()
{
    window.location.href = sURL;
}
*/
function refresh()
{
    window.location.reload( false );
}
/****************************************/
/** select file link **/
/*
function storeCaret (textEl) {
   if (textEl.createTextRange)
     textEl.caretPos = document.selection.createRange().duplicate();
}
*/   
function insertAtCaret(myField, myValue, url) { 
    if (myValue!='') {
    //myValue = '<a href="'+url+'download.php?id='+ myValue +'">Download File</a>' 
    myValue = '%%'+url+'index.php?page=save_attach&attach_id='+ myValue +'%%Download File%%'
    //IE support
    if (document.selection) {
    myField.focus();
    sel = document.selection.createRange();
    sel.text = myValue;
    }
    //MOZILLA/NETSCAPE support
    else if (myField.selectionStart || myField.selectionStart =='0') {
    var startPos = myField.selectionStart;
    var endPos = myField.selectionEnd;
    myField.value = myField.value.substring(0, startPos)
    + myValue
    + myField.value.substring(endPos, myField.value.length);
    } else {
    myField.value += myValue;
    }
    }
}
/****************************************/
/****************************************/
/****************************************/
/********* News Scroller start **********/
<!-- Random Img Begin
// Set up the image files to be used.
var theImages = new Array() // do not change this
// To add more image files, continue with the
// pattern below, adding to the array.

theImages[0] = 'images/random1/01.jpg'
theImages[1] = 'images/random1/02.jpg'
theImages[2] = 'images/random1/03.jpg'
//theImages[3] = 'images/random1/04.jpg'

// do not edit anything below this line

var j = 0
var p = theImages.length;
var preBuffer = new Array()
for (i = 0; i < p; i++){
   preBuffer[i] = new Image()
   preBuffer[i].src = theImages[i]
}
var whichImage = Math.round(Math.random()*(p-1));
function showImage(){
document.write('<img src="'+theImages[whichImage]+'" width="460">');
}

// Random Img End -->

<!--
/*Example message arrays for the two demo scrollers*/
/*
var pausecontent=new Array()
pausecontent[0]='<strong>02.16.05</strong> Whiskey Priest St. Patricks Day <a href="#">more...</a>'
pausecontent[1]='<strong>03.19.05</strong> Baci New Menu <a href="#">more...</a>'
pausecontent[2]='<strong>03.25.05</strong> CDA Foie Gras Promotion <a href="#">more...</a>'
pausecontent[3]='<strong>04.01.05</strong> April Fool\'s Lucky Draw <a href="#">more...</a>'
*/
/*
var pausecontent2=new Array()
pausecontent2[0]='<a href="http://www.news.com">News.com: Technology and business reports</a>'
pausecontent2[1]='<a href="http://www.cnn.com">CNN: Headline and breaking news 24/7</a>'
pausecontent2[2]='<a href="http://news.bbc.co.uk">BBC News: UK and international news</a>'
*/
//-->
/********* News Scroller end **********/

/***********************************************
* News scroller function start
***********************************************/
function pausescroller(content, divId, divClass, delay){
this.content=content //message array content
this.tickerid=divId //ID of ticker div to display information
this.delay=delay //Delay between msg change, in miliseconds.
this.mouseoverBol=0 //Boolean to indicate whether mouse is currently over scroller (and pause it if it is)
this.hiddendivpointer=1 //index of message array for hidden div
document.write('<div id="'+divId+'" class="'+divClass+'" style="position: relative; overflow: hidden"><div class="innerDiv" style="position: absolute; width: 100%" id="'+divId+'1">'+content[0]+'</div><div class="innerDiv" style="position: absolute; width: 100%; visibility: hidden" id="'+divId+'2">'+content[1]+'</div></div>')
var scrollerinstance=this
if (window.addEventListener) //run onload in DOM2 browsers
window.addEventListener("load", function(){scrollerinstance.initialize()}, false)
else if (window.attachEvent) //run onload in IE5.5+
window.attachEvent("onload", function(){scrollerinstance.initialize()})
else if (document.getElementById) //if legacy DOM browsers, just start scroller after 0.5 sec
setTimeout(function(){scrollerinstance.initialize()}, 500)
}

// -------------------------------------------------------------------
// initialize()- Initialize scroller method.
// -Get div objects, set initial positions, start up down animation
// -------------------------------------------------------------------

pausescroller.prototype.initialize=function(){
this.tickerdiv=document.getElementById(this.tickerid)
this.visiblediv=document.getElementById(this.tickerid+"1")
this.hiddendiv=document.getElementById(this.tickerid+"2")
this.visibledivtop=parseInt(pausescroller.getCSSpadding(this.tickerdiv))
//set width of inner DIVs to outer DIV's width minus padding (padding assumed to be top padding x 2)
this.visiblediv.style.width=this.hiddendiv.style.width=this.tickerdiv.offsetWidth-(this.visibledivtop*2)+"px"
this.getinline(this.visiblediv, this.hiddendiv)
this.hiddendiv.style.visibility="visible"
var scrollerinstance=this
document.getElementById(this.tickerid).onmouseover=function(){scrollerinstance.mouseoverBol=1}
document.getElementById(this.tickerid).onmouseout=function(){scrollerinstance.mouseoverBol=0}
if (window.attachEvent) //Clean up loose references in IE
window.attachEvent("onunload", function(){scrollerinstance.tickerdiv.onmouseover=scrollerinstance.tickerdiv.onmouseout=null})
setTimeout(function(){scrollerinstance.animateup()}, this.delay)
}


// -------------------------------------------------------------------
// animateup()- Move the two inner divs of the scroller up and in sync
// -------------------------------------------------------------------

pausescroller.prototype.animateup=function(){
var scrollerinstance=this
if (parseInt(this.hiddendiv.style.top)>(this.visibledivtop+5)){
this.visiblediv.style.top=parseInt(this.visiblediv.style.top)-5+"px"
this.hiddendiv.style.top=parseInt(this.hiddendiv.style.top)-5+"px"
setTimeout(function(){scrollerinstance.animateup()}, 50)
}
else{
this.getinline(this.hiddendiv, this.visiblediv)
this.swapdivs()
setTimeout(function(){scrollerinstance.setmessage()}, this.delay)
}
}

// -------------------------------------------------------------------
// swapdivs()- Swap between which is the visible and which is the hidden div
// -------------------------------------------------------------------

pausescroller.prototype.swapdivs=function(){
var tempcontainer=this.visiblediv
this.visiblediv=this.hiddendiv
this.hiddendiv=tempcontainer
}

pausescroller.prototype.getinline=function(div1, div2){
div1.style.top=this.visibledivtop+"px"
div2.style.top=Math.max(div1.parentNode.offsetHeight, div1.offsetHeight)+"px"
}

// -------------------------------------------------------------------
// setmessage()- Populate the hidden div with the next message before it's visible
// -------------------------------------------------------------------

pausescroller.prototype.setmessage=function(){
var scrollerinstance=this
if (this.mouseoverBol==1) //if mouse is currently over scoller, do nothing (pause it)
setTimeout(function(){scrollerinstance.setmessage()}, 100)
else{
var i=this.hiddendivpointer
var ceiling=this.content.length
this.hiddendivpointer=(i+1>ceiling-1)? 0 : i+1
this.hiddendiv.innerHTML=this.content[this.hiddendivpointer]
this.animateup()
}
}

pausescroller.getCSSpadding=function(tickerobj){ //get CSS padding value, if any
if (tickerobj.currentStyle)
return tickerobj.currentStyle["paddingTop"]
else if (window.getComputedStyle) //if DOM2
return window.getComputedStyle(tickerobj, "").getPropertyValue("padding-top")
else
return 0
}
/***********************************************
* News scroller function end
***********************************************/

/***********************************************
* WYSIWYG
***********************************************/
// inserts a link by prompting the user for a url
// bbcode modified to add textarea, link_type, prompt_text argument, instead of hardcode
//function insertlink()
/***************************************************************/
function insertlink(textarea, link_type, prompt_text)
{
    // our textfield
    //var textarea = document.getElementById("The_TextArea");

    // our link
    var url = prompt("Please enter the "+ link_type, prompt_text);
    var link = "%%" + url + "%%" + url + "%%";

    if(!textarea.setSelectionRange)
    {
        // get selected text
        var selected = document.selection.createRange().text; 

        if(selected.length <= 0)
        { 
            // no text was selected so add the link to the end
            textarea.value += link;
        }
        else
        {
            // replace the selection with the link
            document.selection.createRange().text = "%%" + url + "%%" + selected + "%%";   
        }
    }
    else
    {
        // the text before the selection
        var pretext = textarea.value.substring(0, textarea.selectionStart);

        // the text after the selection
        var posttext = textarea.value.substring(textarea.selectionEnd, textarea.value.length);

        // update the text field
        textarea.value = pretext + "%%" + url + "%%" + selected + "%%" + posttext;
    }

    // set the focus on the text field
    textarea.focus();
}
/***************************************************************/
// bbcode modified to add textarea argument, instead of hardcode
// insert: bold, italic
/***************************************************************/
function insertcode(textarea, tag, desc)
{
    // our textfield
    // var textarea = document.getElementById("The_TextArea");

    // our open tag
    // var open = "[" + tag + ">";
	var open = "<" + tag + ">";
	
    // our close tag
    // var close = "[/" + tag + ">";
	var close = "</" + tag + ">";
	
    if(!textarea.setSelectionRange)
    {
        var selected = document.selection.createRange().text; 
        if(selected.length <= 0)
        { 
            // no text was selected so prompt the user for some text
            textarea.value += open + prompt("Please enter the text you'd like to " + desc, "") + close;
        }
        else
        {
            // put the code around the selected text
            document.selection.createRange().text = open + selected + close; 
        }

    }
    else
    {
        // the text before the selection
        var pretext = textarea.value.substring(0, textarea.selectionStart);
        
        // the selected text with tags before and after
        var codetext = open + textarea.value.substring(textarea.selectionStart, textarea.selectionEnd) + close;

        // the text after the selection
        var posttext = textarea.value.substring(textarea.selectionEnd, textarea.value.length);
        
        // check if there was a selection
        if(codetext == open + close)
        {
            //prompt the user
            codetext = open + prompt("Please enter the text you'd like to " + desc, "") + close;
        }

        // update the text field
        textarea.value = pretext + codetext + posttext;
    }

    // set the focus on the text field
    textarea.focus();
}
/***************************************************************/
/***************************************************************
Insert string onButtonClick at cursor position in textarea 
and not at the end of string

Please Use the InsertText Function:
  The First argument is the textbox/textarea control: 
  document.[formName].[textareaName]
  e.g. document.paste_pt_form.pasted_pt 
  the next is the Text to be inserted...
****************************************************************/
function InsertText(input, insTexte)
{

startTag = '';
endTag = '';


     if (input.createTextRange)
     {
      var text;
      input.focus(input.caretPos);
      input.caretPos = document.selection.createRange().duplicate();
      if(input.caretPos.text.length>0)
      {
       input.caretPos.text = startTag + input.caretPos.text + endTag;
      }
      else
      {
       input.caretPos.text = startTag + " " + insTexte + " " + endTag;
      }
     }
     else input.value += startTag + insTexte + endTag;
}
/****************************************************************/
/****************************************************************/
// Legacy functions
// some functions: img, hyperlink may still be used
/****************************************************************/
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); return x;
}

function showHideLayers() 
{
	var i,p,v,obj,args=showHideLayers.arguments;
  	for (i=0; i<(args.length-2); i+=3) if ((obj=findObj(args[i]))!=null) 
	{ 
		v=args[i+2];
    	if (obj.style) 
		{ 
			obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; 
		}
    	obj.visibility=v; 
	}
}

function doCopyValue() 
{
    document.forms[0].content.value = "" + editor.document.body.innerHTML + "";
}

function trimIt(trimStr)
{    
	var i = trimStr.length;
	while (trimStr.charAt(0) == " ")
            {          
		trimStr = trimStr.substring(1,i) 
		i = i-1;
	}
	while (trimStr.charAt(trimStr.length-1) == " ")
	{
		trimStr = trimStr.substring( 0,trimStr.length-1) 
	}
	return trimStr;

}

function doMakeBold() 
{
    // Get a text range for the selection
    var tr = frames.editor.document.selection.createRange()
    tr.execCommand("Bold")
    tr.select()
    doCopyValue();
}

function doCopy() 
{
    // Get a text range for the selection
    var tr = frames.editor.document.selection.createRange()
    tr.execCommand("Copy", false)
    doCopyValue();
}

function doPaste() 
{
    // Get a text range for the selection
    var tr = frames.editor.document.selection.createRange()
    tr.execCommand("Paste", false)
    doCopyValue();
}

function doInsertUL() 
{
    // Get a text range for the selection
    var tr = frames.editor.document.selection.createRange()
    tr.execCommand("InsertUnorderedList", false)
    doCopyValue();
}

function doIndent() 
{
    // Get a text range for the selection
    var tr = frames.editor.document.selection.createRange()
    tr.execCommand("Indent", false)
    doCopyValue();
}

function doUnIndent() 
{
    // Get a text range for the selection
    var tr = frames.editor.document.selection.createRange()
    tr.execCommand("Outdent", false)
    doCopyValue();
}

function doMakeItalic() 
{
    var tr = frames.editor.document.selection.createRange()
    tr.execCommand("Italic")
    tr.select()
    doCopyValue();    
}

function doFontName(what)
{
    var tr = frames.editor.document.selection.createRange()
    tr.execCommand("FontName", false, what)
    tr.select()
    doCopyValue();    
}

function doFontSize(what)
{
    var tr = frames.editor.document.selection.createRange()
    tr.execCommand("FontSize", false, what)
    tr.select()
    doCopyValue();    
}


function doInsertLink()
{
    var tr = frames.editor.document.selection.createRange()
    tr.execCommand("CreateLink")
    tr.select()
    doCopyValue();    
}

function doUnLink()
{
    var tr = frames.editor.document.selection.createRange()
    tr.execCommand("UnLink")
    tr.select()
    doCopyValue();    
}

function doImage(img)
{
    var tr = frames.editor.document.selection.createRange()
    tr.execCommand("InsertImage", 0, img)
    tr.select()
    doCopyValue();    
}

function doJustify(where)
{
    var tr = frames.editor.document.selection.createRange()
    if (where == 'Left') tr.execCommand("JustifyLeft")
    else if (where == 'Right') tr.execCommand("JustifyRight")
    else if (where == 'Center') tr.execCommand("JustifyCenter")
    tr.select()
    doCopyValue();  
}

function doHorizRule()
{
    var tr = frames.editor.document.selection.createRange()
    tr.execCommand("InsertHorizontalRule")
    tr.select()
    doCopyValue();    
}


function doFieldSet()
{
    var tr = frames.editor.document.selection.createRange()
    tr.execCommand("InsertFieldset")
    tr.select()
    doCopyValue();    
}

function doTable()
{
    var tr = frames.editor.document.selection.createRange()
    tr.pasteHTML("<table border='1'><tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr><tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr><tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr></table>")
    tr.select()
    doCopyValue();    
}

function doRenderHTML() 
{
	editor.document.body.innerHTML=document.forms[0].content.value;
}

/*********************************************************************
						insert expressions
*********************************************************************/
tags = new Array();

//insert Salutation, First name, Last name, etc.
function doText(text)
{
    var tr = frames.editor.document.selection.createRange()
    tr.pasteHTML("%"+text+"%")
    tr.select()
    doCopyValue();    
}

//insert URL
function doLink(link_type, prompt_text) {
	//prompt
	url = prompt("Enter " + link_type, prompt_text);
	
	if ((url != null) && (url != "")){
			text = prompt("Enter the text to be displayed for the " + link_type, "");
			
			if((text != null) && (text != "")){
				display_text = text;
			}else{
				display_text = url;
			}
			var tr = frames.editor.document.selection.createRange()
			// insert %%xxxx%%xxxx%%  style markup
    		tr.pasteHTML("%%"+url+"%%"+display_text+"%%")
    		tr.select()
    		doCopyValue(); 
		}
}

//file link
function doFileLink(file) {
// insert  $$file#file ID#displayed text$$  style markup
	file_id = file;
	//prompt
	text = prompt("Enter the text to be displayed for the link","");
		if ((file_id != null) && (file_id != "")){
			if((text != null) && (text != "")){
				display_text = text;
			}else{
				display_text = file_id;
			}
			var tr = frames.editor.document.selection.createRange()
    		tr.pasteHTML("$$file#"+file_id+"#"+display_text+"$$")
    		tr.select()
    		doCopyValue(); 
		}
}
/*********************************************************************/
function doInsertText(insert_text) {
// insert %xxxx% style markup
	paste_pt_form.pasted_pt.value += "%"+insert_text+"% ";
	paste_pt_form.pasted_pt.focus();
}

function doInsertLink(url, display_text) {
// insert >xxxx xxxx style markup
	paste_pt_form.pasted_pt.value += ">" + display_text + "\n" + url + " \n";
	paste_pt_form.pasted_pt.focus();
}

function doInsertLinkHTML(url, display_text) {
// insert %%xxxx%%xxxx%% style markup
	paste_pt_form.pasted_pt.value += "%%" + url + "%%" + display_text + "%% \n";
	paste_pt_form.pasted_pt.focus();
}

//jump menu
function MM_jumpMenu(targ,selObj,restore){
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
/*********************************************************************/


