	var strsymkey;


    function clearKey(){

        strsymkey = '';

        if(navigator.userAgent.indexOf("MSIE") != -1) {
			var oKeyDiv = document.getElementById("keyDiv");
			oKeyDiv.load("oXMLBranch");
            oKeyDiv.removeAttribute("symkey");
			oKeyDiv.save("oXMLBranch");
		}
		else if(navigator.userAgent.indexOf("Firefox") != -1) {
			sessionStorage.setItem("symkey", "");
		}
		else if(navigator.userAgent.indexOf("Safari") != -1 && navigator.userAgent.indexOf("Chrome") == -1) {
			var db;
			if(window.openDatabase){
				db = openDatabase("KeyS", "1.0", "KeyStorage", 2000);

				db.transaction(function (tx) {
					tx.executeSql("CREATE TABLE KeyStore(id INTEGER UNIQUE, key TEXT )", [], function(result) {});
				});

				db.transaction(function (tx) {
					tx.executeSql("INSERT INTO KeyStore (id, key ) VALUES (?, ? )", [0, ""]);
				});
			}

		}
    }

	function getKey() {
		//alert(navigator.userAgent);
		//±âÅ¸ ºê¶ó¿ìÀú »ç¿ë½Ã¿¡´Â, ´Ü¹æÇâ ¾ÏÈ£¸¸À» Ã³¸®ÇÑ´Ù.
		//¾ç¹æÇâ ¾ÏÈ£°¡ Ã³¸®µÇ´Â ºê¶ó¿ìÀú´Â IE, FF·Î Ã³¸®ÇÏ¸ç, »çÆÄ¸®´Â »óÈ²¿¡ µû¶ó, Å©·Ò°ú ¿ÀÆä¶ó´Â ´Ü¹æÇâ
		if(navigator.userAgent.indexOf("MSIE") != -1) {

			var oKeyDiv = document.getElementById("keyDiv");

			oKeyDiv.load("oXMLBranch");

			strsymkey = oKeyDiv.getAttribute("symkey");


		}
		else if(navigator.userAgent.indexOf("Firefox") != -1) {
			// fireFox
			strsymkey = sessionStorage.getItem("symkey");
		}
		else if(navigator.userAgent.indexOf("Safari") != -1 && navigator.userAgent.indexOf("Chrome") == -1) {
			var db;
			if(window.openDatabase){
				db = openDatabase("KeyS", "1.0", "KeyStorage", 2000);
				db.transaction(function (tx) {
					tx.executeSql("SELECT key  FROM KeyStore", [],function(tx, result) {
					var row = result.rows.item(0);
					if(row != null) {
						strsymkey = ""+row["key"];
					}
				}) });

			}
		}

		if(strsymkey == null || strsymkey == "" || strsymkey == "null" ) {
			makeKey();
			if(navigator.userAgent.indexOf("MSIE") != -1) {
				var oKeyDiv = document.getElementById("keyDiv");
				oKeyDiv.load("oXMLBranch");

				strsymkey = oKeyDiv.getAttribute("symkey");

			}
			else if(navigator.userAgent.indexOf("Firefox") != -1) {
				// fireFox
				strsymkey = sessionStorage.getItem("symkey");

			}
			else if(navigator.userAgent.indexOf("Safari") != -1 && navigator.userAgent.indexOf("Chrome") == -1) {
				var db;
				if(window.openDatabase){
					db = openDatabase("KeyS", "1.0", "KeyStorage", 2000);
					db.transaction(function (tx) {
						tx.executeSql("SELECT key  FROM KeyStore", [],function(tx, result) {
						var row = result.rows.item(0);
						if(row != null) {
							strsymkey = ""+row["key"];
						}
					}) });
				}
			}



		}
	}

	function makeKey() {
        

		var symkey = "";
		for(var i=0;i<16;i++) {
		 	symkey += String.fromCharCode(Math.round(Math.random()*25)+97); // ascii 33 ~ 126
		}
		strsymkey = symkey;
 

		if(navigator.userAgent.indexOf("MSIE") != -1) {
			var oKeyDiv = document.getElementById("keyDiv");
			 
			
			oKeyDiv.load("oXMLBranch");

			if (oKeyDiv.getAttribute("symkey")==null ||
			        oKeyDiv.getAttribute("symkey")==""  || oKeyDiv.getAttribute("symkey")=='null') {
				oKeyDiv.setAttribute("symkey",strsymkey);
 
				oKeyDiv.save("oXMLBranch");
			}
		}
		else if(navigator.userAgent.indexOf("Firefox") != -1) {
			sessionStorage.setItem("symkey", strsymkey);
		}
		else if(navigator.userAgent.indexOf("Safari") != -1 && navigator.userAgent.indexOf("Chrome") == -1) {
			var db;
			if(window.openDatabase){
				db = openDatabase("KeyS", "1.0", "KeyStorage", 2000);

				db.transaction(function (tx) {
					tx.executeSql("CREATE TABLE KeyStore(id INTEGER UNIQUE, key TEXT )", [], function(result) {});
				});

				db.transaction(function (tx) {
					tx.executeSql("INSERT INTO KeyStore (id, key ) VALUES (?, ? )", [0, strsymkey]);
				});
			}

		}
	}

	function browserStore() {
		if(navigator.userAgent.indexOf("MSIE") != -1) {
			return 1;
		}
		else if(navigator.userAgent.indexOf("Firefox") != -1) {
			return 1;
		}
		else if(navigator.userAgent.indexOf("Safari") != -1 && navigator.userAgent.indexOf("Chrome") == -1) {
			return 1;
		}
		else {
			return 0
		}
	}
