/*emulate insertAdjacentHTML in Netscape 6/Mozilla*/
/*http://www.faqts.com/knowledge_base/view.phtml/aid/5756*/

if(typeof HTMLElement!="undefined" && !
HTMLElement.prototype.insertAdjacentElement){
	HTMLElement.prototype.insertAdjacentElement = function
(where,parsedNode)
	{
		switch (where){
		case 'beforeBegin':
			this.parentNode.insertBefore(parsedNode,this)
			break;
		case 'afterBegin':
			this.insertBefore(parsedNode,this.firstChild);
			break;
		case 'beforeEnd':
			this.appendChild(parsedNode);
			break;
		case 'afterEnd':
			if (this.nextSibling) 
this.parentNode.insertBefore(parsedNode,this.nextSibling);
			else this.parentNode.appendChild(parsedNode);
			break;
		}
	}

	HTMLElement.prototype.insertAdjacentHTML = function
(where,htmlStr)
	{
		var r = this.ownerDocument.createRange();
		r.setStartBefore(this);
		var parsedHTML = r.createContextualFragment(htmlStr);
		this.insertAdjacentElement(where,parsedHTML)
	}


	HTMLElement.prototype.insertAdjacentText = function
(where,txtStr)
	{
		var parsedText = document.createTextNode(txtStr)
		this.insertAdjacentElement(where,parsedText)
	}
}
//Submit returns true if form hasnt been submitted. Uses global below
var formSubmitted = false;
var WPG_selectedTemp = "";

function CreateBookmarkLink() {
	title = "Harnesslink.com - Harness Racing Portal";
	url = "http://www.harnesslink.com/";
	if (window.sidebar) {
		// Mozilla Firefox Bookmark
			window.sidebar.addPanel(title, url,"");
	}
	else if( window.external ) {
		// IE Favorite
			window.external.AddFavorite( url, title);
	}
	else if(window.opera && window.print) {
			alert('please use IE browser!')
	}
}

function dropDMenu() {
	if (document.all&&document.getElementById) {
		navRoot = document.getElementById("nav");
		for (i=0; i<navRoot.childNodes.length; i++) {
		node = navRoot.childNodes[i];
		if (node.nodeName=="LI") {
		node.onmouseover=function() {
		this.className+=" over";
		  }
		  node.onmouseout=function() {
		  this.className=this.className.replace(" over", "");
		   }
		   }
		  }
	 }
}

function submitOnce()
{
    var allowSubmit = !formSubmitted;
    formSubmitted = true;
    if (!allowSubmit)
    {
        alert('You have already submitted this form. You may only submit once.');
        return false;
    }
    return true;     
}

//Show a please wait message while page unloads
function busyMessage()
{
    //window.status='Opening new page...'; 
    //document.body.style.cursor='wait';
    return true;
}
//Cancels above message
function readyMessage()
{
    //window.status='Harnesslink'; 
    //document.body.style.cursor='auto';
    return true;
}  
//Shows obj's ALT text in a popup message
function PopupAlt(obj)
{
    var msg;
    if (obj.alt != null)
    {
        msg =  obj.alt;    
    }
    else
    {
        msg =  obj.title;
    }
    alert("HARNESSLINK HINT: "+msg);  
}

//disables the right-click menu for an image
function DisableRClick()
{
    //IE only:
//    if (!document.layers)
//    {
//        if (event.button==2)
//        {
//            alert("Image is (c) copyright");
//        }
//    }
//    return false;
}
function SetDivText(windowName, divID, text)
{
    //ie only version:
    windowName.all.divID.innerHTML = text;
}
function GetDivText(windowName, divID)
{
    //ie only version:
    return windowName.all.divID.innerHTML;
}


function MediaViewer(MI_id)
{
// Modify Kimiko - 03/06/04 - start
// ----------------------------------------------------------
//    mediaWindow = window.open('../www/MediaViewer.cgi?ID='+MI_id,'','scrollbars=yes,resizable=yes,width=690,height=480');
    mediaWindow = window.open('/www/MediaViewer.cgi?ID='+MI_id,'','scrollbars=yes,resizable=yes,width=690,height=480');
// ----------------------------------------------------------
// Kimiko - 03/06/04 - end
    mediaWindow.focus();
    return void(0);
}

