

// isASVInstalled
//
// utililty function to check for Adobe SVG viewer
//
function isASVInstalled() {
	try {
	 var asv = new ActiveXObject("Adobe.SVGCtl");
	 return true;
	}
	catch(e){ }
	return false;
}

function embedSVG( parentId, url, width, height) {
	var parent = document.getElementById(parentId);
	
	var obHTML='';
	
	if (isASVInstalled()) {
		obHTML = '<embed src="'+url+'" width=\"'+width+'", height="'+height+'" type=\"image/svg+xml\">';
	} else {
		obHTML = '<object data="'+url+'" width=\"'+width+'", height="'+height+'" type=\"image/svg+xml\">';
	}
			
	parent.innerHTML = obHTML;

}

	function serialize() {
	
		var str = "SYMBOL*"+ ((this.symbol==null) ? "" : this.symbol) ;
		str+="|YEAR*"+ ((this.year==null) ? "" : this.year);
		str+="|COMPARE*"+((this.compare==null) ? "" : this.compare);
		str+="|COMPAREVALUE*"+((this.compareValue==null) ? "" : this.compareValue);		
		str+="|VISIBLE_LAYERS*"+((this.visibleLayers==null) ? "" : this.visibleLayers.join("&"));		
		str+="|HIDDEN_LAYERS*"+((this.hiddenLayers==null) ? "" : this.hiddenLayers.join("&"));		
		str+="|CURRENT_TAB*"+((this.currentTab==null) ? "" : this.currentTab);
//		alert(str);
		createCookieOA(str);		
	}

//	function serialize2(state) {	
//		var str = "SYMBOL*"+ ((state.symbol==null) ? "" : state.symbol) ;
//		str+="|YEAR*"+ ((state.year==null) ? "" : state.year);
//		str+="|COMPARE*"+((state.compare==null) ? "" : state.compare);
//		str+="|COMPAREVALUE*"+((state.compareValue==null) ? "" : state.compareValue);		
//		alert(str);
//		createCookieOA(str);		
//	}
	
		
	
	function deserialize() {
		
		var str =  readCookieOA();	
		var elems = str.split("|");
		for (i =0 ; i < elems.length;i++) {
			var nameValue = elems[i].split("*");
			var name= nameValue[0];			
			var value = null;
			if (nameValue.length > 1) value = nameValue[1];
			if  ("SYMBOL"==name) this.symbol=value;
			if  ("YEAR"==name) this.year=value;
			if  ("COMPARE"==name) this.compare=value;
			if  ("COMPAREVALUE"==name) this.compareValue=value;				
			
			if  ("VISIBLE_LAYERS"==name) {
				 if ( value != null && value.length>0 ) 
					this.visibleLayers = value.split("&");
				else 	
					this.visibleLayers = new Array();
			}		
				
			if  ("HIDDEN_LAYERS"==name) {
				if ( value != null && value.length>0)  								
					this.hiddenLayers = value.split("&");	
				else 
					this.hiddenLayers=new Array();
			}	
			if  ("CURRENT_TAB"==name) this.currentTab=value;					
						
		}
	}
	
	function State() {
		this.symbol=null;
		this.compare=null;
		this.compareValue=null;
		this.year=null;
		this.visibleLayers=null;
		this.hiddenLayers=null;
		this.currentTab=null;
		this.serialize=serialize;
		this.deserialize=deserialize;
	}


	function createCookie(name, value, days) {
		var expires = "";
		if (days) {
			var date = new Date();
			date.setTime(date.getTime()+(days*24*60*60*1000));
			var expires = "; expires="+date.toGMTString();
		}
		
		document.cookie = name+"="+value+expires+"; path=/";
		//alert(document.cookie);		
	}

	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);
	}

	function eraseCookieOA() {
		createCookie('OnlineAtlas', "", -1);
	}
	
	function readCookieOA() {
		return readCookie('OnlineAtlas');
	}

	function createCookieOA(value) {
		createCookie('OnlineAtlas',value);
	}
	
	
