function checkEula(e){
	if(document.getElementById){
		var eulaAgreed = document.getElementById('eularead');
		if(eulaAgreed){
				if(!eulaAgreed.checked){
					alert('Please read the EULA and check the box indicating that you have read and understood the agreement. If you cannot see the checkbox, scroll down to the bottom of the EULA box.');
					if (e && e.preventDefault){
						e.preventDefault();
					} 
					window.event.returnValue = false;
						return false;
					}
				}
				return true;
			}
		
		}
//----- Browser check. For use when object detection wont work
function checkIt(string) {
	
	var detect = navigator.userAgent.toLowerCase();
	var place = detect.indexOf(string) + 1;
	var thestring = string;
	return place;
}

function toggleClassName(id, class1, class2) {
  if (document.getElementById) {
    var e = $(id);
    if (e) {
      if (e.className !== class1){
			e.className = class1;
		}else{
			e.className = class2; 
		}
    }  
  }
}

function toggleBoxes(theElement) {
     var theForm = theElement.form, z = 0;
	 /*
     while (theForm[z].type == 'checkbox' && theForm[z].name != 'checkall') {
      theForm[z].checked = theElement.checked;
      z++;
     }*/
	 theForm = $A(theForm);
	 theForm.each(function(i){
						   if(i.type == 'checkbox' && i.name != 'checkall' && !i.disabled){
							   i.checked = theElement.checked;
							   }
						   })
    }
	
var toggleBox = {
	init : function(){
		this.itemList = $('itemList');
		if(!this.itemList){return;}
		this.createBox();
		},
	createBox : function(){
		var itemList = this.itemList;
		var clear = document.createElement('br');
		var divGroup = document.createElement('div');
		var label = document.createElement('label');
		var labelT = document.createTextNode('Select All');
		label.setAttribute('for', 'checkThemAll');
		label.setAttribute('class', 'checkAll');
		label.appendChild(labelT);
		
		divGroup.id = 'checkGroup';
		
		var field = document.createElement('input');
		field.setAttribute('id', 'checkThemAll');
		field.setAttribute('name', 'checkThemAll');
		field.setAttribute('type', 'checkbox');
		field.className = 'checkbox';

		divGroup.appendChild(label);
		divGroup.appendChild(field);
		divGroup.appendChild(clear);

		itemList.parentNode.insertBefore(divGroup,itemList);
		this.assign();
		Event.observe(field,'click', this.run.bindAsEventListener(field));
		},
	run : function(){
		var inputs = document.getElementsByTagName('input');
		var thisBox = this;
		$A(inputs).each(function(i){
								 if(i.type == 'checkbox' && i.id != 'checkThemAll' && !i.disabled){
								if(!$('mark_'+i.id)){
			domEl('img','',{src:'assets/images/markedfordeletion.gif','class':'marked', id:'mark_'+i.id}, i.parentNode.parentNode);
									}
									i.checked = thisBox.checked;
									 i.parentNode.parentNode.className = (i.checked) ? 'deleting' : '';
									

									 }
								 });
		},
	assign : function(){
		var inputs = this.itemList.getElementsByTagName('input');
		$A(inputs).each(function(i){
		if(i.type != 'checkbox' || i.id == 'checkThemAll' || i.disabled){throw $continue;}
		var fade = new fx.Opacity(i.parentNode.parentNode);
		Event.observe(i,'click', function(){
			if(!$('mark_'+i.id)){
			domEl('img','',{src:'assets/images/markedfordeletion.gif','class':'marked', id:'mark_'+i.id}, this.parentNode.parentNode);
			}
			this.parentNode.parentNode.className = this.checked ? 'deleting' : '';
											  }.bindAsEventListener(i));
								 });
		}
	}

var confirmUninstall = {
	init : function (){
		
		if($('uninstall')){
			addEvent($('uninstall'), 'click', this.confirmIt);
			}
		if($('delete_uploads')){
			Event.observe($('delete_uploads'), 'click', function(e){
			var deleteUploads = confirm('Are you SURE you want to delete the uploads folder? All of your uploaded files will be completely removed.');
			if(!deleteUploads){
				Event.stop(e);
				}});
			}
		if($('delete_db')){
			Event.observe($('delete_db'), 'click', function(e){
			var deleteDB = confirm('Are you SURE you want to clear the database and delete the config file? This procedure is irreversible, and all of your records will be gone forever. Expanse will be considered uninstalled, and it\'s always a bit sad to say goodbye.');
			if(!deleteDB){
				Event.stop(e);
				}});
			}
		if($('delete_config')){
			Event.observe($('delete_config'), 'click', function(e){
			var deleteConfig = confirm('Are you SURE you want to delete the config file? This procedure is irreversible, and you will HAVE to reinstall Expanse if you wish to access your information.');
			if(!deleteConfig){
				Event.stop(e);
				}});
			}
		},
	confirmIt : function(e){
			if(!e){var e = window.event;}
			var uninstall = confirm('Are you SURE you want to uninstall Expanse? This procedure is irreversible.');
			if(!uninstall){
				return (e.preventDefault) ? e.preventDefault() : e.returnValue = false;
				}
		}
	}
	
function checkAll(obj){
	if(obj){
		if(obj.checked){
			if(!$('noteText')){
				var pEl = obj.parentNode;
				var inputs = pEl.getElementsByTagName('input');
				var txt = document.createTextNode('(Total Access, Users, Database Settings, Etc.)');
				var sptxt = document.createElement('span');
				sptxt.id = 'noteText';
				sptxt.className = 'formNote';
				sptxt.appendChild(txt);
				insertAfter(pEl, sptxt, obj.nextSibling);
				for(var i=0; i<inputs.length;i++){
					if(inputs[i].type=='checkbox' && inputs[i].id != 'adminCheck'){
						inputs[i].checked = true;
						addEvent(inputs[i], 'click', function(e){
									if($('adminCheck').checked){
										var input = (window.event) ? window.event.srcElement : this;
										input.checked = true;
										}						 
									
															 });
						}
						
					}
				}
			}
		addEvent(obj, 'click', function(){
										if($('disabled').checked == false){
											
			var pEl = obj.parentNode;
			var inputs = pEl.getElementsByTagName('input');
			if(obj.checked){
				if(!$('noteText')){
				var txt = document.createTextNode('(Total Access, Users, Database Settings, Etc.)');
				var sptxt = document.createElement('span');
				sptxt.id = 'noteText';
				sptxt.className = 'formNote';
				sptxt.appendChild(txt);
				insertAfter(pEl, sptxt, obj.nextSibling);
				}
				var noteFade = new fx.Opacity($('noteText'), {duration: 400});
				noteFade.hide();
				noteFade.toggle();
				for(var i=0; i<inputs.length;i++){
					if(inputs[i].type=='checkbox' && inputs[i].id != 'adminCheck'){
						inputs[i].checked = true;
						addEvent(inputs[i], 'click', function(e){
									if($('adminCheck').checked){
										var input = (window.event) ? window.event.srcElement : this;
										input.checked = true;
										}						 
									
															 });
						}
						
					}
				} else {
					if(!$('noteText')){
						for(var i=0; i<inputs.length;i++){
							if(inputs[i].type=='checkbox' && inputs[i].id != 'adminCheck'){
								inputs[i].checked = false;
								}
							}
						}
					
					if($('noteText')){
						var noteFade = new fx.Opacity($('noteText'), {duration: 400});
						noteFade.toggle();
						for(var i=0; i<inputs.length;i++){
							if(inputs[i].type=='checkbox' && inputs[i].id != 'adminCheck'){
								inputs[i].checked = false;
								}
							}
						}
				}
								
			
											}
										
										});
		}
	
	}
	
function disableBoxes(){
	if($('disabled') && $('categoryBoxes')){
		addEvent($('disabled'), 'click', function(){
			if($('disabled').checked){
				$('categoryBoxes').style.MozOpacity = '0.5';
				$('categoryBoxes').style.opacity = '0.5';
				$('categoryBoxes').style.filter = 'alpha(opacity=50)';
				$('categoryBoxes').style.backgroundColor = '#fff';
				} else {
					$('categoryBoxes').style.MozOpacity = '1.0';
					$('categoryBoxes').style.opacity = '1.0';
					$('categoryBoxes').style.filter = 'alpha(opacity=100)';
					$('categoryBoxes').style.backgroundColor = (document.all) ? '#fff' : 'none';
					}
								 
								 });
		}
	
	
	}
	
