var ua = navigator.userAgent;

var isDOM=document.getElementById?1:0; // DOM1 browser
var isOpera=/Opera/.test(ua);
var isMSIE=/MSIE/.test(ua);
var isGecko=/Gecko/.test(ua);
var isSafari=/Safari/.test(ua);

if(isMSIE)
{
isMSIE=controllerGetMSIEVersion(ua);
}

var controllerI=0;
var controllerInterval1=null;
var controllerInterval2=null;
var controllerTimeOut=null;
var controllerWidget;

var widget=null;

var objectDragApproved=0;
var objectStartX;
var objectStartY;


function $(id)
{
return document.getElementById(id); 
}


function controllerFixIE()
{
	if(isMSIE && isMSIE<7)
	{
	controllerFixPNG(document.body);
	}
}


function controllerCheckDigitsType(event)
{
return controllerCheckValueType(event, /[0-9]+/);
}


function controllerCheckValueType(event, re)
{
var charCode;
	if(isMSIE)
	{
	charCode=window.event.keyCode;
	}
	else
	{
	charCode=event.which;
	}
if(charCode==0 || charCode==8 || charCode==9 || charCode==13) return true;
var str=String.fromCharCode(charCode);
if(str.search(re)==-1) return false;
return true;
}


function controllerCheckEnterType(event)
{
var charCode;
	if(isMSIE)
	{
	charCode=window.event.keyCode;
	}
	else
	{
	charCode=event.which;
	}
	if(charCode==13)
	{
	var widget;
		if(isMSIE)
		{
		widget=window.event.srcElement;
		}
		else
		{
		widget=event.target;
		}
	var frm=widget.form;
	frm.submit();
	}
}


function controllerCheckSelected(widget)
{
	if(widget.selectedIndex==-1 || widget.options[widget.selectedIndex].text=="" || widget.options[widget.selectedIndex].value==0)
	{
	return false;
	}
return true;
}


function controllerCheckValue(widget, re)
{
var val=widget.value;
var re = new RegExp(re, "i");
	if(val.search(re)==-1)
	{
	return false;
	}
return true;
}


function controllerCheckIdentity(widget1, widget2)
{
var str1=widget1.value;
var str2=widget2.value;
	if(str1!=str2)
	{
	controllerSetAlert(widget2, alertCheckWidget);
	return false;
	}
return true;
}


function controllerInitForm(obj)
{
controllerLimitTextAreaForm(obj);
controllerAutofocusForm(obj);
}


function controllerLimitTextAreaForm(obj)
{
	if(obj.childNodes.length)
	{
		for(var child = obj.firstChild; child; child = child.nextSibling)
		{
			if(child.type && child.type=="textarea")
			{
				if(child.getAttribute("maxlength"))
				{
				child.onkeypress=controllerLimitTextArea;
				}
			}
		controllerAutofocusForm(child);
		}
	}
}


function controllerLimitTextArea(e)
{
e = e || window.event;
var widget = e.target || e.srcElement;
var code=e.keyCode?e.keyCode:(e.which?e.which:e.charCode)
	switch (code)
	{
	case 13:
	case 8:
	case 9:
	case 46:
	case 37:
	case 38:
	case 39:
	case 40:
	return true;
	}
return widget.value.length <= widget.getAttribute("maxlength");
}


function controllerAutofocusForm(obj)
{
	if(obj.childNodes.length)
	{
		for(var child = obj.firstChild; child; child = child.nextSibling)
		{
			if(child.type)
			{
				switch(child.type)
				{
				case "text":
				case "textarea":
				case "password":
				case "select-one":
					if(child.getAttribute("autofocus")=="autofocus")
					{
					controllerSetFocus(child);
					}
				break;
				}
			}
		controllerAutofocusForm(child);
		}
	}
}


function controllerEnableWidget(widget)
{
	switch(widget.type)
	{
	case "checkbox":
	case "password":
	case "select-multiple":
	case "select-one":
	case "text":
	case "textarea":
	widget.disabled=false;
	break;

	default:
	break;
	}
}


function controllerDisableWidget(widget)
{
	switch(widget.type)
	{
	case "checkbox":
	widget.checked=false;
	widget.disabled=true;
	break;

	case "password":
	case "text":
	case "textarea":
	widget.value="";
	widget.disabled=true;
	break;

	case "select-multiple":
	controllerDeselectOptions(widget);
	widget.disabled=true;
	break;

	case "select-one":
	widget.selectedIndex=0;
	widget.disabled=true;
	break;

	default:
	break;
	}
}