// Add Kimiko - 15/12/03 - start
//    to create photo album page and use another template for viewer )
// ----------------------------------------------------------
function PhotoViewer(MI_id)
{
    photoWindow = window.open('../www/PhotoViewer.cgi?ID='+MI_id,'','scrollbars=yes,resizable=yes,width=690,height=480');
    photoWindow.focus();
    return void(0);
}
// ----------------------------------------------------------
// Kimiko - 15/12/03 - end

function ViewAllEventRaces(eventId, showResults)
{
    var url="RaceDetails.cgi";
    if (showResults){url="RaceResults.cgi"};
    
    if(confirm('This will show all races in this event. This page may take a long time to download as it contains details of many races. For faster viewing, it is recommended you view races one at a time.\n\nReally view all races in this event?'))
    {document.location.href=url+'?allRaces=1&EVENT_ID='+eventId}
}
function selectClasses(obj, classPrefix)
//sets all objects with className of classPrefixOn to classPrefixOff and sets obj's class to classPrefixOn
{	
	//unselect all of the menuOn's first first
	var i = 0;
    while(i < document.all.length)
    {
        tmpObj = document.all[i];			
		if (tmpObj.className == classPrefix+'On')
		{
			tmpObj.className =  classPrefix+'Off'
		}
   	    i++;
   	}
	obj.className = classPrefix+'On';
}

function saveFavourite(pageUrl, pageTitle)
{
    if(ie())
    {
        window.external.AddFavorite(pageUrl, pageTitle);
    }
    else
    {
        alert('To save this page as a bookmark to visit later, follow these steps:\n\n1. Click OK below.\n2. Press CTRL+D\n\nYou page will then be added to your list of bookmarks.');
    }
}
//toggles sibling of obj, or if defaultValue is set then sets visability to defaultValue
function ToggleMe(obj, defaultValue)
{	
        var sibling = GetToggleSibling(obj);
        if (sibling == null)
            return null;
        else
        {
            if (""+defaultValue == "undefined")
                return ToggleObj( sibling );
            else
                return setObjVisible( sibling, defaultValue );
        }
}

function GetToggleSibling(obj)
{
    //find parent object
	var parent = obj;
	while(parent.getAttribute('n6toggler') != "parent" && parent.parentNode)
	{
	    parent = parent.parentNode;
	}
	if (parent.getAttribute('n6toggler') != "parent")
	{
	    alert("Could not find parent object to toggle")
	    return null;
    }
    else
    {
        //find closest child object
    	var child = parent;	
    	var i = 1;
		var l = parent.getElementsByTagName("*");

		//var l = parent.all.length;
    	while(i < l.length  && child.getAttribute('n6toggler') != "child")
    	{
    	    //more = confirm (i+". <"+child.tagName+"> "+ child.id);
    	    child = l[i];
    	    i++;
    	}
    	if (child.getAttribute('n6toggler') != "child")
    	{
    	    alert("Could not find child object to toggle");
    	    return null;
        }
        else
        {
            return child;
        }
    }
}
function isMozilla()
{
	return (window.sidebar)?true:false;
}
function ie()
{
	ns4 = (document.layers)? true:false;
	ie4 = (document.all)? true:false;
	if (ns4) return false;
	if (ie4) return true;
	alert("This site has features that are not supported by your browser");
}

function GetLayer(name)
{
	if (ie()) layer = 'document.all["' + name  +'"]';
    else layer = "document." + name;
	return eval(layer);
}

function ToggleTable(tableName)
{
		var visible;
		var strTab = eval(tableName)
		return ToggleObj(strTab);
}
function ToggleObj(obj, defaultValue)
{
		var visible;
		var strTab = obj;	
		if (strTab.style.display == "none" ) {
			visible = true;
			strTab.style.display = "block"
		}
		else if (strTab.style.display == "block") {
			visible = false;
			strTab.style.display = "none"
		}

		return visible;
}
function setObjVisible(obj, show)
{
		var visible;
		var strTab = obj;	
		if (show) {
			visible = true;
			strTab.style.display = "block"
		}
		else 
		{
			visible = false;
			strTab.style.display = "none"
		}
		return visible;
}

