//------------------- session cookie --------------------------------------//
function createCookie(name, value, days){
	document.cookie = name+"="+value+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

var flashSkipInit = false;
var cookie = readCookie("firstTime");
if(cookie){
	flashSkipInit = false;
	//alert("skip Flash Intro");
}else{
	flashSkipInit = true;
	//alert("show Flash Intro");
	createCookie("firstTime", "true", "");
}

//should be called from the flash
function flashInit(){
	var flashMenuObj = document.getElementById("flash");
	//setFlashInit fun is inside the flash, it gets the value of flashSkipInit
	return(flashSkipInit);   
}

//------------------- passing the node to the flash ---------------------------//

//this function is called from flash and sends information to Flash, 
//for example: the flash can do  fSendContent("flashContent") to get the node flashContent
function fSendContent(contentID){
	//alert("fsendcontent: " + contentID);
	var flashObj = document.getElementById("flash");

	if (flashObj) {
		var contentObj = document.getElementById(contentID);
		
		if (contentObj) {
			//alert(myInnerHTML(contentObj));
			flashObj.processContent(myInnerHTML(contentObj));
		} else {
			alert("div not found");
		}	
	} else {
		alert("could not get reference to flash object");
	}
}

function getFlashContent(contentID){
	//alert("getFlashContent: " + contentID);
	var contentObj = document.getElementById(contentID);
    if (contentObj) {
		return (myInnerHTML(contentObj));
	} else {
		alert("div not found");
	}	
}


function myInnerHTML(node) {
		
	// internet explorer's innerHTML is craptastic so we use some hackery to fix it
	//if(navigator.appVersion.indexOf("MSIE") != -1 && navigator.appVersion.indexOf("Windows") > -1){
		// BUG: self-closing <a> tags don't work , e.g "<a name='inline' />"
		
		var reTag = /(<\/?\w+)([^>]*>)/g;
		var reAttr = /(\w+=)((['"])[\s\S]*\3|[^\s>]+)/g;
		var str = node.innerHTML;
			
		function fixAttr($0, $1, $2, $3) {
			if ($3) return $1.toLowerCase() + $2;
			else return $1.toLowerCase() + '"' + $2 + '"'
		} 		

		function fixTag($0, $1, $2) {
			return $1.toLowerCase() + $2.replace(reAttr, fixAttr);
		}

		// clean up tags (make html tags and attributes lowercase)
		str = str.replace(reTag, fixTag);

		// make sure self-closing tags are closed 
		var reSelfClosing = new RegExp("\<(area|base|basefont|br|hr|img|input)(.*?)>", "g");
		
		str = str.replace(reSelfClosing, "<$1$2/>");
		
		// IE's treatment of UL's and DL's is mind boggling.
		// Dan's big brain came up with this series of search/replaces that fixes them.  you go dan.  
		str = str.replace(/<\/li>|<\/dt>/g, "");							// get rid of all closing li and dt tags (for IE)
		str = str.replace(/\s*<li([^>]*)>/g, "<\/li><li$1>");		// put a closing li in front of all opening li
		str = str.replace(/<\/ul>/g, "<\/li><\/ul>");					// put a closing li in front of closing ul
		str = str.replace(/<ul([^>]*)>\s*<\/li>/g, "<ul$1>");		// remove closing li's that appear directly after opening ul
		str = str.replace(/\s*<dd([^>]*)>/g, "<\/dt><dd$1>");	// put a closing dt in front of all opening dd's
		//end dan hackery		
		return str;
	//} else {
	//	return node.innerHTML;
	//}
}