var varload='<table width="100%" height="100%"><tr><td valign="middle" align="center"><img src="design/ajaxloader.gif"></td></tr></table>';
var lastsubmenu=null;
var lastm=null;

function ajax(nurl,opt,ctr) {
	new Ajax('ajax.php?mod='+nurl, {
			method: 'get',
			data: opt,
			update: $(ctr),
			evalScripts: true
		}).request(opt);
}


function loadmenu(newmenu) {
	var win=$('content');
	win.innerHTML='<table height=100% width=100% border=0><tr><td valign=middle align=center><img src="pics/ajax.gif"></td></tr></table>';
	new Ajax(newmenu, {method: 'get',update: $('content')}).request();
}


function loadgallery() {
  var nowid=$('gido');
  var gn=nowid.value;
  loadmenu('mods/?m=gallery&gn='+gn);
}

function showpic(picnr) {
	var fade=$('fader');
	var zoom=$('zoomer');


	var fx = new Fx.Style(fade,'opacity', {duration:500, wait:false});
	var fx2 = new Fx.Style(zoom, 'opacity', {duration:200, wait:false});
	zoom.setOpacity(0);
	fade.setOpacity(0);
	fade.setStyle('display', 'block');
	fx.start(0,0.7).chain(function(){
		zoom.setStyle('display', 'block');
		fx2.start(0,1);
	});
}

function showcrew(newurl,h,w) {
	var fade=$('fader');
	var zoom=$('zoomer');

	var nw=-Math.floor(w/2);
	var nh=-Math.floor(h/2);

	var tw=Math.floor(screenw()/2);
	var th=Math.floor(screenh()/2)-12;


	var fx = new Fx.Style(fade,'opacity', {duration:500, wait:false});
	var fx2 = new Fx.Style(zoom, 'opacity', {duration:200, wait:false});
	zoom.setOpacity(0);
	fade.setOpacity(0);
	zoom.setStyle('height',h);
	zoom.setStyle('width',w);
	zoom.setStyle('margin-top',nh);
	zoom.setStyle('margin-left',nw);
	zoom.setStyle('top',th);
	zoom.setStyle('left',tw);
	
	fade.setStyle('display', 'block');
	fx.start(0,0.7).chain(function(){
		new Ajax(newurl, {
		method: 'get',
		update: $('zoomer'),
		evalScripts: true
		}).request();
	});
}

function changeadminmenu(newurl,w,h,opt) {
	var win=$('adminbox');
	var win2=$('admincontent');
	lastuser=null;
	if(opt==undefined) {
		opt='';
	}
	var nh=-Math.floor(h/2);
	var nw=-Math.floor(w/2);
	var fx = new Fx.Styles(win, {duration:500, wait:false});
	var fx2 = new Fx.Style(win2, 'opacity', {duration:200, wait:false});
	var currentTime = new Date()
	var fck=$('fck');
	hidecomm();
	if(fck!=null) {	
		fck.value=''; 
		FCKeditorAPI.GetInstance('fck').value='';
	}

  fx2.start(1,0).chain(function(){
		fx.start({ 'height': h,
							 'margin-left': nw,
							 'margin-top': nh,
						   'width' : w}).chain(function(){
						 		new Ajax(newurl, {
			method: 'get',
			data: opt,
			update: $('admincontent'),
			evalScripts: true
		}).request(opt);
						 });
		});
	
}
function showadminbox() {
	var fade=$('admincontent');
	var fx = new Fx.Style(fade,'opacity', {duration:200, wait:false});
	fx.start(0,1);
}


function fadeinzoom(nh,nw) {
	var win=$('zoomer');
	var fx3 = new Fx.Style(win,'opacity', {duration:500, wait:true});
	win.setStyle('opacity', '0');
	win.setStyle('display', 'block');
	fx3.start(0,1);	
}

function hidepic() {
	var fade=$('fader');
	var zoom=$('zoomer');
	
	var fx = new Fx.Style(fade,'opacity', {duration:500, wait:false});
	var fx2 = new Fx.Style(zoom, 'opacity', {duration:200, wait:false});
	fx2.start(1,0).chain(function(){
		zoom.setStyle('display', 'none');
		fx.start(0.7,0).chain(function(){
			fade.setStyle('display', 'none');
		});
	});
}

function changemenu(el,loadinframe) {
	if(lastm!=null) {
		var fx = new Fx.Style(lastm,'opacity', {duration:200, wait:false});
		fx.start(1,0.0001);
	}
	if(el!=null) {
		var fx2 = new Fx.Style(el,'opacity', {duration:200, wait:false});
		fx2.start(0,1);
	}
	if(loadinframe!='') {
		document.getElementById('main').src=loadinframe;
	}
	lastm=el;

	var win=$('content');

	win.innerHTML='<table height=100% width=100% border=0><tr><td valign=middle align=center><img src="pics/ajax.gif"></td></tr></table>';
	new Ajax(loadinframe, {method: 'get',update: $('content')}).request();
}