function ToggleTableButton(name)
{
    var visible = ToggleTable(name+"Sub");
    var buttonTable = eval(name+"Button");
    if (visible)
        buttonTable.className = "dropMenuOn";
	else
        buttonTable.className = "dropMenuOff";
}

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 SetCookie(name, value, days_till_expires) 
{   
   var today = new Date()
   var expires = new Date()
   expires.setTime(today.getTime() + 1000*60*60*24* days_till_expires)
   
   document.cookie = name + "=" + escape(value)   + ((expires == null) ? "" : ("; expires=" + expires.toGMTString()))
}

function GetCookie(Name) 
{
   var search = Name + "="
   if (document.cookie.length > 0) 
   { // if there are any cookies
      offset = document.cookie.indexOf(search)
       if (offset != -1)
       { // if cookie exists
          offset += search.length
          // set index of beginning of value
         end = document.cookie.indexOf(";", offset)
          // set index of end of cookie value
         if (end == -1)
             end = document.cookie.length
         return unescape(document.cookie.substring(offset, end))
      }
    }
}
//========================= functions used by website builder =============================

//taken from Dreamweaver MM_findObj v4.01 - returns object with name objectName
function getObject(objectName, documentObj) 
{ 
  if (documentObj == null){documentObj = window.document};
  var d = documentObj;
  var n = objectName;
  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=getObject(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
//taken from Dreamweaver MM_swapImage()  //v3.0
function swapImage() 
{ 
  var i,j=0,x,a=swapImage.arguments;
   document.MM_sr=new Array; 
   for(i=0;i<(a.length-2);i+=3)
        if ((x=getObject(a[i]))!=null)
        {
            document.MM_sr[j++]=x; 
            if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];
        }
}

//taken from Dreamweaver MM_preloadImages() //v3.0
function preloadImages() 
{ 
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=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];}}
}

//opens a preview with a save/no/cancel option first  if page is edited
function Preview(nextUrl)
{
   if (GLOBAL_n6FormIsEdited)
    {
        var title = "Please Save Before Preview";
        var message = "You need to save first before you can preview your recent edits. Please save by clicking the Save button before previewing.";       
        ShowModalDialog(title, message, "     OK     ", "void(0)");     
    }
    else
    {
        OpenNewWindow(nextUrl,'_preview','toolbar, scrollbars=yes,resizable=yes,width=800,height=500, left=0, top=20')      
    }  
}

function OpenWindow(url, winName, options)
{


    //default to window called 'hl'
    if (winName == null)
    {
        winName="hl";
    }
    if (options != null)
    {
        var newWindow = window.open(url, winName, options);
    }
    else
    {
        var newWindow = window.open(url, winName);
    }
    
    newWindow.focus();
}


//confirms for save/no/cancel before exiting unsaved page
function ConfirmChange(nextUrl)
{
   if (GLOBAL_n6FormIsEdited)
    {
        var title = "Save Changes?";
        var message = "You are attempting to leave this page after making changes to it. Do you want to save your changes first?"; 
        var yesAction = 'SaveForm(\"' + nextUrl + '\")';
        var noAction  = 'window.document.location.href=\"' + nextUrl + '\"';
        ShowModalDialog(title, message, "Yes", yesAction, "No", noAction, "Cancel", "void(0)");     
    }
    else
    {
        document.location.href = nextUrl ;
    }  
}

//confirms for ok-save/cancel before executing nextJS. If page is not edited then just does nextJS
function ConfirmChangeJS(nextJS)
{
   if (GLOBAL_n6FormIsEdited)
    {
        alert('edited...');
        var title = "This will Save";
        var message = "Your page will be saved before this can be done. Is this ok?"; 
        var yesAction = 'SaveForm(); '+nextJS;
        var noAction  = 'void(0)';
        ShowModalDialog(title, message, "Ok", yesAction, "Cancel", noAction);     
    }
    else
    {
        eval(nextJS);
    }  
}

