ie=false;
nn=false;
if(document.all) ie = true;
if(document.layers) nn = true;

function hideByID(id){
	var triger;	
	triger = document.getElementById(id).style.display;
	if(triger == 'block'){
		document.getElementById(id).style.display = 'none';
	}else{
		document.getElementById(id).style.display = 'block';
	}
};

function anonymousAccess()
{
	if(document.logon.user.value == 'anonymous')
	{
	  document.logon.user.value = '';
	  document.logon.user.focus();
	} else {
	  document.logon.user.value = 'anonymous';
	  document.logon.password.focus();
	}
};

function submitForm(action, file, file2)
{
  document.actionform.action.value = action;
  document.actionform.file.value = file;
  document.actionform.file2.value = file2;
  document.actionform.submit();
};

function createDirectory(directory)
{
  if(directory)
  {submitForm("createdir", directory);}
  else
  {alert('Enter a directory name first');}
};

function changeMode(mode)
{
  document.actionform.mode.value = mode;
  document.putForm.mode.value = mode;
  mode==1?document.currentMode.showmode.value = "FTP_BINARY":document.currentMode.showmode.value = "FTP_ASCII";
};

function renameFile(oldName)
{
  newName = window.prompt("Enter the new name for "+oldName,""+oldName);
  if(newName)
    {submitForm("rename", oldName, newName);}
    else
    {alert('Please enter a new name');}
};

function Confirmation(URL, DIR)
{
  if (confirm("Really delete this "+DIR+"?\n"))
  {location = String(URL);}
  else
  {
	  //Do nothing
  }
};
function ConfirmationAjax(URL, DIR)
{
	if (confirm(DIR+"\n")){
		ajaxpack.getAjaxRequest(URL, "", processGetPost, "txt");
	}
	else{
	  //Do nothing
  }
};
function imgTextAjax(imgId)
{
	var imgDes = document.getElementById(("imgText"+imgId)).innerHTML;
	imgDes = imgDes.replace("<br>","");
	imgDes = imgDes.replace("<br>","");
	var newText = prompt("Edit text", imgDes);
	if (newText){
		postStr = "imgId="+imgId+"&imgText=" + encodeURIComponent(newText);
		ajaxpack.getAjaxRequest("/webinac/images.php", postStr, callbackImgText, "txt");
	}
	else{
	  //Do nothing
  }
};
function imgRotateAjax(imgId,degrees)
{
	postStr = "imgId="+imgId+"&rotate=" + encodeURIComponent(degrees);
	ajaxpack.getAjaxRequest("/webinac/images.php", postStr, callbackImgRotate, "txt");
};

function ConfirmationUnzip(URL)
{
  if (confirm("Unzip File in the current dir ?\n"))
  {location = String(URL);}
};




function setCookie(name, value, expires, domain, secure)
{
 var curCookie = name + "=" + escape(value) +
   ((expires) ? "; expires=" + expires.toGMTString() : "") +
   "; path= / "+
   ((domain) ? "; domain=" + domain : "") +
   ((secure) ? "; secure" : "");
   
   //var curCookie = new Array();
   //curCookie[name]= value;

 document.cookie = curCookie;
};

function Set_Cookie( name, value, expires, path, domain, secure ) 
{
	// set time, it's in milliseconds
	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" : "" );
};
// this function gets the cookie, if it exists
function Get_Cookie( 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 ) );
};
// this deletes the cookie when called
function Delete_Cookie( name, path, domain ) {
if ( Get_Cookie( name ) ) document.cookie = name + "=" +
( ( path ) ? ";path=" + path : "") +
( ( domain ) ? ";domain=" + domain : "" ) +
";expires=Thu, 01-Jan-1970 00:00:01 GMT";
};
oldColor ="";
function changeBG(obj,newColor){
	var curColor = obj.style.backgroundColor;
	if (newColor == ""){
		obj.style.backgroundColor = this.oldColor;
	}else{
		this.oldColor = obj.style.backgroundColor;
		obj.style.backgroundColor = newColor;
	}
	
}
function Querystring(qs) { // optionally pass a querystring to parse
	this.params = new Object()
	this.get=Querystring_get
	
	if (qs == null)
		qs=location.search.substring(1,location.search.length)

	if (qs.length == 0) return
	qs = qs.replace(/\+/g, ' ')
	var args = qs.split('&') // parse out name/value pairs separated via &
// split out each name=value pair
	for (var i=0;i<args.length;i++) {
		var value;
		var pair = args[i].split('=')
		var name = unescape(pair[0])

		if (pair.length == 2)
			value = unescape(pair[1])
		else
			value = name
		
		this.params[name] = value
	}
}
function Querystring_get(key, default_) {
	// This silly looking line changes UNDEFINED to NULL
	if (default_ == null) default_ = null;
	
	var value=this.params[key]
	if (value==null) value=default_;
	
	return value
}