function debug(obj, op) {
 	var output = '';
    for (var i in obj)
        output += i+ ' | \n';
    if(!op){
		alert(output);
		} else{
		document.write(output);		
		}
	
}

function insertAfter(parent, node, referenceNode) {
	parent.insertBefore(node, referenceNode.nextSibling);
}

/*
	domEl() painless DOM manipulation
*/

var domEl = function(e,c,a,p,x) {
if(e||c) {
	c=(typeof c=='string'||(typeof c=='object'&&!c.length))?[c]:c;	
	e=(!e&&c.length==1)?document.createTextNode(c[0]):e;	
	var n = (typeof e=='string')?document.createElement(e) : !(e&&e===c[0])?e.cloneNode(false):e.cloneNode(true);	
	if(e.nodeType!=3) {
		c[0]===e?c[0]='':'';
		for(var i=0,j=c.length;i<j;i++) typeof c[i]=='string'? ((c[i] =='') ? '': n.appendChild(document.createTextNode(c[i]))):n.appendChild(c[i].cloneNode(true));
		if(a) {
			for (var i in a) i=='class'?n.className=a[i]:(i == 'style')?n.style.cssText=a[i]:n.setAttribute(i,a[i]);}
	}
}
	if(!p)return n;
	p=(typeof p=='object'&&!p.length)?[p]:p;
	for(var i=(p.length-1);i>=0;i--) {
		if(x){while(p[i].firstChild)p[i].removeChild(p[i].firstChild);
			if(!e&&!c&&p[i].parentNode)p[i].parentNode.removeChild(p[i]);}
		if(n){
			if(!document.all){
				p[i].appendChild(n.cloneNode(true));
				} else {
				if(n.canHaveChildren){
					p[i].appendChild(n.cloneNode(true));
				} else if(p[i].canHaveChildren) {
				p[i].appendChild(n.cloneNode(false));			
				} else {
					p[i].parentNode.appendChild(n);
					}
				}
			} 
	}	
}

function setDateFormat(){
	if(document.getElementById('dateformat') && document.getElementById('timeformat')){
		var dformat = document.getElementById('dateformat').value;
		var offset = ($F('timeoffset') == '') ? theZone() : $('timeoffset').value;
		xajax_returnDate(dformat,offset);
		var tformat = document.getElementById('timeformat').value;
		xajax_returnTime(tformat,offset);
		}
	}
    function ToggleAll(e)
    {
	if (e.checked) {
	    CheckAll();
	}
	else {
	    ClearAll();
	}
    }
   function CheckAll()
    {
	var ml = document.edit;
	var len = ml.elements.length;
	for (var i = 0; i < len; i++) {
	    var e = ml.elements[i];
	    eval(e.checked = true);
	}
	ml.toggleAll.checked = true;
    }
    function ClearAll()
    {
	var ml = document.edit;
	var len = ml.elements.length;
	for (var i = 0; i < len; i++) {
	    var e = ml.elements[i];
	    eval(e.checked = false);
	}
	ml.toggleAll.checked = false;
    }
    
function stripe(cl){
	if(document.getElementById){						
		var table = document.getElementsByClassName(cl);
		if (table){
			for(var x=0;x<table.length;x++){
				table[x].className += ' stripeTableSib';
					var rows = table[x].getElementsByTagName("tr");	
					for(i = 0; i < rows.length; i++){			
						//manipulate rows	
							//doAlternate(rows[i], i);
							if(i % 2 == 0){
								rows[i].className += " stripe1";
							} else {
								rows[i].className += " stripe2";
							}
					}
				}
			
		} 
	}
}