//saves the n6form data
function SaveForm(nextUrl)
{
	var form = getObject("n6form", window.document);

	if (N6Validate(form, validateElements))
	{    	
    	//ToggleSaveButtonWait();
    	if (""+nextUrl == "undefined"){nextUrl = ""};
    	form.UIaction.value = "save";
    	form.UInextUrl.value = nextUrl;	
    	form.submit();
    }    
}

//Add Kimiko - 06/05/04 - start
//----------------------------------------------------------
//saves the n6form data
function WPG_SaveFormOnPopup(nextUrl)
{
	var form = getObject("n6form", opener.document);
		//alert("WPG_SaveFormOnPopup");
    	//ToggleSaveButtonWait();
    	if (""+nextUrl == "undefined"){nextUrl = ""};
    	form.UIaction.value = "save";
    	form.UInextUrl.value = nextUrl;	
		window.close();
    	form.submit();
}

//added on 27/05/04 by Naleen, since "formatt()" function is called by WPB_SaveForm().
function WPG_formatt(textEntered)	{
	//alert("Before formatt:" + textEntered);
	rightpart = "";
	leftpart = "";
	//alert("here:" + window.document.n6form.WEB_TEMPLATE_ID.value);
	//escape characters
	for(i=0; i<textEntered.length; i++)	{
		if(textEntered.charAt(i)=="'")	{
			leftpart = textEntered.substr(0,i);
			//alert("leftpart:" + leftpart);
			rightpart = textEntered.substr(i+1,textEntered.length);
			//alert("rightpart:" + rightpart);
			textEntered = leftpart + "&#39;" + rightpart;
		}
	}
	//alert("After formatt:" + textEntered);
	//alert("here:" + window.document.n6form.WEB_TEMPLATE_ID.value);
	return textEntered;
}

function WPG_SaveForm(nextUrl)
{
	var form = getObject("n6form", window.document);
		form.Top_Banner_Title.value = WPG_formatt(form.Top_Banner_Title.value);
		form.WEB_PAGE_SUMMARY.value = WPG_formatt(form.WEB_PAGE_SUMMARY.value);
		form.WEB_ITEM1_CONTENT.value =WPG_formatt(form.WEB_ITEM1_CONTENT.value);
		form.WEB_ITEM1_TITLE.value =WPG_formatt(form.WEB_ITEM1_TITLE.value);
		form.WEB_ITEM2_CONTENT.value =WPG_formatt(form.WEB_ITEM2_CONTENT.value);
		form.WEB_ITEM2_TITLE.value =WPG_formatt(form.WEB_ITEM2_TITLE.value);
		form.WEB_ITEM3_CONTENT.value =WPG_formatt(form.WEB_ITEM3_CONTENT.value);
		form.WEB_ITEM3_TITLE.value =WPG_formatt(form.WEB_ITEM3_TITLE.value);
		
		form.CompanyNameInContact.value = WPG_formatt(form.CompanyNameInContact.value);
		form.Contact_personName.value = WPG_formatt(form.Contact_personName.value);
		form.emailAddress.value =WPG_formatt(form.emailAddress.value);
		form.homePhon01.value =WPG_formatt(form.homePhon01.value);	
		form.homePhon02.value =WPG_formatt(form.homePhon02.value);
		form.businessPhon01.value =WPG_formatt(form.businessPhon01.value);	
		form.businessPhon02.value =WPG_formatt(form.businessPhon02.value);
		form.homeFax.value =WPG_formatt(form.homeFax.value);	
		form.businessFax.value =WPG_formatt(form.businessFax.value);
		form.mobile01.value =WPG_formatt(form.mobile01.value);
		form.mobile02.value =WPG_formatt(form.mobile02.value);
		form.strAddr.value =WPG_formatt(form.strAddr.value);
		form.postalAddr.value =WPG_formatt(form.postalAddr.value); 
		form.country.value =WPG_formatt(form.country.value);
		//form.WEB_TEMPLATE_ID.value = WPG_selectedTemp;
    	//ToggleSaveButtonWait();
    	if (""+nextUrl == "undefined"){nextUrl = ""};
    	form.UIaction.value = "save";
    	form.UInextUrl.value = nextUrl;	
		/*alert(form.WEB_TEMPLATE_ID.length);*/
		/*for(i=0; i<form.WEB_TEMPLATE_ID.length; i++)
			if(form.WEB_TEMPLATE_ID[i].value == WPG_selectedTemp)
				form.WEB_TEMPLATE_ID[i].checked = true;*/
    	form.submit();
}
//----------------------------------------------------------
//Kimiko - 14/05/04 - end