function fadeinwin() {
	var win=$('content');
	var fx3 = new Fx.Style(win,'opacity', {duration:500, wait:true});
	fx3.start(0,1);	
}

function changesubmenu(newmenu,newurl,params) {
    if(lastsubmenu!=null || lastsubmenu==newmenu) {
	  document.getElementById(lastsubmenu).className='submenuitem';
	  document.getElementById('sub'+lastsubmenu).innerHTML='';
	}
    document.getElementById(newmenu).className='submenuitema';
    document.getElementById('sub'+newmenu).innerHTML='<img src="pictures/menu_arrow.png" width="22" height="12" alt="">';
	lastsubmenu=newmenu;
	document.getElementById('mainwindow').innerHTML='<table height=300 width=100% border=0><tr><td valign=middle align=center><img src="pictures/loading.gif" height=100 width=100></td></tr></table>';
	new Ajax(newurl, {method: 'get',update: $('mainwindow')}).request();
}

function loadsubmenu(newurl) {
  var fx = new Fx.Styles('submenuitems', {duration:300, wait:false});
	fx.start({
	  'opacity': 0
	}); 
   	new Ajax(newurl, {method: 'get',update: $('submenuitems')}).request();
	fx.start({
	  'opacity': 1
	}); 
   	
}

function getElementsByName_iefix(tag, name) {
     
     var elem = document.getElementsByTagName(tag);
     var arr = new Array();
     for(i = 0,iarr = 0; i < elem.length; i++) {
          att = elem[i].getAttribute("name");
          if(att == name) {
               arr[iarr] = elem[i];
               iarr++;
          }
     }
     return arr;
}


function expand(nid,newurl) {
  ob = getElementsByName_iefix('div','det');
  for (i=0; i < ob.length; i++){
  	ob[i].style.display='none';
	ob[i].innerHTML='';
  }
  document.getElementById('accd'+nid).innerHTML='<table height=300 width=100% border=0><tr><td valign=middle align=center><img src="pictures/loading.gif" height=100 width=100></td></tr></table>';
  new Ajax(newurl, {method: 'get',update: $('accd'+nid)}).request();
  document.getElementById('accd'+nid).style.display='block';
}

function loginuser() {
	nuser=document.getElementById('login_user').value;
	npass=document.getElementById('login_pass').value;
	document.getElementById('end2').innerHTML='loading...';
	new Ajax('mods/login/loginbar.php?login_user='+nuser+'&login_pass='+npass, {method: 'get',update: $('end2')}).request();
}

function end2(newurl) {
  new Ajax(newurl, {method: 'get',update: $('end2')}).request();	
}


function changeclass(obj1,newclass) {
	obj1.className=newclass;
}

function videfck() {
	$('fck').value="";
}
function sendForm(newurl,loader) {
	var fckcontent = escape(FCKeditorAPI.GetInstance('fck').GetXHTML()); //message being your fck id
	var mypost = $('pageform').toQueryString(); //testform is your form id
  if(loader!=null) {
  	document.getElementById(loader).innerHTML='<img src="pics/ajax.gif" height=16 width=16> saving...';
  }
	mypost+='&fck2='+fckcontent;
	videfck();
	myAjax = new Ajax(newurl, { //test2.php the php working page
		method: 'post',
		postBody: mypost,
		update: $('admincontent'),
		evalScripts: true
	}).request();
	mypost='';
}

function sendformc(formid,newurl,wind){
	var mypost = $(formid).toQueryString(); //testform is your form id
	ajax(newurl,mypost,wind);
	mypost='';
}

function sendFormUsers(newurl,loader){
	var win = $('userdetails');
	var mypost = $('pageform').toQueryString(); //testform is your form id
  if(loader!=null) {
  	document.getElementById(loader).innerHTML='<img src="pics/ajax.gif" height=16 width=16> saving...';
  }
	myAjax = new Ajax(newurl, { //test2.php the php working page
		method: 'post',
		postBody: mypost,
		update: win,
		evalScripts: true
	}).request();
	mypost='';
}

function sendFormMusic(newurl,loader){
	var win = $('userdetails');
	var mypost = $('pageform').toQueryString(); //testform is your form id
  if(loader!=null) {
  	document.getElementById(loader).innerHTML='<img src="pics/ajax.gif" height=16 width=16> saving...';
  }
	myAjax = new Ajax(newurl, { //test2.php the php working page
		method: 'post',
		postBody: mypost,
		update: win,
		evalScripts: true
	}).request();
	mypost='';
}

