



//Global JS Include for TON Front End Javascript Classes


//See: http://jason.pureconcepts.net/articles/javascript_cookie_object
//Cookie Naming Conventions;  Global Cookies start with g, Component Cookies, with com
var Cookie = {
  data: {},
  options: {expires: 1, domain: "", path: "/", secure: false},

init: function(options, data) {
  Cookie.options = Object.extend(Cookie.options, options || {});

  var payload = Cookie.retrieve();
        if(payload) {
            Cookie.data = payload.evalJSON();
        }
        else {
            Cookie.data = data || {};
        }
        Cookie.store();
    },
    getData: function(key) {
        return Cookie.data[key];
    },
    setData: function(key, value) {
        Cookie.data[key] = value;
        Cookie.store();
    },
    removeData: function(key) {
        delete Cookie.data[key];
        Cookie.store();
    },
    retrieve: function() {
        var start = document.cookie.indexOf(Cookie.options.name + "=");

        if(start == -1) {
            return null;
        }
        if(Cookie.options.name != document.cookie.substr(start, Cookie.options.name.length)) {
            return null;
        }

        var len = start + Cookie.options.name.length + 1;   
        var end = document.cookie.indexOf(';', len);

        if(end == -1) {
            end = document.cookie.length;
        } 
        return unescape(document.cookie.substring(len, end));
    },
    store: function() {
        var expires = '';

        if (Cookie.options.expires) {
            var today = new Date();
            expires = Cookie.options.expires * 86400000;
            expires = new Date(today.getTime() + expires);
        }

        document.cookie = Cookie.options.name + '=' + escape(Object.toJSON(Cookie.data)) + Cookie.getOptions() + ';expires=' + expires;
    },
    erase: function() {
        document.cookie = Cookie.options.name + '=' + Cookie.getOptions() + ';expires=Thu, 01-Jan-1970 00:00:01 GMT';
    },
    getOptions: function() {
        return (Cookie.options.path ? ';path=' + Cookie.options.path : '') + (Cookie.options.domain ? ';domain=' + Cookie.options.domain : '') + (Cookie.options.secure ? ';secure' : '');      
    }
};