//resets the n6form data
function ResetForm()
{
	SetFormNonEdited();
	var form = getObject("n6form", window.document);
	form.reset();
}
//catch form events
function CatchFormEvents(formName, eventHandler)
{
	var form = getObject(formName, window.document);
    for(var i=0; i<form.elements.length; i++)
    {
    	var formElement = form.elements[i];
    	//catch CHANGEs for txt boxes
    	if (formElement.type == 'text')
    	{
    		    formElement.onchange = eventHandler;
    		    formElement.onkeydown = eventHandler;	
    	}
    	//catch CHANGEs for selects
    	else if (formElement.type.indexOf('select') >= 0)
    	{
    		formElement.onchange = eventHandler;
    	}
    	//catch CLICKs for everything else
    	else	
    	{
    		formElement.onmouseup= eventHandler;
    	}
    } 
      
}

var GLOBAL_n6FormIsEdited = false;

function InitialiseSaveButton(buttonObj)
{
    buttonObj.onload = "";
}
function InitialiseEditor()
{
   if (getObject("saveButton"))
   {
        preloadImages('../images/navBars/navFooter-saveOn.gif', '../images/navBars/navFooter-saveWait.gif', '../images/navBars/navFooter-cancelOn.gif');
        SetFormNonEdited();
        window.status="No changes made yet."
    }
}

function SetFormEdited()
{
    window.status="Page Unsaved. Click Save to record changes";
   
    CatchFormEvents("n6form", null);
    GLOBAL_n6FormIsEdited = true;
    ToggleSaveButtonOn();
}

function SetFormNonEdited()
{
    window.status="Changes discarded.";
    CatchFormEvents("n6form", SetFormEdited);
    GLOBAL_n6FormIsEdited = false;
    ToggleSaveButtonOff();
}


function ToggleSaveButtonOn(eventObj)
{         
    var cancelBtn = getObject("cancelButton", window.document);
    var saveBtn   = getObject("saveButton", window.document);
    //saveBtn.onclick = SaveForm;
    //saveBtn.style.cursor = 'hand';    
    //cancelBtn.onclick = ResetForm;
    //cancelBtn.style.cursor = 'hand'; 
    swapImage('saveButton','','../images/navBars/navFooter-saveOn.gif',1);
    swapImage('cancelButton','','../images/navBars/navFooter-cancelOn.gif',1);
}

function ToggleSaveButtonOff(eventObj)
{
    var cancelBtn = getObject("cancelButton", window.document);
    var saveBtn   = getObject("saveButton", window.document);
    //saveBtn.onclick = '';
    //saveBtn.style.cursor = '';    
    //cancelBtn.onclick = '';
    //cancelBtn.style.cursor = '';  
    swapImage('saveButton','','../images/navBars/navFooter-saveOff.gif',1);
    swapImage('cancelButton','','../images/navBars/navFooter-cancelOff.gif',1);    
    return true;
}

function ToggleSaveButtonWait(eventObj)
{
   swapImage('saveButton','','../images/navBars/navFooter-saveWait.gif',1);
   swapImage('cancelButton','','../images/navBars/navFooter-cancelOff.gif',1);   
   return true;
}

function PositionLayerRelative(divName,x,y)
{
	var scrollXOffset; 
	var scrollYOffset;	
	
	ns4 = (document.layers)? true:false;
	ie4 = (document.all)? true:false;

	if (ns4) div = "document." + divName;
	if (ie4) div = 'document.all["' + divName  +'"].style';
	
	if (ie4 || ns4)
	{
		
		if (ns4)
		{
			scrollXOffset = window.pageXOffset;
			scrollYOffset = window.pageYOffset;
		}
		else
		{
			scrollXOffset = document.body.scrollLeft;	
			scrollYOffset = document.body.scrollTop;						
		}				
		
		x = x + scrollXOffset;
		y = y + scrollYOffset;		

		if (x > -1) {eval( div + ".left=" + x);}
		if (y > -1) {eval( div + ".top=" + y); }
	}
}

