/**
##
#	Project: PHPDisk Personal Edition
#	This is NOT a freeware, use is subject to license terms.
#
#	Site: http://www.phpdisk.com
#
#	$Id: common.js 146 2009-06-22 15:52:29Z along $
#
#	Copyright (C) 2008-2009 PHPDisk Team. All Rights Reserved.
#
##
*/

String.prototype.strtrim = function(){
	return this.replace(/(^\s*)|(\s*$)/g, "");
}

function g(id){
	return document.getElementById(id);	
}
function go(url){
	document.location.href = url;
}

function resize_textarea(obj,type) {
	if(type == 'plus'){
		var newheight = parseInt(g(obj).style.height, 10) + 50;
		g(obj).style.height = newheight + 'px';
	}else{
		var newheight = parseInt(g(obj).style.height, 10) - 50;
		if(newheight > 0) {
			g(obj).style.height = newheight + 'px';
		}
	}
}

function createHttpRequest(){
	var xmlhttp;
	try{
		xmlhttp = new XMLHttpRequest();
		if(xmlhttp.overrideMimeType){
			xmlhttp.overrideMimeType('text/xml');	
		}	
	}catch(e){
		try{
			xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
		}catch(e){
			try{
				xmlhttp = new ActiveXObject('Msxml2.XMLHTTP');
			}catch(e){
				alert('Ajax error!');			
			}	
		}	
	}
	return xmlhttp;
}

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() : "" ) + 
		( ( 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";
}

var menuTimer = null;
function show_menu(obj1,obj2,state,location){ 
    var btn=g(obj1);
    var obj=g(obj2);
    var h=btn.offsetHeight;
    var w=btn.offsetWidth;
    var x=btn.offsetLeft;
    var y=btn.offsetTop;
    
    obj.onmouseover =function(){
        show_menu(obj1,obj2,'show',location);
    }
    obj.onmouseout =function(){
        show_menu(obj1,obj2,'hide',location);
    }
    
    while(btn=btn.offsetParent){y+=btn.offsetTop;x+=btn.offsetLeft;}
    
    var hh=obj.offsetHeight;
    var ww=obj.offsetWidth;
    var xx=obj.offsetLeft;
    var yy=obj.offsetTop;
    var obj2state=state.toLowerCase();
    var obj2location=location.toLowerCase();
    
    var showx,showy;

    if(obj2location=="left" || obj2location=="top" || obj2location=="right" || obj2location=="bottom"){
        if(obj2location=="left"){showx=x-ww;showy=y;}
        if(obj2location=="top"){showx=x;showy=y-hh;}
        if(obj2location=="right"){showx=x+w;showy=y;}
        if(obj2location=="bottom"){showx=x;showy=y+h;}
    }else{ 
        showx=xx;showy=yy;
    }
    obj.style.left=showx+"px";
    obj.style.top=showy+"px";
    if(state =="hide"){
        menuTimer =setTimeout("_hide_menu('"+ obj2 +"')", 1);
    }else{
        clearTimeout(menuTimer);
        obj.style.visibility ="visible";
    }
}
function _hide_menu(id){
    g(id).style.visibility ="hidden";
}
function show_thumb(id){
	var xmlhttp = createHttpRequest();
	xmlhttp.open("get","ajax.php?file_id="+id,true);
	xmlhttp.onreadystatechange = function(){
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
			g('thb_'+id).src = xmlhttp.responseText;
		}
	}
	xmlhttp.send(null);
}
function resize_img(imgID,w,h){
	if(g(imgID).width>w){
		g(imgID).width = w;
	}
	if(g(imgID).height>h){
		g(imgID).height = h;
	}
}
function display_box(id){
	g(id).style.display = (g(id).style.display =='none') ? '' : 'none';
}

function js_redirect(url){
	if(url == 'close'){
		self.parent.tb_remove();
	}else{
		setTimeout(function(){self.parent.tb_remove();},3000);
		self.parent.document.location.href = url;
	}
}
function f_folder_box(title,url){
	tb_showIframeBox(title,url,350,250);
	return false;
}
function f_upload_box(title,url){
	tb_showIframeBox(title,url,500,300);
	return false;
}
function f_confirm_box(title,url){
	tb_showIframeBox(title,url,350,150);
	return false;
}
