
function showResize(resize){

	if(document.getElementById(resize).style.display=="none"){
		document.getElementById(resize).style.display="block";
	}else{
		document.getElementById(resize).style.display="none";
	}
}

function show_gallery_photo(imageName,photo) {
	document.images[imageName].src=photo;
}


function NewWindow(mypage, myname, w, h, myscroll) {
	var winl = (screen.width - w) / 4;
	var wint = (screen.height - h) / 4;
	var newWindow
			winprops = 'height='+h+',width='+w+',top=0,left=0,scrollbars='+myscroll;
	win = window.open(mypage, myname, winprops)
			if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
			win.focus();
}

function delbutton(pressbutton) {
	document.adminForm.act_do.value=pressbutton;
	try {
		document.adminForm.onsubmit();
	}
	catch(e){}
	document.adminForm.submit();
}

function checkAll( n, fldName ) {
	if (!fldName) {
		fldName = 'cb';
	}
	var f = document.adminForm;
	var c = f.toggle.checked;
	var n2 = 0;
	for (i=0; i < n; i++) {
		cb = eval( 'f.' + fldName + '' + i );
		if (cb) {
			cb.checked = c;
			n2++;
		}
	}
	
	if (c) {
		document.adminForm.boxchecked.value = n2;
	} else {
		document.adminForm.boxchecked.value = 0;
	}
}

function submitbutton(pressbutton) {
	submitform(pressbutton);
}

function isChecked(isitchecked){
	if (isitchecked == true){
		document.adminForm.boxchecked.value++;
	}
	else {
		document.adminForm.boxchecked.value--;
	}
}

function submitform(pressbutton){
	document.adminForm.action.value=pressbutton;
	try {
		document.adminForm.onsubmit();
	}
	catch(e){}
	document.adminForm.submit();
}

function SubmitEditorForm(){
	document.forms[0].submit() ;
}
	
function clearALl() {
	document.getElementById("dat").value="";
}

function reload(form,path){
	var val=form.cat.options[form.cat.options.selectedIndex].value;
	self.location=path + '.php?action=add&cat=' + val ;
}

function ordby(form,path,tb){
	var val=form.parent_id.options[form.parent_id.options.selectedIndex].value;
	module=document.getElementById("module").value;
	component=document.getElementById("component").value;
	table=document.getElementById("table").value;
	self.location=path + '.php?action=edit&parent_id=' + val + '&component=' + component + '&module=' + module + '&table=' + table;
	
}

function checkAllMapping( n, fldName) {
	if (!fldName) {
		fldName = 'models';
	}
	if(document.adminForm.toggle.checked){
		document.getElementById("checkk").value=1
	}else{
			document.getElementById("checkk").value=""
	}
	var f = document.adminForm;
	var c = f.toggle.checked;
	var n2 = 0;
	for (i=0; i < n; i++) {
		cb = eval( 'f.' + fldName + '' + i );
		if (cb) {
			cb.checked = c;
			n2++;
		}
	}
}


function deteImage(path,img){
	self.location=path + '.php?action=deletephoto&id=' + img ;
}

function deteImageParent(path){
	self.location=path;
}

function deteFormatImage(path,img,filenam,field){
	self.location=path + '.php?action=deletephoto&id='+img+'&filaname='+filenam+'&field='+field;
}

function ordbyloccat(form,path){
	var val=form.cat_id.options[form.cat_id.options.selectedIndex].value;
	self.location=path + '.php?action=edit&cat_id=' + val ;
}

function del_gallery(loc,de,par){
	if (confirm("Are you sure ?")){
		window.location=loc+"?action=deletegallery&gallery_id="+de+"&parent_id="+par;
	}
}

//this is the timeout countdown for the logout
//exit_lang is msg outputted nesxt to timer
//exit_msg_lang is msg outputted when time getting close to disconnection
function countdown(inactive_allowed,exit_lang,exit_msg_lang){
		
	var request = false;
	try {
		request = new XMLHttpRequest();
	} catch (e) {
		try{
			request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {
				alert("Unable to complete your request.");
				return false;
			}
		}
	}
	
	request.open("GET", "/kernel/admin/includes/logoutTimer.php?action=getTimeStamp", true);
	request.onreadystatechange = function() {
		if (request.readyState == 1){
		} else if(request.readyState == 4 && request.status == 200){
			var time_passed = request.responseText;
			if (inactive_allowed < time_passed){
				clearTimeout(t);
				window.location="/admin/index.php";
			} else {
				var time_left = inactive_allowed - time_passed;
				if (time_left == 180)
				alert (exit_msg_lang);
					
				var seconds=time_left%60;
				var minutes=Math.floor(time_left/60);
			
				if (seconds==0){
					seconds = "00";
				} else if (seconds<10){
					seconds = "0"+seconds;
				}
				
				document.getElementById('countdown').innerHTML=exit_lang;
				document.getElementById('countdown').innerHTML+=minutes;
				document.getElementById('countdown').innerHTML+=":";
				document.getElementById('countdown').innerHTML+=seconds;
				t = setTimeout('countdown(' + inactive_allowed + ',\''+exit_lang+'\',\''+exit_msg_lang+'\');', 1000);
			}
		}
	}
	request.send(null);
}

//used to update the timer for the log out
//if pressed this goes to a page that renews the log out timestamp
function updateTimer(){
	var request = false;
	try {
		request = new XMLHttpRequest();
	} catch (e) {
		try{
			request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {
				alert("Unable to complete your request.");
				return false;
			}
		}
	}
	
	request.open("GET","/kernel/admin/includes/logoutTimer.php?action=renewTimeStamp", true);
	request.onreadystatechange = function() {
		if (request.readyState == 1){
		} else if(request.readyState == 4 && request.status == 200){
		}
	}
	request.send(null);
}