function controllerCheckForm(obj)
{
	if(obj.childNodes.length)
	{
		for(var child = obj.firstChild; child; child = child.nextSibling)
		{
			if(child.disabled==false)
			{
				if(child.type)
				{
					switch(child.type)
					{
					case "text":
					case "textarea":
					case "hidden":
					case "password":
						if(child.getAttribute("required")=="required")
						{
							if(child.value=="")
							{
							controllerSetAlert(child, alertCheckWidget);
							return false;
							}
						}
						if(child.getAttribute("pattern")) 
						{
							if(!controllerCheckValue(child, child.getAttribute("pattern")))
							{
							controllerSetAlert(child, alertCheckWidget);
							return false; 
							}
						}
					break;

					case "select-one":
					case "select-multiple":
						if(child.getAttribute("required")=="required")
						{
							if(!controllerCheckSelected(child))
							{
							controllerSetAlert(child, alertCheckWidget);
							return false;
							}
						}
					break;

					default:
					break;
					}
				}
			}
			if(!controllerCheckForm(child))
			{
			return false;
			}
		}
	}
return true;
}


// not necessary whole form, could be one fieldset (section)
function controllerDisableForm(obj)
{
	if(obj.childNodes.length)
	{
		for(var child = obj.firstChild; child; child = child.nextSibling)
		{
		controllerDisableWidget(child);
		controllerDisableForm(child);
		}
	}
}


// not necessary whole form, could be one fieldset (section)
function controllerEnableForm(obj)
{
	if(obj.childNodes.length)
	{
		for(var child = obj.firstChild; child; child = child.nextSibling)
		{
		controllerEnableWidget(child);
		controllerEnableForm(child);
		}
	}
}


function controllerEmptyForm(obj)
{
	if(obj.childNodes.length)
	{
		for(var child = obj.firstChild; child; child = child.nextSibling)
		{
			if(child.type)
			{
				switch(child.type)
				{
				case "text":
				case "textarea":
				case "hidden":
				case "password":
				child.value="";
				break;

				case "select-one":
				child.selectedIndex=0;
				break;

				case "select-multiple":
					if(child)
					{
					controllerDeselectOptions(child);
					}
				break;

				case "checkbox":
				child.checked=false;
				break;

				default:
				break;
				}
			}
		controllerEmptyForm(child);
		}
	}
}


function controllerFixPNG(obj)
{
var src;
var elem;
var fstr;
var backgroundImage;
var backgroundPositionX;
var backgroundRepeat;
var sizingMethod;

	if(obj && obj.childNodes.length)
	{
		for(elem = obj.firstChild; elem; elem = elem.nextSibling)
		{
		src=null;
			if(elem.tagName && elem.tagName.toLowerCase()=="img")
			{
				if (/\.png$/.test(elem.src))
				{
				src = elem.src;
				elem.style.width=elem.offsetWidth+'px';
				elem.style.height=elem.offsetHeight+'px';
				elem.src = "/images/ig_blank.gif";
				fstr="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "',sizingMethod='scale')";
				elem.runtimeStyle.filter = fstr;
				}
			}
			else
			{
			backgroundImage=controllerGetElementComputedStyle(elem, "background-image");
				if(backgroundImage>"")
				{
				src=backgroundImage.match(/url\("(.+\.png)"\)/i);
					if (src)
					{
					backgroundPositionX=controllerGetElementComputedStyle(elem, "background-position-x");
					backgroundRepeat=controllerGetElementComputedStyle(elem, "background-repeat");

						if((backgroundPositionX=="left" ||  backgroundPositionX=="0%") && (backgroundRepeat=="repeat" || backgroundRepeat=="no-repeat"))
						{
						src = src[1];
						elem.runtimeStyle.backgroundImage="none";
						}
						else
						{
						src=null;
						}
						if (src)
						{
							if(backgroundRepeat=="no-repeat")
							{
							sizingMethod='crop';
							}
							else
							{
							sizingMethod='scale';
							}
						fstr="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "',sizingMethod='"+sizingMethod+"')";
						elem.runtimeStyle.filter = fstr;
						}
					}
				}
			}
		controllerFixPNG(elem);
		}
	}
}