//based on Dreamweaver's MM_jumpMenu(targ,selObj,restore){ //v3.0
 function JumpMenu(selObj)
{ 
  var newLocation = selObj.options[selObj.selectedIndex].value;
  var selectedText = selObj.options[selObj.selectedIndex].text;
  selObj.outerHTML = "Please wait. Loading &#147;"+ selectedText +"&#148;...";
  eval("window.document.location='"+newLocation+"'");
}
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

/* --------------------------------------------------------------------------------------------
 ShowModalDialog(title, message, buttons): shows a modal message box.
 arguments:
      title   = title of window               eg. "Save Changes?"
      message = message to show in window     eg. "Do you want to save changes?"
      buttons = array of buttons              eg. "Yes", "SaveForm()", "No", "alert('nothing done')"
      
 example usage:
 
      ShowModalDialog(  "Save Changes?", 
                        "Do you want to save changes?", 
                        "Yes", "SaveForm()", "No", "alert(\"nothing done\")"
                     )
--------------------------------------------------------------------------------------------
*/
function ShowModalDialog()
{
 var pos;
 if(isMozilla())
 {
	pos = "fixed";	 
 }
 else
 {
	pos = "absolute";	 
 }
 
  var args = ShowModalDialog.arguments;
  var title     = args[0];
  var message   = args[1];
  
  var bgColor   = "#CCCCCC";
  var layerName = "ShowModalDialog";

  //make arrays of captions and corresponding codes
  var captions  = new Array;
  var evalCodes = new Array;    
  for(var i = 2; i < args.length; i+=2)
  {
    captions[captions.length]  = args[i];
    evalCodes[evalCodes.length]  = QuoteSingles(args[i+1]);
    //evalCodes[evalCodes.length]  = args[i+1];
  }
  //generate the html code for the buttons
  var buttonWidth = 100/captions.length;
  var buttonHtml = '<table width="100%" border="0" cellpadding="4" cellspacing="0"><tr>';
  var buttonStyle = "";
  if (captions.length > 2) {buttonStyle = "style='width:100%'"};
  for (i=0; i<captions.length; i++)
        buttonHtml += '<td width="'+ buttonWidth +'%" align=center>\n<input type="button" '+ buttonStyle +' value="'+captions[i]+'" onclick="DeleteModalDialog();eval(\''+evalCodes[i]+'\')">\n</td>';
  buttonHtml += "</tr></table>";
  
  //generate the html code for the window
	var html = "";
	html += '<table width="300" border="1" cellpadding="4" cellspacing="0"><tr><th>';
	html += title+'</th></tr><tr><td class="data">';
	html += message+'<br><br><div align="center">';
	html += buttonHtml+'</div></td></tr></table>';
	var IEhtml = "";
	IEhtml = '<table width="100%" height="100%"><tr><td align=center valign=middle>';
	IEhtml += html;
	IEhtml += "<br><br><br></td></tr></table>";
	IEhtml = "<div id='" + layerName +"' style='position:" + pos + "; z-index:99; margin-left:auto; margin-right: auto; float:none; width:100%; height:100%' >"+IEhtml+"</div>";
	document.body.insertAdjacentHTML("afterBegin", IEhtml);
	document.getElementById(layerName).style.backgroundImage = "url(../images/gridX200.gif)";
}

function QuoteSingles(str)
//replaces double quoptes with backslashed single quotes
{
    out = '"'; // replace this
    add = "\\'";  // with this
    temp = "" + str; 
    count = 0;
    while (temp.indexOf(out) > -1 && count < 10) 
    {
        pos= temp.indexOf(out);
        temp = "" + (temp.substring(0, pos) + add + 
        temp.substring((pos + out.length), temp.length));
        count ++;
    }
    return temp;
}