function sendFormLink(newurl,loader){
	var win = $('admincontent');
	var mypost = $('pageform').toQueryString(); //testform is your form id
  if(loader!=null) {
  	document.getElementById(loader).innerHTML='<img src="pics/ajax.gif" height=16 width=16> saving...';
  }
	myAjax = new Ajax(newurl, { //test2.php the php working page
		method: 'post',
		postBody: mypost,
		update: win,
		evalScripts: true
	}).request();
	mypost='';
}

// FOR THE LEFT MENU

function startElem(){
var szNormal = 100, szSmall  = 40, szFull   = 280;
 
var kwicks = $$("#kwicks .kwick");
var fx = new Fx.Elements(kwicks, {wait: false, duration: 300, transition: Fx.Transitions.Quint.easeOut});
kwicks.each(function(kwick, i) {
	kwick.addEvent("mouseenter", function(event) {
		var o = {};
		o[i] = {height: [kwick.getStyle("height").toInt(), szFull]}
		kwicks.each(function(other, j) {
			if(i != j) {
				var w = other.getStyle("height").toInt();
				if(w != szSmall) o[j] = {height: [w, szSmall]};
			}
		});
		fx.start(o);
	});
});
 
$("kwicks").addEvent("mouseleave", function(event) {
	var o = {};
	kwicks.each(function(kwick, i) {
		o[i] = {height: [kwick.getStyle("height").toInt(), szNormal]}
	});
	fx.start(o);
})
}

var lastuser=null;

function changeuser(uid) {
	if(lastuser!=uid) {
	  var win = $('userdetails');
	  document.getElementById('user'+uid).className='adminuser1';
	  if(lastuser!=null) {
	    document.getElementById('user'+lastuser).className='adminuser';
	  }
	  lastuser=uid;
	  new Ajax('user_details.php?uid='+uid, {method: 'get',update: win}).request();
	}	  
}

function changeadd() {
	  var win = $('userdetails');
	  lastuser=null;
	  new Ajax('user_new.php', {method: 'get',update: win}).request();
}
function changeuserlist(uid,act,rn,un) {
	document.getElementById('usera'+uid).className='user'+act;
	document.getElementById('user'+uid).innerHTML=rn+' ('+un+')';
}

function deleteUser(uid,newurl) {
	var r=confirm("Do You really want to delete this account?");
	if(r==true) {
		var win = $('userdetails');
		myAjax = new Ajax(newurl+'?uid='+uid+'&deluser='+uid, { //test2.php the php working page
			method: 'post',
			update: win,
			evalScripts: true
		}).request();
		mypost='';
	}
}

function screenw() {
if (parseInt(navigator.appVersion)>3) {
 if (navigator.appName=="Netscape") {
  winW = window.innerWidth;
  winH = window.innerHeight;
 }
 if (navigator.appName.indexOf("Microsoft")!=-1) {
  winW = document.body.offsetWidth;
  winH = document.body.offsetHeight;
 }
 return winW;
}
}

function screenh() {
	if (parseInt(navigator.appVersion)>3) {
 		if (navigator.appName=="Netscape") {
  winW = window.innerWidth;
  winH = window.innerHeight;
 }
 if (navigator.appName.indexOf("Microsoft")!=-1) {
  winW = document.body.offsetWidth;
  winH = document.body.offsetHeight;
 }
 return winH;
}
}



function zoomimage(img,startw,starth,endw,endh,newurl) {
	var win=$('imager');
	var im=$(img);
	var fx = new Fx.Styles(win, {duration:500, wait:false});
	setzoomer(img,startw,starth);
	var nh=-Math.floor(endh/2);
	var nw=-Math.floor(endw/2);
	var tw=Math.floor(screenw()/2);
	var th=Math.floor(screenh()/2);
	win.setStyle('opacity', '0');
	win.setStyle('display', 'block');
	win.innerHTML='';
	fade();	
	fx.start({ 'height': endh,
						 'opacity' : 1,
						 'top': th,
						 'left': tw,			 
						 'margin-left': nw,
						 'margin-top': nh,
						 'background-color' : '#ffffff',
						   'width' : endw}).chain(function(){
						 		new Ajax(newurl, {
			method: 'get',
			update: win,
			evalScripts: true
			}).request();
		});						 			
}

function loadimg(newurl,h,w,pid) {
	var win=$('imager');
	var im=$('showimg');
	var fx1 = new Fx.Style(im, 'opacity', {duration:200,wait:false});
	var fx2 = new Fx.Style(im, 'opacity', {duration:200,wait:false});
	
	fx1.start(1,0).chain(function(){
		im.innerHTML='<img src="pics/ajax.gif">';
		fx2.start(0,1);
	});
	new Ajax(newurl+'?pid='+pid+'&h='+h+'&w='+w, {
			method: 'get',
			update: win,
			evalScripts: true
			}).request();
	
}

