<!--
var base_url = "http://adult4.net/";
-->

function addEvent( obj, type, fn )
{
	if (obj.addEventListener)
		obj.addEventListener( type, fn, false );
	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] );
	}
}

function removeEvent( obj, type, fn )
{
	if (obj.removeEventListener)
		obj.removeEventListener( type, fn, false );
	else if (obj.detachEvent)
	{
		obj.detachEvent( "on"+type, obj[type+fn] );
		obj[type+fn] = null;
		obj["e"+type+fn] = null;
	}
}

/* window 'load' attachment */
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	}
	else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

/* insert an element after a particular node */
function insertAfter(parent, node, referenceNode) {
	parent.insertBefore(node, referenceNode.nextSibling);
}

/* Array prototype, matches value in array: returns bool */
Array.prototype.inArray = function (value) {
	var i;
	for (i=0; i < this.length; i++) {
		if (this[i] === value) {
			return true;
		}
	}
	return false;
};

/* get, set, and delete cookies */
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";
}

/* quick getElement reference */
function $() {
	var elements = new Array();
	for (var i = 0; i < arguments.length; i++) {
		var element = arguments[i];
		if (typeof element == 'string')
			element = document.getElementById(element);
		if (arguments.length == 1)
			return element;
		elements.push(element);
	}
	return elements;
}