function controllerGetElementComputedStyle(elem, prop)
{
if (typeof elem!="object") elem = $(elem);

	// external stylesheet for Mozilla, Opera 7+ and Safari 1.3+
	if (document.defaultView && document.defaultView.getComputedStyle)
	{
	if (prop.match(/[A-Z]/)) prop = prop.replace(/([A-Z])/g, "-$1").toLowerCase();
	return document.defaultView.getComputedStyle(elem, "").getPropertyValue(prop);
	}
  
	// external stylesheet for Explorer and Opera 9
	if (elem.currentStyle)
	{
	var i;
	while ((i=prop.indexOf("-"))!=-1) prop = prop.substr(0, i) + prop.substr(i+1,1).toUpperCase() + prop.substr(i+2);
	return elem.currentStyle[prop];
	}
return "";
}


function controllerGetWidgetType(widget)
{
var type="";
type=widget.type;
return type;
}


function controllerAddOption(widget, optionValue, optionText)
{
var newElem=document.createElement("OPTION");
newElem.value=optionValue;
newElem.text=optionText;
widget.options.add(newElem, widget.options.length);
}


function controllerAddOptions(widget, optionsStr)
{
	if(isMSIE)
	{
	var selectStartStr=widget.outerHTML.replace('</SELECT>', '');
	var selectStr=selectStartStr+optionsStr+'</SELECT>';
	widget.outerHTML=selectStr;
	}
	else
	{
	widget.innerHTML=optionsStr;
	}
}


function controllerRemoveOption(widget, optionValue)
{
	for(var i=0; i<widget.options.length; i++)
	{
		if(widget.options[i].value==optionValue)
		{
		widget.remove(i);
			if(i<widget.options.length)
			{
			widget.selectedIndex=i;
			}
		break;
		}
	}
}


function controllerRemoveOptions(widget)
{
widget.innerHTML="";
}


function controllerSelectOption(widget, optionValue)
{
var i;
	for(i=0; i<widget.options.length; i++)
	{
		if(widget.options[i].value==optionValue)
		{
		widget.options[i].selected=true;
		break;
		}
	}
}


function controllerSelectOptions(widget)
{
var i;
	for(i=0; i<widget.options.length; i++)
	{
	widget.options[i].selected=true;
	}
}


function controllerDeselectOptions(widget)
{
var i;
	for(i=0; i<widget.options.length; i++)
	{
	widget.options[i].selected=false;
	}
}


function controllerSetAlert(widget, alertMessage)
{
alert(alertMessage);
controllerAlertWidget(widget);
}


function controllerShowHideSelects(vis)
{
var type;
var widget;
vis=(vis)?"visible":"hidden";
	if(isMSIE && isMSIE<7)
	{
		for(i=0; i<document.forms.length; i++)
		{
			for(j=0; j<document.forms[i].elements.length; j++)
			{
				if(document.forms[i].elements[j].type=="select-one" || document.forms[i].elements[j].type=="select-multiple")
				{
				document.forms[i].elements[j].style.visibility=vis;
				}
			}
		}
	}
}


function controllerSetEmail(box, srv, subject, cls, text)
{
var email=box +  '@' + srv;
var str='<a href="mailto:' + email;
if(subject) str+='?subject=' + subject;
str+='"';
	if(cls)
	{
	str+=' class="' + cls + '"';
	}
str+='>';
	if(text>"")
	{
	str+=text;
	}
	else
	{
	str+=email;
	}
str+='</a>';
document.write(str);
}


function controllerSetFocus(widget)
{
var type;
var range;
type=controllerGetWidgetType(widget);
	switch(type)
	{
	case "text":
		if(isMSIE || isOpera)
		{
		range=widget.createTextRange();
		range.moveEnd("textedit");
		range.collapse(false);
		range.select();
		}
	break;
	}
widget.focus();
}


function controllerHideWidget()
{
controllerWidget.style.visibility='hidden';
}


function controllerShowWidget()
{
controllerWidget.style.visibility='visible';
	if(controllerI>1)
	{
	if(controllerInterval1) clearInterval(controllerInterval1);
	if(controllerInterval2) clearInterval(controllerInterval2);
	controllerI=0;
	controllerSetFocus(controllerWidget);
	}
	else
	{
	controllerI++;
	}
}


function controllerPhase()
{
	if(controllerTimeOut)
	{
	clearTimeout(controllerTimeOut);
	}
controllerHideWidget();
controllerInterval2=setInterval(controllerHideWidget, 500);
}