function DeleteModalDialog()
{
	if (isMozilla())
	{
		var element = document.getElementById('ShowModalDialog');
		element.parentNode.removeChild(element);
	}
    else if (ie())
    {
       document.all.ShowModalDialog.innerHTML = "";
       document.all.ShowModalDialog.outerHTML = "";
    }
    else
    {
        document.layers["ShowModalDialog"].visibility = "hide";        
    }
}
    

//========================= functions for Advanced use of n6Toggler (DHTML show/hider) =============================


//toggle N6Toggler controls with a specific name to on/off
function ToggleAll(turnAllOn, confirmFirst)
{
    var confirmed = true;
    if (confirmFirst)
    {
        confirmed = confirm("This action may take a while on slower computers.\n\Continue action?");
    }
    
    if (confirmed)
    {
        var i = 1;
        var obj;
        while(i < document.all.length )
        {
            obj = document.all[i];
            if (obj.n6toggler == "toggler")
            {
                ToggleMe(obj, turnAllOn);
                obj.status = turnAllOn;
            }
            i++;
        }
    }
    readyMessage();
}


//========================= functions for the time ticker =============================


// Netscapes Clock - Start
// this code was taken from Netscapes JavaScript documentation at
// www.netscape.com on Jan.25.96

var timerID = null;
var timerRunning = false;

var weekdays = ['Sun', 'Mon', 'Tues', 'Wed', 'Thur', 'Fri', 'Sat'];
var months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];

function stopclock (){
	if(timerRunning)
		clearTimeout(timerID);
	timerRunning = false;
}

function showtime () {
	var now = new Date();
	var hours = now.getHours();
	var minutes = now.getMinutes();
	var seconds = now.getSeconds();
	var day     = weekdays[now.getDay()];
	var month   = months[now.getMonth()];
	var year    = now.getYear();
	var date    = now.getDate();
	var timeValue = ((hours >12) ? hours -12 :hours)
	timeValue += ((minutes < 10) ? ":0" : ":") + minutes
	timeValue += ((seconds < 10) ? ":0" : ":") + seconds
	timeValue += (hours >= 12) ? " PM" : " AM"
	var dateValue = day + " " + date + ", " + month + " " + year
	document.clock.face.value = timeValue;
	document.clock.face1.value = dateValue;
	timerID = setTimeout("showtime()",1000);
	timerRunning = true;
}

function startclock () {
	// Make sure the clock is stopped
	stopclock();
	showtime();
}

function firstItem()
{
    for (var i = 0; i < document.forms.length; i++)
    {
        var currForm = document.forms[i];
        for(var j=0; j < currForm.elements.length; j++)
        {
            var currElement = currForm.elements[j];
            if(currElement.type == "text" ||
               currElement.type == "textarea")
            {
                    //currElement.select();
                    currElement.focus();
                    return;
            }
        }
    }
}


// Modify daniel - 24/02/04 - start
// give a password on unlock button
// ----------------------------------------------------------

// password verify
function editorPasswd()
{

    var password="pass"+window.prompt("please input the password:","");

    if(password=="pass4nowayback")
    {
//   window.alert("welcome, my friend!");
     return true;
    }
    else
    {
     window.alert("Password wrong, Sorry."); 
     return false;
    }
}
// ----------------------------------------------------------
// daniel - 24/02/04 - end