var is_ie = document.all;
var timer = false;
var icons_url = 'templates/whitegray/images/icons/';
function getObj(sId){return document.getElementById(sId);}
function checkIt(b,c){if(b){b.checked=!c;b.click();b.checked=c;}}
function showIt(sId,v){var x=getObj(sId);if(x)x.style.display=(v?'block':'none');}
function togView(sId){var el=getObj(sId);if(el){el.style.display=el.style.display=='none'?'':'none';}}
function checkAllBoxes(formObj,fieldName,chkVal){if(!formObj)return false;var checkBoxes=formObj.getElementsByTagName('input');for(var i=0;i<checkBoxes.length;i++){if(checkBoxes[i].name==fieldName&&!checkBoxes[i].disabled){checkBoxes[i].checked=chkVal;}}}
function countCheckedBoxes(formObj,fieldName){if(!formObj)return false;var checkBoxes=formObj.getElementsByTagName('input');var checkedBoxes=0;for(var i=0;i<checkBoxes.length;i++){checkedBoxes+=(checkBoxes[i].name==fieldName&&!checkBoxes[i].disabled&&checkBoxes[i].checked)?1:0;}return checkedBoxes;}
function pInt(oF){if(oF){oF.value=parseInt(oF.value);if(oF.value=='NaN'){oF.value=0;}}}
function pop(sURL){return!window.open(sURL);}
function go(url){if(url.substr(0,7)!='http://')url=base_url+url;window.location=url;return false;}
function getXMLHttpObject(){return (typeof XMLHttpRequest!='undefined')?new XMLHttpRequest():(typeof ActiveXObject!='undefined'?new ActiveXObject('Microsoft.XMLHTTP'):false);}
function xmlhttpGet(sURL,process,xml){sURL+=('&'+(Math.floor(Math.random()*10000000))); var xmlhttp=getXMLHttpObject();if(xmlhttp){xmlhttp.onreadystatechange=function(){if(xmlhttp.readyState==4){if(xmlhttp.status==200){process(xml?xmlhttp.responseXML:xmlhttp.responseText);}else{alert('Request Failed: '+xmlhttp.status);}}};xmlhttp.open('GET',sURL,true);xmlhttp.send(null);}else go(sURL);}
function xmlhttpPost(aPostData,sURL,process){sURL+=('&'+(Math.floor(Math.random()*10000000))); var xmlhttp=getXMLHttpObject();if(xmlhttp){var sPostData = '';for(var f in aPostData){sPostData+=((sPostData.length>0?'&':'')+f+'='+encodeURIComponent(aPostData[f]));}xmlhttp.onreadystatechange=function(){if(xmlhttp.readyState==4){if(xmlhttp.status==200){process(xmlhttp.responseText);}else{alert('Request Failed');}}};xmlhttp.open('POST',sURL,true);xmlhttp.setRequestHeader('Content-type','application/x-www-form-urlencoded; charset=UTF-8');xmlhttp.send(sPostData);}else alert('Your browser does not support XMLHttp. If you are on Internet Explorer, enable ActiveX.');}
function htmlspecialchars(s){var t={'&':'&amp;','"':'&quot;',"'":'&#039;','<':'&lt;','>':'&gt;'};for(var k in t){rx=new RegExp(k,'g');s=s.replace(rx,t[k]);}return s;}
function addslashes(s){s=s.replace(/'/gi,"&#039;");s=s.replace(/"/gi,"&quot;");return s;}
function alternateRowColor(obj,el,c1,c2){if(obj){var els=obj.getElementsByTagName(el);var j=0;for(var i=0;i<els.length;i++)if(!els[i].getAttribute('skip_alternate')){els[i].style.backgroundColor=(j&1?c2:c1);j++;}}}
function basename(s){var p=-1;for(var i=0;i<s.length;i++){if( s.charAt(i)=='\\'||s.charAt(i)=='/')p=i;}if(p<0)return s;return s.substr(p+1,s.length-p);}
function dirname(s){var p=-1;for(var i=0;i<s.length;i++){if( s.charAt(i)=='\\'||s.charAt(i)=='/')p=i;}if(p<0)return s;return s.substr(0,p+1);}
function togImage(im,n){if(!im)return false;var alt=im.getAttribute('alternateImage');if(!alt)alt=dirname(im.src)+'/'+n;var cur=im.src;im.src=alt;im.setAttribute('alternateImage',cur);}
function get_extension(n){n=n.substr(n.lastIndexOf('.')+1);return n.toLowerCase();}
function str_slice(s,l){if(s.length>l)return s.substr(0,l/2)+'...'+s.substr(s.length-(l/2));return s;}
function setStyles(obj,styles){if(!obj)return false;for(var k in styles)obj.style[k]=styles[k];}
function Timer(){this.t=false;}
Timer.prototype.start=function(f,ms){this.t=window.setTimeout(f,ms);}
Timer.prototype.stop=function(){if(this.t)window.clearTimeout(this.t);}
function ViewJs(idecko){
el=document.getElementById(idecko).style;
el.display=(el.display == 'block')?'none':'block';
}
function highlight(field) {
        field.focus();
        field.select();
}
function Bubble(t,o,s)
{
	this.t = t;
	this.o = o;
	this.b = false;
	this.s = typeof s != 'undefined' ? s : 0;
}

Bubble.prototype.display = function (s)
{
	if ( this.b )
	{
		this.b.innerHTML = s;
		this.b.style.marginTop =  -(this.b.offsetHeight+this.o+4)+'px';
		return true;
	}
	this.b = document.createElement ( 'span' );
	if(!this.b)return false;
	obj=this;
	this.b.onclick=function(){obj.hide();}

	var styles =
	{
		'backgroundColor' : '#FBFFDF',
		'border' : '1px solid #505050',
		'padding' : '5px',
		'position' : 'absolute',
		'lineHeight' : '1.4em',
		'MozBorderRadius' : '4px'
	};
	if ( this.s > 0 ) styles['width'] = this.s + 'px';

	setStyles ( this.b, styles );
	this.b.innerHTML = s;
	this.t.parentNode.insertBefore(this.b,this.t);
	this.b.style.marginTop =  -(this.b.clientHeight+this.o+4)+'px';
}

Bubble.prototype.hide = function()
{
	if(!this.b)return true;
	this.b.style.display='none';
	//deleteNode(this.b);
	this.b=false;
}

function get_icon ( extension )
{
    var icons = {
		'default':'file.gif',
		// images
		'jpg'	: 'images.gif',
		'jpeg'	: 'images.gif',
		'png'	: 'png.gif',
		'gif'	: 'gif.gif',
		// media
		'avi'	: 'video.gif',
		'wmv'	: 'video.gif',
		'mpeg'	: 'video2.gif',
		'mpg'	: 'video2.gif',
		'mov'	: 'quicktime.gif',
		'mp3'	: 'mp3.gif',
		// Archives
		'zip'	: 'zip.gif',
		'rar'	: 'zip.gif',
		'tar'	: 'zip.gif',
		// documents
		'pdf'	: 'acrobat.gif',
		'ppt'	: 'powerpoint.gif',
		'txt'	: 'text.gif',
		'doc'	: 'word.gif',
		'xls'	: 'excel.gif'
	}
    return icons[extension] ? icons[extension] : icons['default'];
}

function adjustRatio ( event, current, target, ratio, maxVal )
{
	if ( current.value != '' ) current.value = parseInt ( current.value );
	if ( current.value == 'NaN' ) current.value = 0;
	if ( current.value > maxVal ) current.value = maxVal;
	if ( current.value < 0 ) current.value = 0;
	target.value = Math.ceil ( current.value / ratio );
}

function copyTextArea ( id )
{
	var field = getObj ( id );
	if ( field )
	{
		if ( is_ie ) field.createTextRange ( ).execCommand ( 'copy' );
		else alert ( 'Sorry, this feature is only enabled for Internet Explorer at the moment. Select the text and press Ctrl+C to copy and Ctrl+V to paste.' );
	}
}

function help ( str )
{
	var x = getObj ( 'message_content' );
	if(!x)return false;
	x.innerHTML = str.replace(/\n/g,'<br />');
	showIt ( 'message', true );
}

function uplAlert ( str )
{
	var alert_box = getObj ( 'alert_box' );
	if ( !alert_box ) var alert_box = document.createElement ( 'div' );
	alert_box.id = 'alert_box';
	alert_box.innerHTML = '<h1>Oops!</h1>' +
	'<p><img src="templates/whitegray/images/exclamation.gif" alt="" class="img1" /> ' + str + '</p>';
	document.body.appendChild ( alert_box );
}


function deleteNode ( oNode )
{
	return oNode.parentNode.removeChild ( oNode );
}

function togFolderPublic(oImage,sAltImage,togURL)
{
	if ( togURL.substr ( 0, 7 ) != 'http://' )
	{
		togURL = base_url + togURL;
	}
	var func = function ( result )
	{
		if ( result == 'OK' )
		{
			togImage ( oImage, sAltImage );
		}
	}
	xmlhttpGet(togURL,func);
}