function controllerAlertWidget(widget)
{
controllerWidget=widget;
controllerSetFocus(widget);
controllerInterval1=setInterval(controllerShowWidget, 500);
controllerTimeOut=setTimeout(controllerPhase, 250);
}


function controllerWindow(winID, winName, winURL, winWidth, winHeight, winParams)
{
var winLeft=(screen.width-winWidth)*.5;
var winTop=(screen.height-winHeight)*.5;
var winStr='width=' + winWidth + ', height=' + winHeight + ', left=' + winLeft + ', top=' + winTop;
	if(winParams>"")
	{
	winStr+=", "+winParams;
	}
	if(!winID || winID.closed)
	{
	winID=window.open(winURL, winName, winStr);
	}
	else
	{
	winID.location.href=winURL;
	winID.focus();
	}
return winID;
}


function controllerObjectStartDrag(e)
{
e = e || window.event;
var elem = e.target || e.srcElement;
	if(elem.id>"")
	{
	elem.style.cursor="move";
	objectDragApproved=1;

	objectStartX=e.clientX;
	objectStartY=e.clientY;

	document.body.onmousedown=new Function("return false;");
	document.body.onmousemove=new Function("return false;");
	}
}


function controllerObjectDrag(e)
{
e = e || window.event;
var elem = e.target || e.srcElement;
var parent=elem.parentNode;
var minX=1;
var minY=1;
var maxX=controllerGetClientWidth()+controllerGetClientScrollLeft();
var maxY=controllerGetClientHeight()+controllerGetClientScrollTop();
var objectID;
	if(objectDragApproved)
	{
		switch(elem.tagName.toLowerCase())
		{
		case "div":
		objectID=parent.id;
		break;
		case "span":
		objectID=parent.parentNode.id;
		break;
		}
	var newLeft=$(objectID).offsetLeft+(e.clientX-objectStartX);
	objectStartX=e.clientX;
		if(newLeft<=minX)
		{
		newLeft=minX;
		}
		else
		{
		var newRight=newLeft+$(objectID).offsetWidth;
			if(newRight>=maxX)
			{
			newLeft=maxX-$(objectID).offsetWidth;
			}
			if(newLeft<=minX)
			{
			newLeft=minX;
			}
		}
	var newTop=$(objectID).offsetTop+(e.clientY-objectStartY);
	objectStartY=e.clientY;
		if(newTop<=minY)
		{
		newTop=minY;
		}
		else
		{
		var newBottom=newTop+$(objectID).offsetHeight;
			if(newBottom>=maxY)
			{
			newTop=maxY-$(objectID).offsetHeight;
			}
			if(newTop<=minY)
			{
			newTop=minY;
			}
		}
	$(objectID).style.left=newLeft+"px";
	$(objectID).style.top=newTop+"px";
	return false;
	}
return true;
}


function controllerObjectStopDrag(e)
{
e = e || window.event;
var elem = e.target || e.srcElement;
objectDragApproved=0;
elem.style.cursor="default";
document.body.onmousedown=null;
document.body.onmousemove=null;
}


function controllerCheckFlash()
{
var i;
var shock = false;
var flash = false;
	if(navigator.plugins.length)
	{
		for (i=0; i < navigator.plugins.length; i++)
		{
		if (navigator.plugins[i].name.indexOf("Shockwave Flash") != -1)
		shock = true;
		}
	}
	else
	{
		for(i=8;i>0;i--)
		{
		eval('try{flash=new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+i);}catch(e){}');
			if(flash)
			{
			shock = true;
			break;
			}
		}
	}
return shock;
}


function controllerSetFlash(swfFile, width, height, altHTML)
{
var str="";
	if(controllerCheckFlash())
	{
	str='<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"';
	str+=' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0"';
	str+=' width="'+width+'" height="'+height+'">';
	str+=' <param name="allowScriptAccess" value="sameDomain" />';
	str+=' <param name="movie" value="'+swfFile+'" />';
	str+=' <param name="menu" value="false" />';
	str+=' <param name="quality" value="high" />';
	str+=' <param name="wmode" value="transparent" />';
	str+=' <param name="bgcolor" value="#ffffff" />';
	str+=' <embed src="'+swfFile+'"';
	str+=' allowScriptAccess="sameDomain"';
	str+=' type="application/x-shockwave-flash"';
	str+=' width="'+width+'" height="'+height+'"';
	str+=' quality="high"';
	str+=' wmode="transparent"';
	str+=' bgcolor="#000000"';
	str+=' pluginspage="http://www.macromedia.com/go/getflashplayer" />';
	str+=' </object>';
	}
	else
	{
	str+=altHTML;
	}
document.write(str);
}