Cookie.init({name: 'TONUser'});



			function fnTon_CheckBoxClick(strCheckBoxName,strCheckBoxValue)
			{
				var checkBox=document.getElementsByName(strCheckBoxName);

				if (checkBox.length>0)
				{
					fnTon_RadioClick(strCheckBoxName,strCheckBoxValue);
				}
				else
				{
					checkBox[0].click();
				}

			}

			function fnTon_RadioClick(strRadioName,strSelectValue)
			{
				var radioObject=document.getElementsByName(strRadioName);

				for (i=0;i<radioObject.length;i++)
				{
					if (radioObject[i].value==strSelectValue)
					{
						radioObject[i].click();
						break;
					}
				}
			}


			function fnTon_getRadioValue(objRadio)
			{
			
				var radioCount = objRadio.length;
			
				for(var i = 0; i > radioCount; i++) 
				{
					if(objRadio[i].checked) 
					{
						return objRadio[i].value;
					}
				}

				return "";

			}
			
			//Note - This javascript function is bad, especially if we have other elements in the HTML with the same name
			//Also it does not work with radio buttons
			function fnTon_SelectFormElement(strElementName)
			{
				var elementObject=document.getElementsByName(strElementName);
			
				elementObject[0].click();	//I think we need this in case the DOM needs to respond to events
				elementObject[0].select();
			}

			//Changes display mode for an element none|block
			function fnTon_ShowHide(strElementId)
			{
				var elementObject=document.getElementById(strElementId);
				
				if(elementObject.style.display=='none')
					elementObject.style.display='block';
				else
					elementObject.style.display='none';

			}

			//Changes display mode for an element none|block
			function fnTon_Show(strElementId)
			{
				var elementObject=document.getElementById(strElementId);
				
				elementObject.style.display='block';			

			}

			//Changes display mode for an element none|block
			function fnTon_Hide(strElementId)
			{
				var elementObject=document.getElementById(strElementId);
				
				elementObject.style.display='none';			

			}

			//returns an increased or decreased percentage
			function fnWidthChange(strWidth,strDir)
			{
					intWidth=strWidth.substring(0,strWidth.length-1);
					
					if (strDir==1)
					{
						intWidth++;
					}
					else
					{
						intWidth--;
					}

				

					return(intWidth.toString()+'%');


			}

			function fnTonCom_doWidth(strComponentId,strDir,strFixed)
			{
				var divCom=document.getElementById('ton_comSuper_'+strComponentId);
				var divComName=document.getElementById('ton_com_wName'+strComponentId);

				if(strFixed>0)
					strNewWidth=strFixed+'%';
				else				
 				 strNewWidth=fnWidthChange(divCom.style.width,strDir);

				divCom.style.width=strNewWidth;
				divComName.innerText=strNewWidth;

				new Ajax.Request('/ajax.php?app_axC=admin&app_axH=12345&app_axO=html&app_ac=admincomponents&app_action=Instances&app_task=Instances__Ajax_SetWidth&componentInstanceId='+strComponentId+'&newWidth='+strNewWidth);

//				new Ajax.Updater('rater_ratingblock', '/ajax.php', 
	//				{ method: 'post', parameters: $('frmContentRaterSubmit').serialize(true) });



			}

			function fnTonCom_doMoveUp(strComponentId)
			{
				var divCom=document.getElementById('ton_comSuper_'+strComponentId);

				prevComDiv=divCom.previousSibling;

				//This loop gets us passed any wierd text nodes that are out there in the way
				while(prevComDiv && prevComDiv.nodeType!=1)
				{
					prevComDiv=prevComDiv.previousSibling;					
				}

				if(prevComDiv)
				{
						divCom.parentElement.insertBefore(divCom , prevComDiv);
						strDropId=prevComDiv.id;
						strDropComId=strDropId.substring(13,strDropId.length);

						new Ajax.Request('/ajax.php?app_axC=admin&app_axH=12345&app_axO=html&app_ac=admincomponents&app_action=Instances&app_task=Instances__Ajax_MoveComponent&componentInstanceId='+strComponentId+'&dropInstanceId='+strDropComId+'&direction=1');

				}

			}

			function fnTonCom_doMoveDown(strComponentId)
			{
				var divCom=document.getElementById('ton_comSuper_'+strComponentId);

				prevComDiv=divCom.nextSibling;

				//This loop gets us passed any wierd text nodes that are out there in the way
				while(prevComDiv && prevComDiv.nodeType!=1)
				{
					prevComDiv=prevComDiv.nextSibling;					
				}

				if(prevComDiv)
				{
						divCom.parentElement.insertBefore(prevComDiv , divCom);
						strDropId=prevComDiv.id;
						strDropComId=strDropId.substring(13,strDropId.length);

						new Ajax.Request('/ajax.php?app_axC=admin&app_axH=12345&app_axO=html&app_ac=admincomponents&app_action=Instances&app_task=Instances__Ajax_MoveComponent&componentInstanceId='+strComponentId+'&dropInstanceId='+strDropComId+'&direction=0');

				}

			}


			function fnTonCom_doWeight(strComponentId,strDir)
			{

			}




			function fnTonCreateCookie(name,value,days) {
				if (days) {
					var date = new Date();
					date.setTime(date.getTime()+(days*24*60*60*1000));
					var expires = "; expires="+date.toGMTString();
				}
				else var expires = "";
				document.cookie = name+"="+value+expires+"; path=/";
			}

			function fnTonReadCookie(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 fnTonEraseCookie(name) {
				createCookie(name,"",-1);
			}

				
			function fnQuoteReply(strCommentId)
			{
				
				window.location=window.location + '#doNewComment';

				if(tonIsMember)
				{
							oEditor=FCKeditorAPI.GetInstance('comment');
							oComment=$("forum_reply_id_"+strCommentId).innerHTML;
							oCommentAuthor=$("forum_reply_author_id_"+strCommentId).innerHTML;
							oComment="<blockquote><b>"+oCommentAuthor+" Said:</b><br/>"+oComment+"</blockquote><br/><br/>";
							
							commentCurrent=oEditor.GetHTML();
							oEditor.SetHTML(commentCurrent+oComment);
							oEditor.Focus();
				}

				
			}

			function fnQuickReply(strCommentId)
			{
				window.location=window.location + '#doNewComment';
				
				if(tonIsMember)
				{
						oEditor=FCKeditorAPI.GetInstance('comment');	
						oEditor.Focus();
				}

			}


			function fnGetFormValue(strKey) 
			{
				hu = window.location.search.substring(1);
				gy = hu.split("&");
				for (i=0;i<gy.length;i++) 
				{
					ft = gy[i].split("=");
					if (ft[0] == strKey) 
					{
						return ft[1];
					}
				}
			}