// Add Kimiko - 20/07/04 - start
// To check Flash is installed.
// ----------------------------------------------------------
function IsFalshInstalled() {
    result = false;
    if (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"])
    {
        result = navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin;
    }
    else if (document.all && (navigator.appVersion.indexOf("Mac")==-1))
    {
        // IE Windows only -- check for ActiveX control, have to hide code in eval from Netscape (doesn't like try)
        eval ('try {var xObj = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");if (xObj)            result = true; xObj = null;            } catch (e)         {}');
    }
    return result;
}
// ----------------------------------------------------------
// Kimiko - 20/07/04 - end


// Add Kimiko - 20/07/04 - start
// to show Flash
// ----------------------------------------------------------
function FlashWrite(url,width,height) {
    document.write('<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"');
    document.write('  codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" ');
    document.write('  WIDTH=' + width + ' HEIGHT=' + height + '>');
    document.write(' <PARAM NAME=movie VALUE="' + url + '"> <PARAM NAME=quality VALUE=high>  '); 
    document.write(' <EMBED src="' + url + '" quality=high  ');
    document.write(' swLiveConnect=FALSE WIDTH=' + width + ' HEIGHT=' + height);
    document.write(' TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">');
    document.write(' </EMBED></OBJECT>');
}
// ----------------------------------------------------------
// Kimiko - 20/07/04 - end

//------------------------------
//Check the given filename has a .swf extension.
//Returns true if given file is .swf type else returns false
//Added to rotate adverts in country1, country2, country3, country4 and home pages.
//Naleen Seenevirathne - 8/9/04
//-----------------------------
function isFlashFile(strValue)	{
	var objRegExp  = /^\S+\.(swf)$/;
	return objRegExp.test(strValue);
}

//------------------------------
//Returns width of the given advert-Filename.
//width should be included in filename. This method just find the width from its filename [no other technique].
//Added to rotate adverts in country1, country2, country3, country4 and home pages.
//Naleen Seenevirathne - 8/9/04
//-----------------------------
function getWidthOfImage(fileName)	{
	//match any three digit number ex: /images/ads/RHAndrewsAdd_250x750.swf
	findWidthAndHeight = /\d{3}/g;
	WidthAndHeight = fileName.match(findWidthAndHeight);
	width = WidthAndHeight[0];	//250
	return width;
}

//------------------------------
//Returns height of the given advert-Filename.
//Height should be included in filename. This method just find the height from its filename [no other technique].
//Added to rotate adverts in country1, country2, country3, country4 and home pages.
//Naleen Seenevirathne - 8/9/04
//-----------------------------
function getHeightOfImage(fileName)	{
	//match any three digit number ex: /images/ads/RHAndrewsAdd_250x750.swf
	findWidthAndHeight = /\d{3}/g;
	WidthAndHeight = fileName.match(findWidthAndHeight);
	height = WidthAndHeight[1];	//750
	return height;
}

//------------------------------
//This method dispaly a falsh advert in the page.
//Get the width and heigt of advert-Filename using above methods.
//Find the alternative filename of given flash advert.
//Then use IsFalshInstalled() and FlashWrite() methods.
//Always add noscript tag at the end.
//Added to rotate adverts in country1, country2, country3, country4 and home pages.
//Naleen Seenevirathne - 8/9/04
//-----------------------------
var d = new Date();
var index_of_day = d.getDay(); 
	
function writeFlashFile(fileName, index, imageOrderArray, linkArray, altArray)	{
	widthOfImage = getWidthOfImage(fileName);
	heightOfImage = getHeightOfImage(fileName);
	//split the filename to form the alternative image.
	splitFileName =  fileName.split(".");
	fileNameBeforeExtension = splitFileName[0];
	fileNameExtension = splitFileName[1];
	alternativeAdd = fileNameBeforeExtension + "_alt.gif";
			
	//If we have correct format of vlaues 
	if(widthOfImage != null && heightOfImage != null && alternativeAdd != null)	{
		//If flash is availble at clients end
		if (IsFalshInstalled())	
			FlashWrite(fileName,widthOfImage,heightOfImage);
		//If no flash show up alternative image
		else	
			document.write("<a href='" + eval("linkArray[" + imageOrderArray + (index_of_day+1) + "[" + index + "]]") + "' target='_blank'><img src='" + alternativeAdd + "' width='" + widthOfImage + "' height='" + heightOfImage + "' vspace='2' border='0' alt='" + eval("altArray[" + imageOrderArray + (index_of_day+1) + "[" + index + "]]") + "'></a><br />");
		//write No script Tag
		document.write("<noscript><a href='" + eval("linkArray[" + imageOrderArray + (index_of_day+1) + "[" + index + "]]") + "' target='_blank'><img src='" + alternativeAdd + "' width='" + widthOfImage + "' height='" + heightOfImage + "' vspace='2' border='0' alt='" + eval("altArray[" + imageOrderArray + (index_of_day+1) + "[" + index + "]]") + "'></a><br /></noscript>");
	}
}