function controllerGetClientWidth()
{
return (document.compatMode=='CSS1Compat')?document.documentElement.clientWidth:document.body.clientWidth;
}


function controllerGetClientHeight()
{
return (document.compatMode=='CSS1Compat')?document.documentElement.clientHeight:document.body.clientHeight;
}


function controllerGetClientScrollLeft()
{
return self.pageXOffset || (document.documentElement && document.documentElement.scrollLeft) || (document.body && document.body.scrollLeft);
}


function controllerGetClientScrollTop()
{
return self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop);
}


function controllerCenterPanel(obj)
{
var paddingMin=10;

var windowWidth=controllerGetClientWidth();
var windowHeight=controllerGetClientHeight();

var windowScrollLeft=controllerGetClientScrollLeft();
var windowScrollTop=controllerGetClientScrollTop();

var panelWidth=obj.offsetWidth;
var panelHeight=obj.offsetHeight;

var panelLeft=windowScrollLeft+(windowWidth-panelWidth)*.5;
var panelTop=windowScrollTop+(windowHeight-panelHeight)*.5;

	if(panelLeft<0)
	{
	panelLeft=paddingMin;
	var bodyWidth=panelLeft+paddingMin*2;
	var contentsAddWidth=bodyWidth-document.body.offsetWidth;
	$("contents").style.width=$("contents").offsetWidth+contentsAddWidth+'px';
	}

	if(panelTop<0)
	{
	panelTop=paddingMin;
	var bodyHeight=panelHeight+paddingMin*2;
	var contentsAddHeight=bodyHeight-document.body.offsetHeight;
	$("contents").style.height=$("contents").offsetHeight+contentsAddHeight+'px';
	}

obj.style.left=panelLeft+'px';
obj.style.top=panelTop+'px';
}


function controllerRequest(method, url, params, callback, cache)
{
var paramsURL="";

	if(!cache)
	{
	var tm=new Date().getTime();
	params[params.length]='tm=' + tm;
	}

	for(var i=0; i<params.length; i++)
	{
	paramsURL+=(paramsURL.indexOf("?")==-1)?"?":"&";
	paramsURL+=params[i];	
	}
var req=controllerCreateXMLHTTPObject();
	if(req)
	{
		req.onreadystatechange = function()
		{
			if(req.readyState == 4)
			{
				if(req.status==200)
				{
					if(callback)
					{
					callback(req);
					}
				}
				else
				{
				controllerHandleXMLHTTPObjectError(req.statusText);
				}
			}
		};
	url+=paramsURL;
	req.open(method, url, true);
		switch(method)
		{
		case "GET":
		req.send(null);
		break;
		default:
		break;
		}
	}
	if(!req)
	{
	var f=arguments[3]+" ";
	f=f.substring(f.indexOf(" ")+1,f.indexOf("("));
	paramsURL+=(paramsURL.indexOf("?")==-1)?"?":"&";
	paramsURL+='callback='+f;
	url+=paramsURL;
	controllerCreateJSHTTPRequest(url);
	}
}


function controllerHandleXMLHTTPObjectError(message)
{
alert("Error: " + message)
}


function controllerCreateXMLHTTPObject()
{
	if (window.XMLHttpRequest)
	{
	return new XMLHttpRequest();
	}
	if (window.ActiveXObject)
	{
	return new ActiveXObject("Microsoft.XMLHTTP");
	}
return null;
}


function controllerCallback(obj)
{
var s;
s=(obj.responseText)?obj.responseText:obj;
eval(s);
}


function controllerCreateJSHTTPRequest(url)
{
var bodyElem=document.getElementsByTagName("body")[0];
var scriptElem;
	if($("controller_script"))
	{
	var scriptElem=$("controller_script");
	bodyElem.removeChild(scriptElem);
	}
scriptElem=document.createElement("SCRIPT");
scriptElem.setAttribute("id", "controller_script");
scriptElem.setAttribute("src", url);
bodyElem.appendChild(scriptElem);
}


