function get(str){
    return document.getElementById(str);
}
function getN(str){
    return document.getElementsByName(str);
}
function checkKey(evt){
    if(evt.keyCode==13 && get('lin').value==1){
	logIn();
    }
}
function logIn(){
    var f = get('f');
    f.action = "index.php";
    f.submit();
}
function logOut(){
    var f = get('f');
    f.action = "includes/logout.php";
}
function editContent(){
    get('inContent').style.display = 'none';
    get('editContent').style.display = 'block';
    get('editContent').focus();
}
function saveContent(){
    var f = get('f');
    var id = get('id').value;
    f.action = "includes/update.php?id="+id;
}
function sendForm(){
    document.write("<input type='hidden' name='redirect' value='index.php?id=5'>");
    var f = get('f');
    f.action = "includes/nvform.php";
}
function resetForm(){
    var f = get('f');
    f.reset();
}
function clickGo(){
    get('f').action = "/nvform.php";
}
function clickReset(){
    get('f').reset();
}

var TheSeparator = "/";
var TheSeparator2 = ", ";
var ShowDay ="yes";
var Days = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
var TheDate = new Date();

var TheWeekDay = TheDate.getDay();
var Day ="";
if (ShowDay == "yes"){
    Day = Days[TheWeekDay];
    Day += "";}

var TheMonth = TheDate.getMonth() + 1;
if (TheMonth < 10) TheMonth = "0" + TheMonth;

var TheMonthDay = TheDate.getDate();
if (TheMonthDay < 10) TheMonthDay = "0" + TheMonthDay;

var TheYear = TheDate.getYear();
if (TheYear < 1000) TheYear += 1900;

var D = "";
D += TheYear;

function createXHR(){
	var xhr;
	try{
		xhr = new ActiveXObject("MSXML2.XMLHTTP");
	}catch(e){
		try{
			xhr = new ActiveXObject("Microsoft.XMLHTTP");
		}catch(E){
			xhr=false;
		}
	}
	if(!xhr && typeof XMLHttpRequest != 'undefined'){
		xhr= new XMLHttpRequest();
	}
	return xhr;
}
function setDiv(){
	if (xhr.readyState == 4){
		var res = xhr.responseText;
		l = getN("right").length -1;
		get('right').innerHTML = res;
	}
}
var glblFile;
function getFile(id){
	glblFile = id;
	xhr = createXHR();
	xhr.onreadystatechange = setDiv;
	xhr.open("GET","index.php?id=" + id);
	xhr.send(null);
}

//DELETE UPLOADED FILE
function cBack(rText){
    //alert(rText);
    if(rText!='false'){
	var f = document.getElementById("li"+rText);
	f.parentNode.removeChild(f);
    }
}
function ajaxObject(url,callbackFunction){
    var that=this;
    this.updating = false;
    this.abort = function(){
	if(that.updating){
	    that.updating = false;
	    that.AJAX.abort();
	    that.AJAX = null;
	}
    }
    this.update=function(passData,postMethod){
	if(that.updating){ return false; }
	    that.AJAX = null;
	if(window.XMLHttpRequest){
	    that.AJAX = new XMLHttpRequest();
	} else {
	    that.AJAX=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if(that.AJAX==null){
	    return false;
	} else {
	    that.AJAX.onreadystatechange=function(){
		if(that.AJAX.readyState==4){
		    that.updating = false;
		    that.callback(that.AJAX.responseText,that.AJAX.status,that.AJAX.responseXML);
		    that.AJAX = null;
		}
	    }
	    that.updating=new Date();
	    if(/post/i.test(postMethod)){
		var uri = urlCall+'?'+that.updating.getTime();
		that.AJAX.open("POST",uri,true);
		that.AJAX.setRequestHeader("Content-type","application/x-www-form-urlencoded");
		that.AJAX.setRequestHeader("Content-Length",passData.length);
		that.AJAX.send(passData);
	    } else {
		var uri = urlCall+'?'+passData+'&timestamp='+(that.updating.getTime());
		that.AJAX.open("GET",uri,true);
		that.AJAX.send(null);
	    }
	    return true;
	}
    }
    var urlCall = url;
    this.callback = callbackFunction || function (){};
}
function delFile(fileid,filenm){
    var AJ = new ajaxObject("/new2/up.php",cBack);
    AJ.update("id="+fileid+"&file="+filenm,"post");
}
$(function(){
    var lo=location.pathname.substr(1);
    $("[href='"+lo+"']").addClass("active");
    if(!lo) $("#leftnav li a:eq(0)").addClass("active");
});