function appendInputTypeClasses() {
	if ( !document.getElementsByTagName )
	return;
var inputs = document.getElementsByTagName('input');
var inputLen = inputs.length;
	for ( i=0;i<inputLen;i++ ) {
		if ( inputs[i].getAttribute('type') )
		inputs[i].className += ' '+inputs[i].getAttribute('type');
	}
}
/*
Cookie functions. Get, Set, and Delete
*/
function getCookie( name ) {
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {
		return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ";", len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}
	
function setCookie( name, value, expires, path, domain, secure ) {
	var today = new Date();
	today.setTime( today.getTime() );
	if ( expires ) {
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );
	document.cookie = name+"="+escape( value ) +
		( ( expires ) ? ";expires="+expires_date.toGMTString() : "" ) + //expires.toGMTString()
		( ( path ) ? ";path=" + path : "" ) +
		( ( domain ) ? ";domain=" + domain : "" ) +
		( ( secure ) ? ";secure" : "" );
}
	
function deleteCookie( name, path, domain ) {
	if ( getCookie( name ) ) document.cookie = name + "=" +
			( ( path ) ? ";path=" + path : "") +
			( ( domain ) ? ";domain=" + domain : "" ) +
			";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

/*
ToolTip code courtesy
*/
document.getElementsByClassName = function (needle)
{
  var         my_array = document.getElementsByTagName("*");
  var         retvalue = new Array();
  var        i;
  var        j;
  for (i = 0, j = 0; i < my_array.length; i++)
  {
    var c = " " + my_array[i].className + " ";
    if (c.indexOf(" " + needle + " ") != -1)
      retvalue[j++] = my_array[i];
  }
  return retvalue;
}
function addEvent( obj, type, fn ) {
	if(obj){
		if (obj.addEventListener) {
		obj.addEventListener( type, fn, false );
		EventCache.add(obj, type, fn);
	}
	else if (obj.attachEvent) {
		obj["e"+type+fn] = fn;
		obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
		obj.attachEvent( "on"+type, obj[type+fn] );
		EventCache.add(obj, type, fn);
	}
	else {
		obj["on"+type] = obj["e"+type+fn];
	}
		}
	
}
function removeEvent(obj, evType, fn, useCapture){
  if (obj.removeEventListener){
    obj.removeEventListener(evType, fn, useCapture);
    return true;
  } else if (obj.detachEvent){
    var r = obj.detachEvent("on"+evType, fn);
    return r;
  } else {
    alert("Handler could not be removed");
  }
}	
var EventCache = function(){
	var listEvents = [];
	return {
		listEvents : listEvents,
		add : function(node, sEventName, fHandler){
			listEvents.push(arguments);
		},
		flush : function(){
			var i, item;
			for(i = listEvents.length - 1; i >= 0; i = i - 1){
				item = listEvents[i];
				if(item[0].removeEventListener){
					item[0].removeEventListener(item[1], item[2], item[3]);
				};
				if(item[1].substring(0, 2) != "on"){
					item[1] = "on" + item[1];
				};
				if(item[0].detachEvent){
					item[0].detachEvent(item[1], item[2]);
				};
				item[0][item[1]] = null;
			};
		}
	};
}();
addEvent(window,'unload',EventCache.flush);
function HelpHover()
{
	this._mousePosX = 0;
	this._mousePosY = 0;
	this._hoverItem = null;
	this._hoverContents = null;
}
HelpHover.prototype.init = function()
{
	var hh = this;
	var helpItems = document.getElementsByClassName('hasHelp');
	for (var i=0; i<helpItems.length; i++)
	{
		helpItems[i].onmouseover = function(e)
		{
			if (!e) var e = window.event;
			if (e.pageX || e.pageY)
			{
				hh.mousePosX = e.pageX;
				hh.mousePosY = e.pageY;
			}
			else if (e.clientX || e.clientY)
			{
				
hh.mousePosX = (document.documentElement && document.documentElement.scrollLeft) ? e.clientX + document.documentElement.scrollLeft : e.clientX + document.body.scrollLeft;
hh.mousePosY = (document.documentElement && document.documentElement.scrollTop) ? e.clientY + document.documentElement.scrollTop : e.clientY + document.body.scrollTop;
			}
			hh._hoverItem = this;
			hh._hoverContents = document.getElementById(this.id+'Help');
			hh.move();
		}
		helpItems[i].onmouseout = function (e)
		{
			hh.out();
		}
	}
}
HelpHover.prototype.out = function()
{
	this._hoverContents.style.top = -10000+'px';
	this._hoverContents.style.left = -10000+'px';
	this._hoverItem = null;
	this._hoverContents = null;
	// IE hack because of floating elements over SELECT drop boxes
	if(document.all){
		selects = document.getElementsByTagName('select');
		selects.length.times(function(n){
							selects[n].style.visibility = 'visible';
									  });
		toggleFrame('showSelects');
		}
	//End IE HACK
}
HelpHover.prototype.move = function()
{
	this._hoverContents.style.top = this.mousePosY-70+'px';
	this._hoverContents.style.left = this.mousePosX-278+'px';
	// IE hack because of floating elements over SELECT drop boxes
	if(document.all){
		selects = document.getElementsByTagName('select');
		selects.length.times(function(n){
			selects[n].style.visibility = 'hidden';
									  });
		}
	//End IE HACK
}

function toggleFrame(type){
	if(type == 'hideSelects'){
		if(!$('hideFrame')){
			var objBody = document.getElementsByTagName("body").item(0);
			var arrayPageSize = getPageSize();
	// create overlay div and hardcode some functional styles (aesthetic styles are in CSS file)
			var objOverlay = document.createElement("iframe");
			objOverlay.setAttribute('id','hideFrame');
			objOverlay.style.display = 'block';
			objOverlay.style.height = (arrayPageSize[1] + 'px');
			objOverlay.style.position = 'absolute';
			objOverlay.style.top = '0';
			objOverlay.style.left = '0';
			objOverlay.style.zIndex = '90';
			objOverlay.style.width = (arrayPageSize[0] + 'px');
			objOverlay.style.filter='progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)';
			objBody.insertBefore(objOverlay, objBody.firstChild);
			} else {
				$('hideFrame').style.display = 'block';
				}
		} else if(type == 'showSelects'){
			if($('hideFrame')){
				$('hideFrame').style.display = 'none';
				}
			}
	
	}

function theZone(){
   var d, tz, s = "";
   d = new Date();
   tz = d.getTimezoneOffset();
   if (tz < 0)
      s += Math.abs(tz) / 60;
   else if (tz == 0)
      s += "";
   else
      s += '-'+tz / 60;
   return(s);
}

function confirmEula(){
	
	var eulaStep1 = document.getElementById('eulaStep1');
	if(eulaStep1){
		addEvent(eulaStep1, 'submit', checkEula);
		}
	
	}
function dInit(){
	if($('dateformat') && $('timeformat')){
		addEvent($('dateformat'), 'blur', function(){
			var offset = ($F('timeoffset') == '') ? theZone() : $F('timeoffset');
			var tformat = $F('timeformat');
			var dformat = $F('dateformat');
			xajax_returnDate(dformat,offset);
		});
		addEvent($('timeformat'), 'blur', function(){
			var offset = ($F('timeoffset') == '') ? theZone() : $F('timeoffset');
			var tformat = $F('timeformat');
			var dformat = $F('dateformat');
			xajax_returnTime(tformat,offset);
		});
		addEvent($('timeoffset'), 'blur', function(){
			var offset = ($F('timeoffset') == '') ? theZone() : $F('timeoffset');
			var tformat = $F('timeformat');
			var dformat = $F('dateformat');
			xajax_returnDate(dformat,offset);
			xajax_returnTime(tformat,offset);
		});
		addEvent($('dateformat'), 'keyup', function(){
			var offset = ($F('timeoffset') == '') ? theZone() : $F('timeoffset');
			var tformat = $F('timeformat');
			var dformat = $F('dateformat');
			xajax_returnDate(dformat,offset);
		});
		addEvent($('timeformat'), 'keyup', function(){
			var offset = ($F('timeoffset') == '') ? theZone() : $F('timeoffset');
			var tformat = $F('timeformat');
			var dformat = $F('dateformat');
			xajax_returnTime(tformat,offset);
		});
		addEvent($('timeoffset'), 'keyup', function(){
			var offset = ($F('timeoffset') == '') ? theZone() : $F('timeoffset');
			var tformat = $F('timeformat');
			var dformat = $F('dateformat');
			xajax_returnDate(dformat,offset);
			xajax_returnTime(tformat,offset);
		});
			
		}
	}
	
var autoThumb = {
	autothumb : Object,
	thumbField : Object,
	inputs : Array,
	init : function (){
		this.autothumb = $('autothumb');
		this.thumbField = $('thumbField');
		this.inputs = document.getElementsByTagName('input');
		if(this.autothumb && this.thumbField){
			this.loopInputs();
			}
		},
	loopInputs : function(){
		var inputs = this.inputs;
			inputs = $A(inputs);
			inputs.each(function(i){
								 
			if(i.type == "checkbox" && i.name == "autothumb"){
				addEvent(i, 'click', function(){
						toggleClassName('thumbField', 'visible', 'hidden');
						toggleClassName('cropLinksContainer', 'hidden', 'visible');
						if($('thumbNailThumb')){
							$('thumbNailThumb').style.cursor = (i.checked) ? 'pointer' : '';
						if(!i.checked){
							removeEvent($('thumbNailThumb'), 'click', loadCrop);
							} else {
							addEvent($('thumbNailThumb'), 'click', loadCrop);
							}
							}
						});
				if(i.checked==true){
						$('thumbField').className = 'hidden';
						createCropLinks();
						if($('thumbNailThumb')){
							$('thumbNailThumb').style.cursor = 'pointer';
						}
					} else {
						if($('thumbNailFields')){
							$('thumbNailFields').className = 'hidden';
							}
						if($('thumbField')){$('thumbField').className = 'visible';}
						if($('thumbNailThumb')){$('thumbNailThumb').style.cursor = '';}
					}
				
				}
			
								 });

		

		}
	}

function collapseIt(){
var fadeTheBox = new Array;
var collBoxId;
var collSwitch = document.getElementsByClassName("collSwitch");
for(i=0;i<collSwitch.length;i++){
			collBoxId = collSwitch[i].id+'Contents';
			if($(collBoxId)){
			fadeTheBox[collBoxId] = new fx.Combo($(collBoxId), {duration: 400});
			fadeTheBox[collBoxId].hide($(collBoxId), 'height');		
				}
			addEvent(collSwitch[i], 'click', function(e){
				var divId = this.id+'Contents';
				if($(divId)){
					fadeTheBox[divId].toggle('height');
				}
				});
	}
}

function print_r(theObj){
  if(theObj.constructor == Array ||
     theObj.constructor == Object){
    document.write("<ul>")
    for(var p in theObj){
      if(theObj[p].constructor == Array||
         theObj[p].constructor == Object){
document.write("<li>["+p+"] => "+typeof(theObj)+"</li>");
        document.write("<ul>")
        print_r(theObj[p]);
        document.write("</ul>")
      } else {
document.write("<li>["+p+"] => "+theObj[p]+"</li>");
      }
    }
    document.write("</ul>")
  }
}

var setChecks = {
	checkBoxes : Array,
	init : function(){
		this.checkBoxes = ['online', 'autothumb', 'comments', 'smilies', 'for_sale'];
		this.doCheckBoxes();
		},
	assignRemember : function(){
		var boxes = this.checkBoxes;
		boxes.each(function(box){
			addEvent($(box), 'click', function(){
				setChecks.rememberChecks(this);
			});	
		});
		},
	rememberChecks :  function(obj){
if(obj){
	
		var keepStateID = 'keepState'+obj.id;
		var keepMessage;
		if(obj.checked == true){
			keepMessage = 'Keep this button checked';
		} else {
			keepMessage = 'Keep this button unchecked';
		}
		if($(keepStateID)){
			$(keepStateID).parentNode.removeChild($(keepStateID));
			}
		insertAfter(obj.parentNode, domEl('span', domEl('a', keepMessage, {id : keepStateID, href : 'javascript:;', 'class' : 'keepState'}), {id : 'keepStateContainer'+obj.id}), obj);
		Event.observe($(keepStateID), 'mouseover', function(){window.status=keepMessage; return true;});
		Event.observe($(keepStateID), 'mouseout', function(){window.status='';return true;});
		
		
		var keepState = $(keepStateID);
		var opayk = new fx.Opacity(keepState, {duration: 4500});
		opayk.toggle();
		addEvent(keepState, 'click', function(){
				setChecks.setCheckBox(obj);
				opayk.duration = 1600;
				opayk.toggle();
										  });
			}
		},
	setCheckBox : function(obj){
		if(obj.checked == true){
			setCookie(obj.id+'Checked', 'checked');
			} else {
			setCookie(obj.id+'Checked', 'unchecked');
		}
	},
	doCheckBoxes : function(){
		var docloc = document.URL;
		var add = /add.php/;
		var edit = /edit.php/;
		if((docloc.match(add) && !docloc.match(edit))){
			this.assignRemember();
			this.assignGets();
		}	
	
		},
	assignGets : function(){
		this.checkBoxes.each(function(box){
				setChecks.getCheck($(box));
			});
		},
	getCheck : function(obj){
		if(obj){
			var cookie = getCookie(obj.id+'Checked');
			if(cookie !== null){
				if(cookie == 'checked'){
					obj.checked = true;
					} else {
					obj.checked = false;
					}
				}	
		}
		
		}
	}

var reorder = {
	sortContainer : Object,
	draggables : Array,
	init:function(){
		
		if($('itemList')){
			this.sortContainer = $('itemList');
			var itemsCount = this.sortContainer.getElementsByTagName('div').length;
			if(itemsCount <= 1){
				return;
				}
			var reorderL = domEl('a', 'Reorder your items', {href:'javascript:;',id:'reorderLink'});
			var response = domEl('div', '', {id:'responseText'});
			Event.observe(reorderL, 'click',reorder.create);
			Event.observe(reorderL, 'mouseover', function(){window.status='Reorder your items'; return true;});
			Event.observe(reorderL, 'mouseout', function(){window.status='';return true;});
			
			this.sortContainer.parentNode.insertBefore(response, this.sortContainer);
			this.sortContainer.parentNode.insertBefore(reorderL, this.sortContainer);
			}
		},
	create:function(){
		if($('order_by') && $F('order_by') !== 'order_rank'){
			return alert('If you wish to reorder your items, you must go to Admin Settings > Preferences > Theme/Appearance Settings and choose to order your categories by User Rank.');
			}
		$('reorderLink').childNodes[0].nodeValue = 'I\'m done reordering';
			Event.stopObserving($('reorderLink'), 'click', reorder.create);
			Event.observe($('reorderLink'), 'click', reorder.destroy);
		Element.addClassName(reorder.sortContainer, 'reordering');
		Sortable.create('itemList',{tag:'div',ghosting:false,constraint:false,hoverclass:'over'});
		},
	destroy:function(){
		Event.stopObserving($('reorderLink'), 'click', reorder.destroy);
		Event.observe($('reorderLink'), 'click', reorder.create);
		$('reorderLink').childNodes[0].nodeValue = 'Reorder your items';
		reorder.updateOrder();
		Sortable.destroy('itemList');
		Element.removeClassName(reorder.sortContainer, 'reordering');
		},
	updateOrder:function(){
	 xajax_updateOrder(Sortable.serialize('itemList'));
		}
	};

function makeAlert(){
	button = $('process');
	if(button){
		var dims = getPageSize();
		var middlePos = getPageScroll()[1] + (getPageSize()[3] / 3)+'px';
		var note = domEl('blockquote', domEl('h1', 'Please wait...'),{id:'overlayHelp','class':'helpContents','style':'position:absolute;top:'+middlePos+';left:40%;'});
		
		createOverlay();
		hideSelects();
		$('overlay').className += ' submit';
		button.style.visibility='hidden';
		$('post').appendChild(note);
		button.parentNode.insertBefore(document.createTextNode('Please Wait...'), button);
		}
	}
function loadAlert(){
	if($('process')){	
		Event.observe($('post'), 'submit', makeAlert);
		validate.init();
		}
	}
	
var resizeEditor = {
	init : function(){
		if($('descr___Frame') || $('descr') ) {
			this.createText();
			}
		},
	createText : function(){
	var sizerCont = domEl('span', [domEl('a', '+', {href : 'javascript:;', id : 'increaseBox'}), domEl('a', '-', {href : 'javascript:;', id : 'decreaseBox'})], {id : 'sizerContainer'});
	insertAfter($('descr').parentNode, sizerCont, $('descr'));
	Event.observe($('increaseBox'), 'mouseover', function(){window.status='Increase the editor size'; return true;});
	Event.observe($('increaseBox'), 'mouseout', function(){window.status='';return true;});
	Event.observe($('decreaseBox'), 'mouseover', function(){window.status='Decrease the editor size'; return true;});
	Event.observe($('decreaseBox'), 'mouseout', function(){window.status='';return true;});
	this.addActions();
		},
	addActions : function(){
			var edObj = ($('descr___Frame')) ? $('descr___Frame') : $('descr');
			if($('safari_descr')){
				edObj = $('safari_descr');
				}
			remDescr = new fx.RememberHeight(edObj, 365, {duration: 400});
			addEvent($('increaseBox'), 'click', function(){
									remDescr.resize(100);
														 })
			addEvent($('decreaseBox'), 'click', function(){
									remDescr.resize(-100);
														 })
		}
	};

var resizeEditorEn = {
	init : function(){
		if($('descren___Frame') || $('descren') ) {
			this.createText();
			}
		},
	createText : function(){
	var sizerCont = domEl('span', [domEl('a', '+', {href : 'javascript:;', id : 'increaseBoxEn'}), domEl('a', '-', {href : 'javascript:;', id : 'decreaseBoxEn'})], {id : 'sizerContainer'});
	insertAfter($('descren').parentNode, sizerCont, $('descren'));
	Event.observe($('increaseBoxEn'), 'mouseover', function(){window.status='Increase the editor size'; return true;});
	Event.observe($('increaseBoxEn'), 'mouseout', function(){window.status='';return true;});
	Event.observe($('decreaseBoxEn'), 'mouseover', function(){window.status='Decrease the editor size'; return true;});
	Event.observe($('decreaseBoxEn'), 'mouseout', function(){window.status='';return true;});
	this.addActions();
		},
	addActions : function(){
			var edObjEn = ($('descren___Frame')) ? $('descren___Frame') : $('descren');
			if($('safari_descren')){
				edObjEn = $('safari_descren');
				}
			remDescren = new fx.RememberHeight(edObjEn, 365, {duration: 400});
			addEvent($('increaseBoxEn'), 'click', function(){
									remDescren.resize(100);
														 })
			addEvent($('decreaseBoxEn'), 'click', function(){
									remDescren.resize(-100);
														 })
		}
	};

var resizeEditorEn1 = {
	init : function(){
		if($('descren1___Frame') || $('descren1') ) {
			this.createText();
			}
		},
	createText : function(){
	var sizerContEn1 = domEl('span', [domEl('a', '+', {href : 'javascript:;', id : 'increaseBoxEn1'}), domEl('a', '-', {href : 'javascript:;', id : 'decreaseBoxEn1'})], {id : 'sizerContainer'});
	insertAfter($('descren1').parentNode, sizerContEn1, $('descren1'));
	Event.observe($('increaseBoxEn1'), 'mouseover', function(){window.status='Increase the editor size'; return true;});
	Event.observe($('increaseBoxEn1'), 'mouseout', function(){window.status='';return true;});
	Event.observe($('decreaseBoxEn1'), 'mouseover', function(){window.status='Decrease the editor size'; return true;});
	Event.observe($('decreaseBoxEn1'), 'mouseout', function(){window.status='';return true;});
	this.addActions();
		},
	addActions : function(){
			var edObjEn1 = ($('descren1___Frame')) ? $('descren1___Frame') : $('descren1');
			if($('safari_descren1')){
				edObjEn1 = $('safari_descren1');
				}
			remDescren1 = new fx.RememberHeight(edObjEn1, 365, {duration: 400});
			addEvent($('increaseBoxEn1'), 'click', function(){
									remDescren1.resize(100);
														 })
			addEvent($('decreaseBoxEn1'), 'click', function(){
									remDescren1.resize(-100);
														 })
		}
	};	
var resizeEditorEnPrb = {
	init : function(){
		if($('descrprb___Frame') || $('descrprb') ) {
			this.createText();
			}
		},
	createText : function(){
	var sizerContEn = domEl('span', [domEl('a', '+', {href : 'javascript:;', id : 'increaseBoxPrb'}), domEl('a', '-', {href : 'javascript:;', id : 'decreaseBoxPrb'})], {id : 'sizerContainerPrb'});
	insertAfter($('descrprb').parentNode, sizerContEn, $('descrprb'));
	Event.observe($('increaseBoxPrb'), 'mouseover', function(){window.status='Increase the editor size'; return true;});
	Event.observe($('increaseBoxPrb'), 'mouseout', function(){window.status='';return true;});
	Event.observe($('decreaseBoxPrb'), 'mouseover', function(){window.status='Decrease the editor size'; return true;});
	Event.observe($('decreaseBoxPrb'), 'mouseout', function(){window.status='';return true;});
	this.addActions();
		},
	addActions : function(){
			var edObj = ($('descrprb__Frame')) ? $('descrprb___Frame') : $('descrprb');
			if($('safari_descrprb')){
				edObj = $('safari_descrprb');
				}
			remDescrPrb = new fx.RememberHeight(edObj, 365, {duration: 400});
			addEvent($('increaseBoxPrb'), 'click', function(){
									remDescrPrb.resize(100);
														 })
			addEvent($('decreaseBoxPrb'), 'click', function(){
									remDescrPrb.resize(-100);
														 })
		}
	};	
	
var accordion = {
	divs : Array,
	links: Array,
	toggler: Object,
	init : function() {
		this.divs = document.getElementsByClassName('stretch');
		this.links = document.getElementsByClassName('stretchToggle');
		this.run();
	},
	run : function() {
		this.toggler = new fx.Accordion(this.links, this.divs, {opacity: true});
		this.hideDefault();
		this.toggler.showThisHideOpen = function(toShow){
		this.elements.each(function(el, i){
		if (el.offsetHeight > 0 && el != toShow) this.clearAndToggle(el);
		}.bind(this));
		setTimeout(function(){this.clearAndToggle(toShow)  ;}.bind(this), this.options.delay);
		};
	},
	hideDefault : function() {
		if(this.checkHash()){return;}
		if(this.links.length > 1 || (this.links.length == 1 && this.links[0].id != 'wedge')){
			this.toggler.showThisHideOpen(this.divs[0]);
			}
		
	},
	checkHash : function(){
		var found = false;
		this.links.each(function(h3, i){
							  if(window.location.href.indexOf(h3.title) > 0){
								  accordion.toggler.showThisHideOpen(accordion.divs[i]);
								  found=true;
								  }
							  });
		return found;
		}
};

var navigation = {
	divs : Array,
	links: Array,
	toggler: Object,
	init : function() {
		this.divs = document.getElementsByClassName('navigation');
		this.links = document.getElementsByClassName('navigationToggle');
		this.run();
	},
	run : function() {
		this.toggler = new fx.Accordion(this.links, this.divs, {opacity: true});
		this.hideDefault();
		this.toggler.showThisHideOpen = function(toShow){
		this.elements.each(function(el, i){
		if (el.offsetHeight > 0 && el != toShow) this.clearAndToggle(el);
		}.bind(this));
		setTimeout(function(){this.clearAndToggle(toShow)  ;}.bind(this), this.options.delay);
		};
	},
	hideDefault : function() {
		if(this.checkHash()){return;}
		if(this.links.length > 1 || (this.links.length == 1 && this.links[0].id != 'wedge')){
			this.toggler.showThisHideOpen(this.divs[0]);
			}
		
	},
	checkHash : function(){
		var found = false;
		this.links.each(function(h3, i){
							  if(window.location.href.indexOf(h3.title) > 0){
								  accordion.toggler.showThisHideOpen(accordion.divs[i]);
								  found=true;
								  }
							  });
		return found;
		}
};

var hiliteInput = {
	init : function(){
		var fields = document.getElementsByClassName('shareField');
		fields = $A(fields);
		fields.each(function(i){
							 ////alert(i);
							Event.observe(i, 'focus', function(){
															   i.select();
															   });
							 });
		}
	}		
	
var addCustomFields = {
		custField : Object,
		custGroup : Object,
		fieldCount : Number,
		custFields : Object,
		addLabel : String,
		removeLabel : String,
		clearLabel : String,
		labelInnerText : String,
		fieldInnerText : String,
		customLabels : Array,
	init: function(){
		
		if(!$('customLabel1')){return;}
			this.customLabels = eval($F('customList'));
			this.labelInnerText = 'Label (click to edit)';
			this.fieldInnerText = 'Value (click to edit)';
			this.custField = $('customLabel1');
			this.custGroup = this.custField.parentNode;
			this.fieldCount = this.custGroup.getElementsByTagName('input').length;
			this.addLabel = '+ Add another custom field';
			this.removeLabel = '- Remove custom field';
			this.clearLabel = 'Clear custom fields';

			this.setInitialValues();
			this.addText();
		},

	setInitialValues : function(){
		var firstLabel = $('customLabel1');
		var firstField = $('customValue1');
		firstLabel.value = (firstLabel.value == '') ? this.labelInnerText : firstLabel.value;
		firstLabel.className += ' fieldLabel';
		this.toggleValue(firstLabel.value, firstLabel);
		firstField.value = (firstField.value == '') ? this.fieldInnerText : firstField.value;
		firstField.className += ' fieldValue';
		this.toggleValue(firstField.value, firstField);
		if($('increaseBox1')){return;}
		this.insertSizers(firstField, 1);
		new AutoSuggest(firstLabel,addCustomFields.customLabels);
	},
	addText: function(){
		domEl('div', '', {id:'customFieldsControls'}, this.custGroup);
		custControls = $('customFieldsControls');
		domEl('a', this.addLabel, {style : 'margin:0.3em;', href : 'javascript:;', id : 'addCustom'}, custControls);
		domEl('a', this.removeLabel, {style : 'margin:0.3em', href : 'javascript:;', id : 'removeCustom'}, custControls);
		domEl('a', this.clearLabel, {style : 'margin:0.3em', href : 'javascript:;', id : 'resetCustom'}, custControls);
		Event.observe($('addCustom'), 'mouseover', function(){window.status=this.addLabel; return true;}.bindAsEventListener(this));
		Event.observe($('addCustom'), 'mouseout', function(){window.status='';return true;});
		Event.observe($('removeCustom'), 'mouseover', function(){window.status=this.removeLabel; return true;}.bindAsEventListener(this));
		Event.observe($('removeCustom'), 'mouseout', function(){window.status='';return true;});
		Event.observe($('resetCustom'), 'mouseover', function(){window.status=this.clearLabel; return true;}.bindAsEventListener(this));
		Event.observe($('resetCustom'), 'mouseout', function(){window.status='';return true;});
		Event.observe($('addCustom'), 'click', this.addField);	
		Event.observe($('removeCustom'), 'click', this.removeFields);	
		Event.observe($('resetCustom'), 'click', this.resetFields);	
		},
	addField : function(){
		var clear = document.createElement('br');
		var divGroup = document.createElement('div');
		var label = document.createElement('input');
		var fieldCount = addCustomFields.countFields();
		fieldCount = fieldCount+1;
		var labelT = document.createTextNode('Field Label'+fieldCount);
		var optID = 'custom'+fieldCount;
		var customLabelID = 'customLabel'+fieldCount;
		var customFieldID = 'customValue'+fieldCount;
		//label.setAttribute('for', optID);
		//label.appendChild(labelT);
		
		label.value = addCustomFields.labelInnerText;
		label.id = customLabelID;
		label.className = 'fieldLabel text';
		label.setAttribute('name', 'custom['+fieldCount+'][field]');
		
		divGroup.id = optID+'Group';
		divGroup.className = 'customFieldGroup';
		var field = document.createElement('textarea');
		field.id = customFieldID;
		field.setAttribute('id', optID);
		field.setAttribute('name', 'custom['+fieldCount+'][value]');
		field.className = 'fieldValue';
		//field.appendChild(document.createTextNode(addCustomFields.fieldInnerText));
		field.value = addCustomFields.fieldInnerText;
		addCustomFields.toggleValue(addCustomFields.labelInnerText, label);
		addCustomFields.toggleValue(addCustomFields.fieldInnerText, field);
		divGroup.appendChild(label);
		divGroup.appendChild(field);
		//divGroup.appendChild(clear);
		//divGroup.appendChild(deleteLink);
		addCustomFields.custGroup.insertBefore(divGroup,$('customFieldsControls'));
		addCustomFields.insertSizers(field,fieldCount);
		new AutoSuggest(label,addCustomFields.customLabels);
		},
	resetFields : function(){
		var divs = addCustomFields.custGroup.getElementsByTagName('div');
		var resetConf = confirm('Are you sure you want to delete all of your custom fields?');
		
		
		if(resetConf){
			
			divs.length.times(function(n){
			if(divs[0].id == 'customFieldsControls'){throw $continue;}
			 addCustomFields.custGroup.removeChild(divs[0]);
										 });
			addCustomFields.setInitialValues();
		}
	},
	countFields : function(){
		this.Fields = this.custGroup.getElementsByTagName('input');
		return this.fieldCount = this.Fields.length;
	},
	removeFields : function(){
			divs = $A(document.getElementsByClassName('customFieldGroup', addCustomFields.custGroup)).last();
			if(divs){
				addCustomFields.custGroup.removeChild(divs);
				}
			
	},
	toggleValue : function(origValue, obj){
		Event.observe(obj, 'focus', function(){
		this.value = (this.value == origValue) ? '' : this.value;
		}.bindAsEventListener(obj));
		Event.observe(obj, 'blur', function(){
		this.value = (this.value == '') ? origValue : this.value;
		}.bindAsEventListener(obj));
	},
	insertSizers : function(obj, num){
	var sizerCont = domEl('span', [domEl('a', '+', {href : 'javascript:;', id : 'increaseBox'+num}), domEl('a', '-', {href : 'javascript:;', id : 'decreaseBox'+num})], {'class' : 'sizerContainer', id:obj.id+num});	
	this.insertAfter(obj, sizerCont);	
	var increaseBox = $('increaseBox'+num);
	var decreaseBox = $('decreaseBox'+num);	
	Event.observe(increaseBox, 'mouseover', function(){window.status='Increase the field size'; return true;});
	Event.observe(increaseBox, 'mouseout', function(){window.status='';return true;});
	Event.observe(decreaseBox, 'mouseover', function(){window.status='Decrease the field size'; return true;});
	Event.observe(decreaseBox, 'mouseout', function(){window.status='';return true;});
	
	if(typeof(fx) == 'undefined'){fx = false;}
	if(!fx){
		var remHeight = {
		init : function(obj){
			this.el = obj;
			this.height = this.el.offsetHeight; 
			this.el.style.height = this.height+'px';
			return this;
		},
		resize : function(size){
		this.height = this.el.offsetHeight; 
		var calcHeight = (this.height + size);
		if(calcHeight < 60 || calcHeight > 300){return;}
		this.el.style.height = calcHeight+'px';
		}
	}.init(obj);
		} else {
		var remHeight = new fx.RememberHeight(obj, 365, {duration: 400});	
		}
			Event.observe(increaseBox, 'click', function(){
									remHeight.resize(100);
														 })
			Event.observe(decreaseBox, 'click', function(){
									if(remHeight.el.offsetHeight < 60){return;}
									remHeight.resize(-100);
														 })
			
	},
	insertAfter : function(referenceNode, node){
		referenceNode = $(referenceNode);
		referenceNode.parentNode.insertBefore(node, referenceNode.nextSibling);
		}
	
};	

var addOptions = {
		optField : Object,
		optGroup : Object,
		fieldCount : Number,
		optFields : Object,
	init: function(){
		
		if($('option1')){
			this.optField = $('option1');
			this.optGroup = this.optField.parentNode;
			this.fieldCount = this.optGroup.getElementsByTagName('input').length;
			this.addText();
			}
		
		},
	addText: function(){
		domEl('a', '+ Add another option', {style : 'margin:0.3em;', href : 'javascript:;', id : 'addLink'}, this.optGroup);
		domEl('a', '- Remove option', {style : 'margin:0.3em', href : 'javascript:;', id : 'removeLink'}, this.optGroup);
		domEl('a', 'Clear options', {style : 'margin:0.3em', href : 'javascript:;', id : 'resetLink'}, this.optGroup);
		Event.observe($('addLink'), 'mouseover', function(){window.status='Add another option'; return true;});
		Event.observe($('addLink'), 'mouseout', function(){window.status='';return true;});
		Event.observe($('removeLink'), 'mouseover', function(){window.status='Remove option'; return true;});
		Event.observe($('removeLink'), 'mouseout', function(){window.status='';return true;});
		Event.observe($('resetLink'), 'mouseover', function(){window.status='Clear options'; return true;});
		Event.observe($('resetLink'), 'mouseout', function(){window.status='';return true;});
		addEvent($('addLink'), 'click', this.addField);	
		addEvent($('removeLink'), 'click', this.removeFields);	
		addEvent($('resetLink'), 'click', this.resetFields);	
		},
	addField : function(){
		var clear = document.createElement('br');
		var divGroup = document.createElement('div');
		var label = document.createElement('label');
		var fieldCount = addOptions.countFields();
		fieldCount = fieldCount+1;
		var labelT = document.createTextNode('Option'+fieldCount);
		var optID = 'option'+fieldCount;
		label.setAttribute('for', optID);
		label.appendChild(labelT);
		
		divGroup.id = optID+'Group';
		
		var field = document.createElement('input');
		field.id = optID;
		field.setAttribute('id', optID);
		field.setAttribute('name', 'extraoptions[]');
		field.className = 'text';
		
		divGroup.appendChild(label);
		divGroup.appendChild(field);
		divGroup.appendChild(clear);
		addOptions.optGroup.insertBefore(divGroup,$('addLink'));
		},
	resetFields : function(){
		var resetConf = confirm('Are you sure you want to delete all of your options?');
		
		if(resetConf){
			var divs = addOptions.optGroup.getElementsByTagName('div');
			divs.length.times(function(n){
										 addOptions.optGroup.removeChild(divs[0]);
										 });
			$('option1').value = '';
		}
	},
	countFields : function(){
		this.Fields = this.optGroup.getElementsByTagName('input');
		return this.fieldCount = this.Fields.length;
	},
	removeFields : function(){
			divs = $A(addOptions.optGroup.getElementsByTagName('div')).last();
			if(divs){
				addOptions.optGroup.removeChild(divs);
				}
			
	}
	
};

validate = {
	init : function(){
		var theform = $('post');
		if(theform){
			Event.observe(theform, 'submit', this.validateFields);
		}
		
	},
	validateFields : function(e){
		if($('bla..blal...lpassword') && !$('bla..blal...edit_user')){
			if($F('bla..blal...username') == '' || $F('bla..blal...password') == ''){
			alert('Please make sure that you\'ve entered the username and password');
			Event.stopObserving($('post'), 'submit', makeAlert);
			return window.event ? event.returnValue = false : e.preventDefault();
			}
		}
		
		
		}
	
	};
	
var createFooter = {
	init : function(){
		this.mainContainer = $('mainContainer');
		if(this.mainContainer){
			this.createElements();
			}
		},
	createElements : function(){
		domEl('div', '', {id : 'footerBottom'}, this.mainContainer);
		$('footerBottom').appendChild($('footer'))
		}
	};
	
var hiForm = {
	init : function(){
		var inputs = document.getElementsByTagName('input');
		var textareas = document.getElementsByTagName('textarea');
		for(var i=0; i<inputs.length; i++){
			addEvent(inputs[i], 'focus', this.hiLite);
			addEvent(inputs[i], 'blur', this.hiLite);
			}
		for(var i=0; i<textareas.length; i++){
		addEvent(textareas[i], 'focus', this.hiLite);
		addEvent(textareas[i], 'blur', this.hiLite);
		}
		},
	hiLite : function(){
		var labels = document.getElementsByTagName('label');
		for(var i=0; i<labels.length; i++){
			if(labels[i].getAttribute('for') == this.id || labels[i].getAttribute('htmlfor') == this.id){					
					if(this.type !== 'submit'){
					if(this.getAttribute('lang') == 'hilited'){
					this.style.border = '';
					labels[i].style.color = '';
					this.setAttribute('lang', '');
					} else {
					this.style.border = '1px solid #ABFFEE';
					labels[i].style.color = '#6B8CC0';
					this.setAttribute('lang', 'hilited');
						}
					}
				}
			}
		}
	};
	
var markDelete = {
	boxes : Array,
	init : function(){
		this.boxes = $A(document.getElementsByClassName('xtraImgDelete',$('extraImages')));
		this.boxes.each(function(i){
								 
			addEvent(i,'click', function(){
										 var fade = new fx.Opacity(i.parentNode);
										 markDelete.mark(i, fade);
										 });
			});
		},
	mark : function(i, fade){
			if(i.checked){
				fade.custom(1, 0.5);
				} else{
					fade.custom(0.5, 1);
					}
			
		}
	};

var addImgFields = {
		upField : Object,
		upGroup : Object,
		fieldCount : Number,
		upFields : Object,
		uploadType : String,
	init: function(){
		if($('additional0')){
			this.uploadType = 'text';
			this.upField = $('additional0');
			this.upGroup = this.upField.parentNode;
			this.fieldCount = this.upGroup.getElementsByTagName('input').length;
			this.addText();
			}
		

		},
	addText: function(){
		domEl('a', '+ Add field', {style : 'margin:0.8em;', href : 'javascript:;', id : 'addUpload'}, this.upGroup);
		domEl('a', '- Remove field', {style : 'margin:0.8em', href : 'javascript:;', id : 'removeUpload'}, this.upGroup);
		//domEl('a', 'Clear upload fields', {style : 'margin:0.3em', href : 'javascript:;', id : 'resetUpload'}, this.upGroup);
		Event.observe($('addUpload'), 'mouseover', function(){window.status='Add field'; return true;});
		Event.observe($('addUpload'), 'mouseout', function(){window.status='';return true;});
		Event.observe($('removeUpload'), 'mouseover', function(){window.status='Remove field'; return true;});
		Event.observe($('removeUpload'), 'mouseout', function(){window.status='';return true;});
		//Event.observe($('resetUpload'), 'mouseover', function(){window.status='Clear fields'; return true;});
		//Event.observe($('resetUpload'), 'mouseout', function(){window.status='';return true;});
		addEvent($('addUpload'), 'click', this.addField);	
		addEvent($('removeUpload'), 'click', this.removeFields);	
		//addEvent($('resetUpload'), 'click', this.resetFields);	
		},
	addField : function(){
		var clear = document.createElement('br');
		var divGroup = document.createElement('div');
		var label = document.createElement('label');
		var fieldCount = addImgFields.countFields();
		fieldCount = fieldCount;
		var labelText = (addImgFields.uploadType == 'images') ? 'Image ' : 'Option ';
		var labelT = document.createTextNode(labelText+fieldCount);
		var optID = 'additional'+fieldCount;
		label.setAttribute('for', optID);
		label.appendChild(labelT);
		
		divGroup.id = optID+'Group';
		divGroup.className = 'uploadGroup';
		
		var field = domEl('input', '', {id:optID,name:'multiple['+fieldCount+']','class':'formfields text','maxlength':'100', type: 'text', size: 50});
		//var captionLabel = domEl('label', 'Caption Tambahan '+fieldCount, {'for':'caption'+fieldCount});
		//var caption = domEl('input', '', {id:'caption'+fieldCount,name:'caption['+optID+']','class':'caption'});
		//var caption = domEl('input', '', {name:'counting',type: 'hidden',value: '+addImgFields.countFields()+'});
		divGroup.appendChild(label);
		divGroup.appendChild(field);
		divGroup.appendChild(clear);
		
		//divGroup.appendChild(captionLabel);
		//divGroup.appendChild(caption);
		//divGroup.appendChild(clear);
		addImgFields.upGroup.insertBefore(divGroup,$('addUpload'));
		},
	resetFields : function(){
		var resetConf = confirm('Are you sure you want to delete all of your upload fields?');
		
		if(resetConf){
			var divs = addImgFields.upGroup.getElementsByTagName('div');
			var divs = document.getElementsByClassName('uploadGroup');
			divs.length.times(function(n){
									   if(divs.length){
										   addImgFields.upGroup.removeChild(divs[n]);
									   }
										 });
			$('additional0').value = '';
			//$('caption1').value = '';
		}
	},
	countFields : function(){
		this.Fields = this.upGroup.getElementsByTagName('input');
		return this.fieldCount = this.Fields.length;
	},
	removeFields : function(){
			divs = $A(addImgFields.upGroup.getElementsByTagName('div')).last();
			if(divs){
				addImgFields.upGroup.removeChild(divs);
				}
			
	}
	
};

var addImgFieldsN = {
		upFieldN : Object,
		upGroupN : Object,
		fieldCountN : Number,
		upFieldsN : Object,
		uploadTypeN : String,
	init: function(){
		if($('additional2')){
			this.uploadTypeN = 'file';
			this.upFieldN = $('additional2');
			this.upGroupN = this.upFieldN.parentNode;
			this.fieldCountN = this.upGroupN.getElementsByTagName('input').length;
			this.addTextN();
			}
		

		},
	addTextN: function(){
		domEl('a', '+ Add field', {style : 'margin:0.8em;', href : 'javascript:;', id : 'addUploadN'}, this.upGroupN);
		domEl('a', '- Remove field', {style : 'margin:0.8em', href : 'javascript:;', id : 'removeUploadN'}, this.upGroupN);
		//domEl('a', 'Clear upload fields', {style : 'margin:0.3em', href : 'javascript:;', id : 'resetUpload'}, this.upGroup);
		Event.observe($('addUploadN'), 'mouseover', function(){window.status='Add field'; return true;});
		Event.observe($('addUploadN'), 'mouseout', function(){window.status='';return true;});
		Event.observe($('removeUploadN'), 'mouseover', function(){window.status='Remove field'; return true;});
		Event.observe($('removeUploadN'), 'mouseout', function(){window.status='';return true;});
		//Event.observe($('resetUpload'), 'mouseover', function(){window.status='Clear fields'; return true;});
		//Event.observe($('resetUpload'), 'mouseout', function(){window.status='';return true;});
		addEvent($('addUploadN'), 'click', this.addFieldN);	
		addEvent($('removeUploadN'), 'click', this.removeFieldsN);	
		//addEvent($('resetUpload'), 'click', this.resetFields);	
		},
	addFieldN : function(){
		var clear = document.createElement('br');
		var divGroup = document.createElement('div');
		var label = document.createElement('label');
		var fieldCountN = addImgFieldsN.countFields();
		fieldCountN = fieldCountN;
		var labelText = (addImgFieldsN.uploadTypeN == 'images') ? 'Image ' : 'Halaman ';
		var labelT = document.createTextNode(labelText+fieldCountN);
		var optID = 'additional2'+fieldCountN;
		label.setAttribute('for', optID);
		label.appendChild(labelT);
		
		divGroup.id = optID+'Group';
		divGroup.className = 'uploadGroup';
		
		var field = domEl('input', '', {id:optID,name:'multipln['+fieldCountN+']','class':'formfields file','maxlength':'100', type: 'file', size: 50});
		//var captionLabel = domEl('label', 'Caption Tambahan '+fieldCount, {'for':'caption'+fieldCount});
		//var caption = domEl('input', '', {id:'caption'+fieldCount,name:'caption['+optID+']','class':'caption'});
		//var caption = domEl('input', '', {name:'counting',type: 'hidden',value: '+addImgFields.countFields()+'});
		divGroup.appendChild(label);
		divGroup.appendChild(field);
		divGroup.appendChild(clear);
		
		//divGroup.appendChild(captionLabel);
		//divGroup.appendChild(caption);
		//divGroup.appendChild(clear);
		addImgFieldsN.upGroupN.insertBefore(divGroup,$('addUploadN'));
		},
	resetFields : function(){
		var resetConf = confirm('Are you sure you want to delete all of your upload fields?');
		
		if(resetConf){
			var divs = addImgFieldsN.upGroupN.getElementsByTagName('div');
			var divs = document.getElementsByClassName('uploadGroup');
			divs.length.times(function(n){
									   if(divs.length){
										   addImgFieldsN.upGroupN.removeChild(divs[n]);
									   }
										 });
			$('additional2').value = '';
			//$('caption1').value = '';
		}
	},
	countFields : function(){
		this.Fields = this.upGroupN.getElementsByTagName('input');
		return this.fieldCountN = this.Fields.length;
	},
	removeFieldsN : function(){
			divs = $A(addImgFieldsN.upGroupN.getElementsByTagName('div')).last();
			if(divs){
				addImgFieldsN.upGroupN.removeChild(divs);
				}
			
	}
	
};


var addImgFieldsEn = {
		upFieldEn : Object,
		upGroupEn : Object,
		fieldCountEn : Number,
		upFieldsEn : Object,
		uploadTypeEn : String,
	init: function(){
		if($('additional1')){
			this.uploadTypeEn = 'text';
			this.upFieldEn = $('additional1');
			this.upGroupEn = this.upFieldEn.parentNode;
			this.fieldCountEn = this.upGroupEn.getElementsByTagName('input').length;
			this.addTextEn();
			}
		

		},
	addTextEn: function(){
		domEl('a', '+ Add field', {style : 'margin:0.8em;', href : 'javascript:;', id : 'addUploadEn'}, this.upGroupEn);
		domEl('a', '- Remove field', {style : 'margin:0.8em', href : 'javascript:;', id : 'removeUploadEn'}, this.upGroupEn);
		//domEl('a', 'Clear upload fields', {style : 'margin:0.3em', href : 'javascript:;', id : 'resetUpload'}, this.upGroup);
		Event.observe($('addUploadEn'), 'mouseover', function(){window.status='Add field'; return true;});
		Event.observe($('addUploadEn'), 'mouseout', function(){window.status='';return true;});
		Event.observe($('removeUploadEn'), 'mouseover', function(){window.status='Remove field'; return true;});
		Event.observe($('removeUploadEn'), 'mouseout', function(){window.status='';return true;});
		//Event.observe($('resetUpload'), 'mouseover', function(){window.status='Clear fields'; return true;});
		//Event.observe($('resetUpload'), 'mouseout', function(){window.status='';return true;});
		addEvent($('addUploadEn'), 'click', this.addFieldEn);	
		addEvent($('removeUploadEn'), 'click', this.removeFieldsEn);	
		//addEvent($('resetUpload'), 'click', this.resetFields);	
		},
	addFieldEn : function(){
		var clear = document.createElement('br');
		var divGroup = document.createElement('div');
		var label = document.createElement('label');
		var fieldCountEn = addImgFieldsEn.countFields();
		fieldCountEn = fieldCountEn;
		var labelText = (addImgFieldsEn.uploadTypeEn == 'images') ? 'Image ' : 'Option ';
		var labelT = document.createTextNode(labelText+fieldCountEn);
		var optID = 'additional'+fieldCountEn;
		label.setAttribute('for', optID);
		label.appendChild(labelT);
		
		divGroup.id = optID+'Group';
		divGroup.className = 'uploadGroup';
		
		var field = domEl('input', '', {id:optID,name:'multipleen['+fieldCountEn+']','class':'formfields text','maxlength':'100', type: 'text', size: 50});
		//var captionLabel = domEl('label', 'Caption Tambahan '+fieldCount, {'for':'caption'+fieldCount});
		//var caption = domEl('input', '', {id:'caption'+fieldCount,name:'caption['+optID+']','class':'caption'});
		//var caption = domEl('input', '', {name:'counting',type: 'hidden',value: '+addImgFields.countFields()+'});
		divGroup.appendChild(label);
		divGroup.appendChild(field);
		divGroup.appendChild(clear);
		
		//divGroup.appendChild(captionLabel);
		//divGroup.appendChild(caption);
		//divGroup.appendChild(clear);
		addImgFieldsEn.upGroupEn.insertBefore(divGroup,$('addUploadEn'));
		},
	resetFields : function(){
		var resetConf = confirm('Are you sure you want to delete all of your upload fields?');
		
		if(resetConf){
			var divs = addImgFieldsEn.upGroup.getElementsByTagName('div');
			var divs = document.getElementsByClassName('uploadGroup');
			divs.length.times(function(n){
									   if(divs.length){
										   addImgFieldsEn.upGroupEn.removeChild(divs[n]);
									   }
										 });
			$('additional1').value = '';
			//$('caption1').value = '';
		}
	},
	countFields : function(){
		this.Fields = this.upGroupEn.getElementsByTagName('input');
		return this.fieldCountEn = this.Fields.length;
	},
	removeFieldsEn : function(){
			divs = $A(addImgFieldsEn.upGroupEn.getElementsByTagName('div')).last();
			if(divs){
				addImgFieldsEn.upGroupEn.removeChild(divs);
				}
			
	}
	
};




var Bookmark = {
	init : function(){
		if(!$('content') || $('content').className != 'login' || !$('forgotLink')) {return;}
		if (!window.external && !window.sidebar) { return;}
		var bookmarkText = (window.sidebar) ? 'Bookmark me' : 'Add me to your Favorites';
		var bookmarkLink = domEl('a', bookmarkText, {href:'javascript:;', id: 'bookmarkLink'});
		insertAfter($('forgotLink').parentNode, bookmarkLink, $('forgotLink'));
		Event.observe(bookmarkLink, 'mouseover', function(){window.status=bookmarkText; return true;});
		Event.observe(bookmarkLink, 'mouseout', function(){window.status='';return true;});
		Event.observe($('bookmarkLink'), 'click', this.run);
		},
	run : function(){
			var title = document.title;   
			var url = window.location.href;  

			if (window.sidebar) { 
			//Firefox	
				window.sidebar.addPanel(title, url,"");	
			} else if( window.external ) { 
			// IE
				window.external.AddFavorite( url, title); 
			}
		}
	};

var page = {
	init:function(){
	var hh = new HelpHover();
	hh.init();	
	markDelete.init();
	addImgFields.init();
	addImgFieldsEn.init();
	addImgFieldsN.init();
	accordion.init();
	navigation.init();
	createFooter.init();
	setChecks.init();
	//autoThumb.init();
	//confirmEula();
	//hiliteInput.init();
	//reorder.init();
	appendInputTypeClasses();
	//confirmUninstall.init();
	//Bookmark.init();
	toggleBox.init();

	//addCustomFields.init();
	
	if($('toggleBox')){
		addEvent($('toggleBox'),'click',function(){
			toggleBoxes($('toggleBox'));
		});
		}
	if($('dateformat')){
		setDateFormat();
		dInit();
	}
	if($('descr') && !checkIt('safari')){
		var oFCKeditor = new FCKeditor( 'descr' ) ;
		oFCKeditor.BasePath = 'thinkbright_editor/';
		oFCKeditor.ReplaceTextarea() ;
	}
	if($('descren') && !checkIt('safari')){
		var oFCKeditor = new FCKeditor( 'descren' ) ;
		oFCKeditor.BasePath = 'thinkbright_editor/';
		oFCKeditor.ReplaceTextarea() ;
	}	
	if($('descren1') && !checkIt('safari')){
		var oFCKeditor = new FCKeditor( 'descren1' ) ;
		oFCKeditor.BasePath = 'thinkbright_editor/';
		oFCKeditor.ReplaceTextarea() ;
	}
	if($('descrprb') && !checkIt('safari')){
		var oFCKeditor = new FCKeditor( 'descrprb' ) ;
		oFCKeditor.BasePath = 'thinkbright_editor/';
		oFCKeditor.ReplaceTextarea() ;
	}
	if($('message') && !checkIt('safari')){
		var oFCKeditor = new FCKeditor( 'message' ) ;
		oFCKeditor.BasePath = 'thinkbright_editor/';
		oFCKeditor.ReplaceTextarea() ;
	}
	if($('messageen') && !checkIt('safari')){
		var oFCKeditor = new FCKeditor( 'messageen' ) ;
		oFCKeditor.BasePath = 'thinkbright_editor/';
		oFCKeditor.ReplaceTextarea() ;
	}
	if($('timeoffset') && $F('timeoffset') == ''){
		$('timeoffset').value = theZone();
		}
			//preloadImgCache();
			resizeEditor.init();			
			resizeEditorEn.init();			
			resizeEditorEn1.init();
			resizeEditorEnPrb.init();
			addAlatFields.init();
			
			// make alert windows load
			loadAlert();
			stripe('stripeTable');
			/*
			checkAll($('adminCheck'));
			disableBoxes();
			addOptions.init();
			addEvent($('use_default_thumbsize'),'click',function(){
				toggleScaleLink();
			});
			*/
		
		if(window.expanse){
			expanse();
			}
		}
	
	};	
	
Event.onDOMReady(page.init);