function controllerCreateIFrame(url)
{
var bodyElem;
var iframeElem;
	if($("controller_iframe"))
	{
	iframeElem=$("controller_iframe");
	iframeElem.setAttribute("src", url);
	}
	else
	{
	iframeElem=document.createElement("IFRAME");
	iframeElem.setAttribute("id", "controller_iframe");
	iframeElem.setAttribute("width", "0");
	iframeElem.setAttribute("height", "0");
	iframeElem.setAttribute("scrolling", "no");
	iframeElem.setAttribute("frameborder", "0");
	iframeElem.setAttribute("src", url);
	bodyElem=document.getElementsByTagName("body")[0];
	bodyElem.appendChild(iframeElem);
	}
}


function controllerAssignFunctionsByClass(elemClassName, evt, func)
{
re=new RegExp(elemClassName+'$');
var elems = document.getElementsByTagName('*');
	for(var i=0; i<elems.length; i++)
	{
		if(elems[i].className)
		{
			if(re.test(elems[i].className))
			{
			eval('elems[i].' + evt + '=' + func + ';');
			}
		}
	}
}


function controllerAssignFunctionsByID(elemID, evt, func)
{
re=new RegExp(elemID);
var elems = document.getElementsByTagName('*');
	for(var i=0; i<elems.length; i++)
	{
		if(elems[i].id)
		{
			if(re.test(elems[i].id))
			{
			eval('elems[i].' + evt + '=' + func + ';');
			}
		}
	}
}


function controllerCountElementsOfClass(elemClassName)
{
re=new RegExp(elemClassName+'$');
var elems = document.getElementsByTagName('*');
var num=0;
	for(var i=0; i<elems.length; i++)
	{
		if(elems[i].className)
		{
			if(re.test(elems[i].className))
			{
			num++;
			}
		}
	}
return num;
}


function controllerGetElementByClassByPosition(elemClassName, pos)
{
re=new RegExp(elemClassName+'$');
var current_pos=0;
var elems = document.getElementsByTagName('*');
	for(var i=0; i<elems.length; i++)
	{
		if(elems[i].className)
		{
			if(re.test(elems[i].className))
			{
				if(current_pos==pos)
				{
				return elems[i];
				}
			current_pos++;
			}
		}
	}
return null;
}


function controllerGetPositionByClassByElement(elemClassName, elem)
{
re=new RegExp(elemClassName+'$');
var pos=0;
var elems = document.getElementsByTagName('*');
	for(var i=0; i<elems.length; i++)
	{
		if(elems[i].className)
		{
			if(re.test(elems[i].className))
			{
				if(elems[i]==elem)
				{
				return pos;
				}
			pos++;
			}
		}
	}
return pos;
}


function controllerGetMSIEVersion(ua)
{
var isMSIE;
var re  = new RegExp("MSIE ([0-9]{1,})");
	if (re.exec(ua) != null)
	{
	isMSIE=parseInt( RegExp.$1 );
	}
return isMSIE;
}


function controllerStorageInit()
{
var storage =null;
	if(window.localStorage)
	{
	storage = window.localStorage;
	}
	else
	{
	storage = document.body;
		if (storage.addBehavior)
		{
		storage.addBehavior("#default#userData");
		storage.load("namespace");
		}
		else
		{
		storage =null;
		}
	}
return storage;
}


function controllerStorageSet(storage, key, value)
{
	try
	{
	storage.setItem(key, value);
	}
	catch(e)
	{
		try
		{
		storage.setAttribute(key, value);
		storage.save("namespace");
		}
		catch(e)
		{
		}
	}
}

    
function controllerStorageGet(storage, key)
{
var str;
	try
	{
	str=storage.getItem(key);
	}
	catch(e)
	{
		try
		{
		str=storage.getAttribute(key);
		}
		catch(e)
		{
		}
	}
return str;
}
 
   
function controllerStorageRemove(storage, key)
{
	try
	{
	storage.removeItem(key);
	}
	catch(e)
	{
		try
		{
		storage.removeAttribute(key);
		storage.save("namespace");
		}
		catch(e)
		{
		}
	}
}


function controllerCookieGet(key)
{
var c=document.cookie;
var s=c.indexOf(key+"=");
if(s==-1) return null;
s=c.indexOf("=",s)+1;
var e=c.indexOf(";",s);
if(e==-1) e=c.length;
return c.substring(s,e);
}


function controllerCookieSet(key, value, period)
{
var dm="."+location.host.replace(/www./, "");
var dt=new Date();
dt.setTime(dt.getTime()+period); // 86400*1000*30
document.cookie=key+"="+value+"; expires="+dt.toGMTString()+"; path=/; domain="+dm;
}