function fade() {
	var fade=$('fader');
	var fx = new Fx.Style(fade,'opacity', {duration:500, wait:false});
	fade.setOpacity(0);
	fade.setStyle('display', 'block');
	fx.start(0,0.7);
}

function unfade() {
	var fade=$('fader');
	var fx = new Fx.Style(fade,'opacity', {duration:500, wait:false});
	fade.setStyle('display', 'block');
	fx.start(0.7,0);
}



function setzoomer(img,sw,sh) {
	var im=$(img);
	var win=$('imager');
  var top = 0, left = 0; 
  var myTarget = im; 
  while(myTarget!= document.body) { 
     top += myTarget.offsetTop; 
     left += myTarget.offsetLeft; 
     myTarget = myTarget.offsetParent; 
  } 
  win.setStyle('background-color', '#ffffff');
  win.setStyle('margin-left', 0);
  win.setStyle('margin-right', 0);
  win.setStyle('top',top);
  win.setStyle('left',left);
  win.setStyle('height',sw);
  win.setStyle('width',sh);
  win.setStyle('margin-left', 0);
  win.setStyle('margin-top', 0);
}

function hideimage() {
	var zoom=$('imager');
	var fx2 = new Fx.Style(zoom, 'opacity', {duration:200, wait:false});
	fx2.start(1,0).chain(function(){
		zoom.setStyle('display', 'none');
	});
	unfade();
}

function uploadpicok(newurl,gid) {
	parent.loadgall(newurl,'gid='+gid);
}

function dopics(newurl,pid){
	hidecomm();
	var win = $('admincontent');
	if(pid=='d') {
		var r=confirm("Do you really want to delete the selected pictures?");
	} else {
		var r=true;
	}
	if(r==true) {
		var mypost = $('pageform').toQueryString(); //testform is your form id
		myAjax = new Ajax(newurl+'?act='+pid, { //test2.php the php working page
			method: 'post',
			postBody: mypost,
			update: win,
			evalScripts: true
		}).request();
		mypost='';
	}
}

function loadgall(newurl,opt) {
	hidecomm();
  var win = $('admincontent');
	new Ajax(newurl+'?'+opt, {method: 'get',update: win}).request();
}
function delcat(newurl,opt) {
	var r=confirm("Do you really want to delete this gallery?");
	if(r==true) {
    var win = $('admincontent');
  	new Ajax(newurl+'?'+opt, {method: 'get',update: win}).request();
  }
}

function sendnewgallery(newurl,loader){
	var win = $('admincontent');
	var mypost = $('pageform1').toQueryString(); //testform is your form id
  if(loader!=null) {
  	document.getElementById(loader).innerHTML='<img src="pics/ajax.gif" height=16 width=16> saving...';
  }
	myAjax = new Ajax(newurl, { //test2.php the php working page
		method: 'post',
		postBody: mypost,
		update: win,
		evalScripts: true
	}).request();
	mypost='';
}

function checkit(pid) {
	var valn=$('ck'+pid);
	var img=$('pic'+pid);
	if(valn.checked) {
		img.className='sel0';
		valn.checked=false;
	} else {
		img.className='sel1';
		valn.checked=true;
	}
}

function changecomm(pid,gid) {
	var im=$('cb'+pid);
	var win=$('addcomm');
	var com2=document.getElementById('newcomm');
	var oldcom=document.getElementById('com'+pid).value;
	var cid=document.getElementById('comid');
	var ggid=document.getElementById('gid');
  var top = 0, left = 0; 
  var myTarget = im; 
  while(myTarget!= document.body) { 
     top += myTarget.offsetTop; 
     left += myTarget.offsetLeft; 
     myTarget = myTarget.offsetParent; 
  } 
  left+=18;
  win.setStyle('top',top);
  win.setStyle('left',left);
  com2.value=oldcom;
  cid.value=pid;
  ggid.value=gid;
  win.setStyle('display','block');
  win.setStyle('opacity',0.8);
}
function hidecomm() {
	var win=$('addcomm');
  win.setStyle('display','none');
}

function newcomm(newurl) {
	var win = $('admincontent');
	var mypost = $('commform').toQueryString(); //testform is your form id

	myAjax = new Ajax(newurl, { //test2.php the php working page
		method: 'post',
		postBody: mypost,
		update: win,
		evalScripts: true
	}).request();
	mypost='';
	hidecomm();
}

function hide(con) {
	var c=$(con);
	c.setStyle('display','none');
}
function show(con) {
	var c=$(con);
	c.setStyle('display','');
}