var xmlHttp

////////////////////
// GLOBAL FUNCTIONS
////////////////////

function stateChanged()
{
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
    {
        document.getElementById('textHint').innerHTML=xmlHttp.responseText
    }
}

function GetXmlHttpObject()
{
    var objXMLHttp=null
    if (window.XMLHttpRequest)
    {
        objXMLHttp=new XMLHttpRequest()
    }
    else if (window.ActiveXObject)
    {
        objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
    }
    return objXMLHttp
}

////////////////////
// OUR FUNCTIONS
////////////////////


// add file to user favorite list
function setStatClick(button)
{
    xmlHttp=GetXmlHttpObject()
    if (xmlHttp==null) {
        alert ("Browser does not support HTTP Request")
        return
    }
    var url="/ajx_statClick.php"
    url=url+"?button="+button
    url=url+"&sid="+Math.random()

/*	xmlHttp.onreadystatechange= function() {
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
			document.getElementById(clq).innerHTML=xmlHttp.responseText
		}
	} */
//    xmlHttp.onreadystatechange=stateChanged
    xmlHttp.open("GET",url,true)
    xmlHttp.send(null)
}

// add file to user favorite list
function setStatVisit(page)
{
    xmlHttp=GetXmlHttpObject()
    if (xmlHttp==null) {
        alert ("Browser does not support HTTP Request")
        return
    }
    var url="/ajx_statVisit.php"
    url=url+"?page="+page
    url=url+"&sid="+Math.random()
/*
	xmlHttp.onreadystatechange= function() {
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
			document.getElementById(clq).innerHTML=xmlHttp.responseText
		}
	}*/
//    xmlHttp.onreadystatechange=stateChanged
    xmlHttp.open("GET",url,true)
    xmlHttp.send(null)
}

// add field to upload file Form
function addUploadField(nbr,clq)
{
	//alert(nbr +' '+ clq);
    xmlHttp=GetXmlHttpObject()
    if (xmlHttp==null)
    {
        alert ("Browser does not support HTTP Request")
        return
    }
    var url="/ajx_adduploadfield.php"
    url=url+"?nbr="+nbr
    url=url+"&sid="+Math.random()

	xmlHttp.onreadystatechange= function() {
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		{
			document.getElementById(clq).innerHTML=xmlHttp.responseText
		}
	}

    xmlHttp.open("GET",url,true)
    xmlHttp.send(null)
}


// add field to upload file Form
function showFileInfo(idf, idalb, clq)
{
	//alert(nbr +' '+ clq);
    xmlHttp=GetXmlHttpObject()
    if (xmlHttp==null) {
        alert ("Browser does not support HTTP Request")
        return
    }

    var url="/ajx_showFileInfo.php"
    url=url+"?idf="+idf
    url=url+"&idalb="+idalb
    url=url+"&sid="+Math.random()

	xmlHttp.onreadystatechange= function() {
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		{
			document.getElementById(clq).innerHTML=xmlHttp.responseText
		}
	}

    xmlHttp.open("GET",url,true)
    xmlHttp.send(null)
}


// add field to upload file Form
function showFileSlideshow(ar_jsId,clq)
{
    xmlHttp=GetXmlHttpObject()
    if (xmlHttp==null)
    {
        alert ("Browser does not support HTTP Request")
        return
    }
	
	for(i=0;i<=ar_jsId.lenght;i++) {
		var url="/ajx_showFileSlideshow.php"
		url=url+"?idf="+i
		url=url+"&sid="+Math.random()

		xmlHttp.onreadystatechange= function() {
			if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
			{
				document.getElementById(clq).innerHTML=xmlHttp.responseText
			}
		}
	}
    xmlHttp.open("GET",url,true)
    xmlHttp.send(null)
}

// add file to user favorite list
function addFileToFav(idf,idu,clq,type)
{
    xmlHttp=GetXmlHttpObject()
    if (xmlHttp==null)
    {
        alert ("Browser does not support HTTP Request")
        return
    }
    var url="/ajx_addfiletofav.php"
    url=url+"?idf="+idf
    url=url+"&idu="+idu
    url=url+"&clq="+clq
	url=url+"&type="+type
    url=url+"&sid="+Math.random()

	xmlHttp.onreadystatechange= function() {
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		{
			document.getElementById(clq).innerHTML=xmlHttp.responseText
		}
	}
//    xmlHttp.onreadystatechange=stateChanged
    xmlHttp.open("GET",url,true)
    xmlHttp.send(null)
}

// add userRef (user 'x' ) to user (user connect) friend list
function addUserToFriend(idf,idu,clq,type)
{
    xmlHttp=GetXmlHttpObject()
    if (xmlHttp==null)
    {
        alert ("Browser does not support HTTP Request")
        return
    }
    var url="/ajx_addusertofriend.php"
    url=url+"?idf="+idf
    url=url+"&idu="+idu
    url=url+"&clq="+clq
	url=url+"&type="+type
    url=url+"&sid="+Math.random()

	xmlHttp.onreadystatechange= function() {
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		{
			document.getElementById(clq).innerHTML=xmlHttp.responseText
		}
	}
//    xmlHttp.onreadystatechange=stateChanged
    xmlHttp.open("GET",url,true)
    xmlHttp.send(null)
}

// Create a new user Album
function createAlbum(idf, idu, name, clq, qstr) {
    xmlHttp=GetXmlHttpObject()
    if (xmlHttp==null) {
        alert ("Browser does not support HTTP Request")
    }

	if(name == "") {
		alert ("Please specify an album name")
		return false;
	}
	if(qstr == undefined) {
		qstr = '';
	}
		
    var url="/ajx_createalbum.php"
    url=url+"?idf="+idf
    url=url+"&idu="+idu
    url=url+"&name="+name
    url=url+"&clq="+clq
    url=url+"&qstr="+qstr
    url=url+"&sid="+Math.random()

	xmlHttp.onreadystatechange= function() {
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { 
			/* 4 : état "complete" */
			//if (xmlHttp.status == 200) /* 200 : code HTTP pour OK */
           	//{
			   document.getElementById(clq).innerHTML=xmlHttp.responseText;
			//}
		}
	}
	xmlHttp.open("GET",url,true)
    xmlHttp.send(null)
}


// add file to user favorite list
function addFileToAlb(idf,idalb,clq)
{
    xmlHttp=GetXmlHttpObject()
    if (xmlHttp==null) {
        alert ("Browser does not support HTTP Request")
        return
    }
    var url="/ajx_addfiletoalbum.php"
    url=url+"?idf="+idf
    url=url+"&idalb="+idalb
    url=url+"&clq="+clq
    url=url+"&sid="+Math.random()

	xmlHttp.onreadystatechange= function() {
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		{
			document.getElementById(clq).innerHTML=xmlHttp.responseText
		}
	}
//    xmlHttp.onreadystatechange=stateChanged
    xmlHttp.open("GET",url,true)
    xmlHttp.send(null)
}



// add file to user favorite list
function setAlbumCover(idf,idalb,clq)
{
    xmlHttp=GetXmlHttpObject()
    if (xmlHttp==null) {
        alert ("Browser does not support HTTP Request")
        return
    }
    var url="/ajx_setAlbumCover.php"
    url=url+"?idf="+idf
    url=url+"&idalb="+idalb
    url=url+"&clq="+clq
    url=url+"&sid="+Math.random()

	xmlHttp.onreadystatechange= function() {
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
			document.getElementById(clq).innerHTML=xmlHttp.responseText
		}
	}
//    xmlHttp.onreadystatechange=stateChanged
    xmlHttp.open("GET",url,true)
    xmlHttp.send(null)
}


// add usrfav (user 'x' ) to user (user connect) favorite list
function flagFile(type,idf,idu)
{
    xmlHttp=GetXmlHttpObject()
    if (xmlHttp==null)
    {
        alert ("Browser does not support HTTP Request")
        return
    }
    var url="/ajx_flagfile.php"
    url=url+"?idf="+idf
    url=url+"&idu="+idu
    url=url+"&type="+type
    url=url+"&sid="+Math.random()

	xmlHttp.onreadystatechange= function() {
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		{
			document.getElementById('flagFile_return').innerHTML=xmlHttp.responseText
			document.getElementById('flagFile_form').innerHTML=''
		}
	}
//    xmlHttp.onreadystatechange=stateChanged
    xmlHttp.open("GET",url,true)
    xmlHttp.send(null)
}


// Resend Invitation information
function resendInvitation(to,clq)//(form)
{
    xmlHttp=GetXmlHttpObject()
    if (xmlHttp==null)




    {
        alert ("Browser does not support HTTP Request")
    }

    var url="/ajx_inviteresend.php"
    url=url+"?to="+to
    url=url+"&clq="+clq
    url=url+"&sid="+Math.random()

	xmlHttp.onreadystatechange= function() {
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") /* 4 : état "complete" */
		{
			//if (xmlHttp.status == 200) /* 200 : code HTTP pour OK */
           	//{
			   document.getElementById(clq).innerHTML=xmlHttp.responseText;
			//}
		}
	}
	xmlHttp.open("GET",url,true)
    xmlHttp.send(null)
}


function resendInvitation2(to,clq)//(form)
{
    xmlHttp=GetXmlHttpObject()
    if (xmlHttp==null)
    {
        alert ("Browser does not support HTTP Request")
    }

    var url="/ajx_inviteresend.php"
    url=url+"?to="+to
    url=url+"&clq="+clq
    url=url+"&sid="+Math.random()

	xmlHttp.onreadystatechange= function() {
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") /* 4 : état "complete" */
		{
			//if (xmlHttp.status == 200) /* 200 : code HTTP pour OK */
           	//{
			   //document.getElementById(clq).innerHTML=xmlHttp.responseText;
			   document.getElementById(clq).innerHTML="re-sent";
			//}
		}
	}
	xmlHttp.open("GET",url,true)
    xmlHttp.send(null)
}





// add file to user favorite list
function displaySelectedImage(img,clq) {
    xmlHttp=GetXmlHttpObject()
    if (xmlHttp==null)
    {
        alert ("Browser does not support HTTP Request")
        return
    }

//    alert(img + ' -- ' + clq);


    var url="/ajx_displayselectedimage.php"
    url=url+"?img="+img
    url=url+"&clq="+clq
    url=url+"&sid="+Math.random()

	xmlHttp.onreadystatechange= function() {
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		{
			document.getElementById(clq).innerHTML=xmlHttp.responseText
		}
	}
//    xmlHttp.onreadystatechange=stateChanged
    xmlHttp.open("GET",url,true)
    xmlHttp.send(null)
}


// add file to user favorite list
function voteEventFile(vote,eventId,fileId,userId,clq) {
    xmlHttp=GetXmlHttpObject()
    if (xmlHttp==null)
    {
        alert ("Browser does not support HTTP Request")
        return
    }

//    alert(img + ' -- ' + clq);


    var url="/ajx_voteeventfile.php"
    url=url+"?vote="+vote
    url=url+"&eid="+eventId
    url=url+"&fid="+fileId
    url=url+"&uid="+userId
    url=url+"&clq="+clq
    url=url+"&sid="+Math.random()

	xmlHttp.onreadystatechange= function() {
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		{
			document.getElementById(clq).innerHTML=xmlHttp.responseText
		}
	}
//    xmlHttp.onreadystatechange=stateChanged
    xmlHttp.open("GET",url,true)
    xmlHttp.send(null)
}


// remove friend from group :)
function removeUserFromGroup(idu,idg,clq)
{
    xmlHttp=GetXmlHttpObject()
    if (xmlHttp==null)
    {
        alert ("Browser does not support HTTP Request")
        return
    }
    var url="/ajx_rmvuserfromgroup.php"
    url=url+"?idu="+idu
    url=url+"&idg="+idg
    url=url+"&clq="+clq
    url=url+"&sid="+Math.random()

	xmlHttp.onreadystatechange= function() {
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		{
			document.getElementById(clq).innerHTML=xmlHttp.responseText
		}
	}
//    xmlHttp.onreadystatechange=stateChanged
    xmlHttp.open("GET",url,true)
    xmlHttp.send(null)
}







//edit by Cristina 28.11.2006
//mine sack for Ajax
function sack(file) {
	this.xmlhttp = null;

	this.resetData = function() {
		this.method = "POST";
  		this.queryStringSeparator = "?";
		this.argumentSeparator = "&";
		this.URLString = "";
		this.encodeURIString = true;
  		this.execute = false;
  		this.element = null;
		this.elementObj = null;
		this.requestFile = file;
		this.vars = new Object();
		this.responseStatus = new Array(2);
  	};

	this.resetFunctions = function() {
  		this.onLoading = function() { };
  		this.onLoaded = function() { };
  		this.onInteractive = function() { };
  		this.onCompletion = function() { };
  		this.onError = function() { };
		this.onFail = function() { };
	};

	this.reset = function() {
		this.resetFunctions();
		this.resetData();
	};

	this.createAJAX = function() {
		try {
			this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e1) {
			try {
				this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e2) {
				this.xmlhttp = null;
			}
		}

		if (! this.xmlhttp) {
			if (typeof XMLHttpRequest != "undefined") {
				this.xmlhttp = new XMLHttpRequest();
			} else {
				this.failed = true;
			}
		}
	};

	this.setVar = function(name, value){
		this.vars[name] = Array(value, false);
	};

	this.encVar = function(name, value, returnvars) {
		if (true == returnvars) {
			return Array(encodeURIComponent(name), encodeURIComponent(value));
		} else {
			this.vars[encodeURIComponent(name)] = Array(encodeURIComponent(value), true);
		}
	}

	this.processURLString = function(string, encode) {
		encoded = encodeURIComponent(this.argumentSeparator);
		regexp = new RegExp(this.argumentSeparator + "|" + encoded);
		varArray = string.split(regexp);
		for (i = 0; i < varArray.length; i++){
			urlVars = varArray[i].split("=");
			if (true == encode){
				this.encVar(urlVars[0], urlVars[1]);
			} else {
				this.setVar(urlVars[0], urlVars[1]);
			}
		}
	}

	this.createURLString = function(urlstring) {
		if (this.encodeURIString && this.URLString.length) {
			this.processURLString(this.URLString, true);
		}

		if (urlstring) {
			if (this.URLString.length) {
				this.URLString += this.argumentSeparator + urlstring;
			} else {
				this.URLString = urlstring;
			}
		}

		// prevents caching of URLString
		this.setVar("rndval", new Date().getTime());

		urlstringtemp = new Array();
		for (key in this.vars) {
			if (false == this.vars[key][1] && true == this.encodeURIString) {
				encoded = this.encVar(key, this.vars[key][0], true);
				delete this.vars[key];
				this.vars[encoded[0]] = Array(encoded[1], true);
				key = encoded[0];
			}

			urlstringtemp[urlstringtemp.length] = key + "=" + this.vars[key][0];
		}
		if (urlstring){
			this.URLString += this.argumentSeparator + urlstringtemp.join(this.argumentSeparator);
		} else {
			this.URLString += urlstringtemp.join(this.argumentSeparator);
		}
	}

	this.runResponse = function() {
		eval(this.response);
	}

	this.runAJAX = function(urlstring) {
		if (this.failed) {
			this.onFail();
		} else {
			this.createURLString(urlstring);
			if (this.element) {
				this.elementObj = document.getElementById(this.element);
			}
			if (this.xmlhttp) {
				var self = this;
				if (this.method == "GET") {
					totalurlstring = this.requestFile + this.queryStringSeparator + this.URLString;
					this.xmlhttp.open(this.method, totalurlstring, true);
				} else {
					this.xmlhttp.open(this.method, this.requestFile, true);
					try {
						this.xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
					} catch (e) { }
				}

				this.xmlhttp.onreadystatechange = function() {
					switch (self.xmlhttp.readyState) {
						case 1:
							self.onLoading();
							break;
						case 2:
							self.onLoaded();
							break;

						case 3:
							self.onInteractive();
							break;
						case 4:
							self.response = self.xmlhttp.responseText;
							self.responseXML = self.xmlhttp.responseXML;
							self.responseStatus[0] = self.xmlhttp.status;
							self.responseStatus[1] = self.xmlhttp.statusText;
							if (self.execute) 
							{
								self.runResponse();
							}

							if (self.elementObj) {
								elemNodeName = self.elementObj.nodeName;
								elemNodeName.toLowerCase();
								if (elemNodeName == "input"
								|| elemNodeName == "select"
								|| elemNodeName == "option"
								|| elemNodeName == "textarea") {
									self.elementObj.value = self.response;
								} else {
									self.elementObj.innerHTML = self.response;
								}
							}
							if (self.responseStatus[0] == "200") 
							{
								self.onCompletion();
							} else {
								self.onError();
							}

							self.URLString = "";
							break;
					}
				};

				this.xmlhttp.send(this.URLString);
			}
		}
	};

	this.reset();
	this.createAJAX();
}

//end sack AJAX
//instantiate a sack object
var ajaxObjectArray=new Array();

var fileAjaxName="../../ajx_editname.php";
var fileAjaxNameView = "../ajx_editname.php";
function editNameAjax(filename,fileid,user_view)
{
	
       //alert(filename);
       ajaxObjectArray[ajaxObjectArray.length] = new sack();
       var ajaxIndex = ajaxObjectArray.length-1;
       ajaxObjectArray[ajaxIndex].setVar('filename',filename);
	   ajaxObjectArray[ajaxIndex].setVar('fileid',fileid);
	   if(user_view)
	   {
       		ajaxObjectArray[ajaxIndex].requestFile  = fileAjaxNameView;
	   }else
	   {
		   	ajaxObjectArray[ajaxIndex].requestFile  = fileAjaxName;
	   }
       ajaxObjectArray[ajaxIndex].onCompletion = function()
       {
		   
               editName(ajaxIndex,fileid)
       };
       // Specify function that will be executed after file has been found
       ajaxObjectArray[ajaxIndex].runAJAX();// Execute AJAX function
	
}
function editName(ajaxIndex,fileid)
{
       response=ajaxObjectArray[ajaxIndex].response;
	   document.getElementById("show_edit_"+fileid).style.display ="none";
	   document.getElementById("div_fileInfo_"+fileid).style.display ="block";
       document.getElementById("div_fileInfo_"+fileid).innerHTML = response;	   	  
}

var fileAjaxDescr="../../ajx_editdescr.php";
var fileAjaxDescrView="../ajx_editdescr.php";

function editDescrAjax(description,fileid,user_view)
{
       ajaxObjectArray[ajaxObjectArray.length] = new sack();
       var ajaxIndex = ajaxObjectArray.length-1;
       ajaxObjectArray[ajaxIndex].setVar('description',description);
	   ajaxObjectArray[ajaxIndex].setVar('fileid',fileid);
	   
       if(user_view)
	   {
       		ajaxObjectArray[ajaxIndex].requestFile  = fileAjaxDescrView;
	   }else
	   {
		   	ajaxObjectArray[ajaxIndex].requestFile  = fileAjaxDescr;
	   }
       ajaxObjectArray[ajaxIndex].onCompletion = function()
       {
		   
               editDescr(ajaxIndex,fileid)
       };
       // Specify function that will be executed after file has been found
       ajaxObjectArray[ajaxIndex].runAJAX();// Execute AJAX function
	
}
function editDescr(ajaxIndex,fileid)
{
       response=ajaxObjectArray[ajaxIndex].response;
	   document.getElementById("show_descr_"+fileid).style.display ="none";
	   document.getElementById("descr_file_"+fileid).style.display ="block";
       document.getElementById("descr_file_"+fileid).innerHTML = response;	   	  
}

var fileAjaxBuy="../ajx_buyFile.php";

function buyFileAjax(userid,fileid)
{
		//alert(fileid);
       ajaxObjectArray[ajaxObjectArray.length] = new sack();
       var ajaxIndex = ajaxObjectArray.length-1;
       ajaxObjectArray[ajaxIndex].setVar('fileid',fileid);
	   ajaxObjectArray[ajaxIndex].setVar('userid',userid);
	   
       ajaxObjectArray[ajaxIndex].requestFile  = fileAjaxBuy;
	  
       ajaxObjectArray[ajaxIndex].onCompletion = function()
       {
		   
               buyFile(ajaxIndex)
       };
       // Specify function that will be executed after file has been found
       ajaxObjectArray[ajaxIndex].runAJAX();// Execute AJAX function
	
}
function buyFile(ajaxIndex)
{

       response=ajaxObjectArray[ajaxIndex].response;
	   //alert(response);
	   if(response == 'done')
	   {
	   document.getElementById("downloadFile").style.display ="block";
	   document.getElementById("buyresponse").style.display ="block";
       //document.getElementById("buyresponse").innerHTML = response;	   	  
	   }else {
		   document.getElementById("buyresponse").style.display ="block";
       		//document.getElementById("buyresponse").innerHTML = response;	   	
	   }
}

//begin ajax edit a user for the user_list_contacts.php
var fileAjaxUser="ajx_edituser.php";
function editNameAjaxUser(name,email,userid)
{
	
      //alert(fileid);
       ajaxObjectArray[ajaxObjectArray.length] = new sack();
       var ajaxIndex = ajaxObjectArray.length-1;
       ajaxObjectArray[ajaxIndex].setVar('name',name);
	   ajaxObjectArray[ajaxIndex].setVar('email',email);
	   ajaxObjectArray[ajaxIndex].setVar('userid',userid);
	   
       ajaxObjectArray[ajaxIndex].requestFile  = fileAjaxUser;
       ajaxObjectArray[ajaxIndex].onCompletion = function()
       {
		   
               editComent(ajaxIndex,userid,name,email)
       };
       // Specify function that will be executed after file has been found
       ajaxObjectArray[ajaxIndex].runAJAX();// Execute AJAX function
	
}


function editAjaxContact(name,email,userid, groupID, groupName)
{
	
      //alert(fileid);
       ajaxObjectArray[ajaxObjectArray.length] = new sack();
       var ajaxIndex = ajaxObjectArray.length-1;
       ajaxObjectArray[ajaxIndex].setVar('name',name);
	   ajaxObjectArray[ajaxIndex].setVar('email',email);
	   ajaxObjectArray[ajaxIndex].setVar('userid',userid);
	   ajaxObjectArray[ajaxIndex].setVar('groupID',groupID);
	   ajaxObjectArray[ajaxIndex].setVar('groupName',groupName);
	   
       ajaxObjectArray[ajaxIndex].requestFile  = fileAjaxUser;
       ajaxObjectArray[ajaxIndex].onCompletion = function()
       {
		   
               editComent(ajaxIndex,userid,name,email)
       };
       // Specify function that will be executed after file has been found
       ajaxObjectArray[ajaxIndex].runAJAX();// Execute AJAX function
	
}



function editComent(ajaxIndex,userid,name,email)
{
	if (!String.prototype.trim) {
		String.prototype.trim=function(){
		    return this.replace(/^\s*|\s*$/g,'');
		}
	}
       response=ajaxObjectArray[ajaxIndex].response;
	response = response.trim();
		if(response == 'done')
		{
		if(name == '') name = "no name";
		if(email == '') email = "no email";
		   document.getElementById("showEdit"+userid).style.display ="none";
		   document.getElementById("nameu"+userid).innerHTML = name;
		   document.getElementById("emailu"+userid).innerHTML = '<a href="mailto:'+email+'" style="text-decoration: none;">'+email+'</a>';
		}
		else if (response == 'dupe')
		{
		    document.getElementById('newgroup'+userid).innerHTML = '<font color="#cc0000">Group Exists</font>';
		}
		else if (response == 'not') 
	   	  {
			  document.getElementById("showEdit"+userid).innerHTML = "can't edit: "+response;
		  }
		else
			eval(response);
}

//end ajax edit a user for the user_list_contacts.php

//begin ajax edit a user for the file_view.php
var fileAjaxPopulate="../ajx_populate.php";
function populateContactAjax(email,userid)
{
	
		if(email != '')
		{
		
		var brokenstring = email.split(',');
		var len	= brokenstring.length -	1;
		emailSearch = brokenstring[len];
		
			if(emailSearch != '')
			{
			
				   ajaxObjectArray[ajaxObjectArray.length] = new sack();
				   var ajaxIndex = ajaxObjectArray.length-1;
				   ajaxObjectArray[ajaxIndex].setVar('email',emailSearch);
				   ajaxObjectArray[ajaxIndex].setVar('userid',userid);
				   
				   ajaxObjectArray[ajaxIndex].requestFile  = fileAjaxPopulate;
				   ajaxObjectArray[ajaxIndex].onCompletion = function()
				   {
						   populateContact(ajaxIndex)
				   };
				   // Specify function that will be executed after file has been found
				   ajaxObjectArray[ajaxIndex].runAJAX();// Execute AJAX function
			}else {
			 $("pop").innerHTML = "";
			 $("pop").style.display ="none";
			 
			}
		}else {
		 $("pop").innerHTML = "";
		 $("pop").style.display ="none";
		 
		}
	
}
function populateContact(ajaxIndex)
{
	
      response=ajaxObjectArray[ajaxIndex].response;
		if(response != 'empty')
		{
		 	
	 	 $("pop").style.display ="block";
     	 $("pop").innerHTML = response;
		}else {
		 $("pop").innerHTML = "";
		 $("pop").style.display ="none";
		 
		}
}

function popselect(initval,email)
{
	//alert(initval.length);
	var str		= $("poptextarea").value;
	var leng	= str.length - initval.length;
	str = str.substr(0,leng)
	//alert(str);
	//alert($("poptextarea").value);
	$("poptextarea").value =  str + email+",";
	 $("pop").style.display ="none";
	  
}
//end ajax edit a user for the file_view.php

//add contact form_add_contact.php
//add from the hidden div
function insertcontact(email)
{
		var str		= $("poptextarea").value;
		$("poptextarea").value =  str + email+", ";
			
}
function removecontact(email)
{
		var str		= $("poptextarea").value;
		if(str.match(email))
			{
			email = email +', ';
			$("poptextarea").value = str.replace(email,"");

			}
}

function insert(theElement) {
  	var theForm = theElement.form, z = 0;
	for(z=0; z<theForm.length;z++){
      if(theForm[z].type == 'checkbox' && theForm[z].name != 'checkall'){
	  		//theForm[z].checked = theElement.checked;
			if(theElement.checked) insertcontact(theForm[z].value);
			else removecontact(theForm[z].value);
		}
	}
}
//begin ajax sending a message form_user_message.php
var fileSendMess="../ajx_sendmess.php";
var sec;
function sendMessAjax(subj,mess,sender,receive,j)
{
	  sec = 5;
       ajaxObjectArray[ajaxObjectArray.length] = new sack();
       var ajaxIndex = ajaxObjectArray.length-1;
       ajaxObjectArray[ajaxIndex].setVar('subj',subj);
	   ajaxObjectArray[ajaxIndex].setVar('mess',mess);
	   ajaxObjectArray[ajaxIndex].setVar('sender',sender);
	   ajaxObjectArray[ajaxIndex].setVar('receive',receive);
	   
       ajaxObjectArray[ajaxIndex].requestFile  = fileSendMess;
       ajaxObjectArray[ajaxIndex].onCompletion = function()
       {
		   
               sendMess(ajaxIndex,j)
       };
       // Specify function that will be executed after file has been found
       ajaxObjectArray[ajaxIndex].runAJAX();// Execute AJAX function
}

function sendMess(ajaxIndex,j)
{

	if (!String.prototype.trim) {
		String.prototype.trim=function(){
		    return this.replace(/^\s*|\s*$/g,'');
		}
	}
       response=ajaxObjectArray[ajaxIndex].response;
	response = response.trim();
		if(response == 'sent')
		{
			if(j != -1){
			$('sendform'+j).style.display = 'none';
			$('sentReturn'+j).style.display = 'block';
			countdown1(j);
			}else {
				//alert(j);
				$('sendform').style.display = 'none';
				$('sentReturn').style.display = 'block';
				countdown();
				
				}
		}else 
	   	  {
			  if(j != -1){
			 $('sendform'+j).style.display='none';//hide the form 
			 $('sentReturn'+j).style.display = 'block';
			 $('sentReturn'+j).innerHTML = "Message was not sent!";
			 }else {
				$('sendform').style.display='none';//hide the form 
			 $('sentReturn').style.display = 'block';
			 $('sentReturn').innerHTML = "Message was not sent!";
			 }
		  }
}
//count down
function countdown1(j){
	if(sec == 0){
		$('sentReturn'+j).style.display = 'none';
		$('sendmess'+j).style.display = 'none';
    	$('sendform'+j).style.display='block';
		$('sendform'+j).sendsubject.value="";
		$('sendform'+j).txtmessage.value="";
	}else{
		//alert(j);
	$('sentReturn'+j).innerHTML = "Your message Has been sent!<br>This window will close in "+sec+" seconds.";
	sec--;	
	setTimeout("countdown1('"+j+"')",1000);
	}
}
//count down single form
function countdown(){
	if(sec == 0){
		$('sentReturn').style.display = 'none';
		$('sendmess').style.display = 'none';
    	$('sendform').style.display='block';
		$('sendform').sendsubject.value="";
		$('sendform').txtmessage.value="";
	}else{
		//alert(j);
	$('sentReturn').innerHTML = "Your message Has been sent!<br>This window will close in "+sec+" seconds.";
	sec--;	
	setTimeout("countdown()",1000);
	}
}
var secu = 0;
function opencountdown(ediv){
	if(secu == 5){
	
		switch(ediv){
			case 'hotmail':
						
						show('hotmail');hide('emaildiv');hide('gmail');hide('aol');hide('yahoo');hide('emailctct');$('emailaddress').focus();
						break;
			case 'gmail':
						show('gmail');hide('emaildiv');hide('hotmail');hide('aol');hide('yahoo');hide('emailctct');
						break;
			case 'aol':
						show('aol');hide('emaildiv');hide('gmail');hide('hotmail');hide('yahoo');hide('emailctct');
						break;
			case 'yahoo':
						show('yahoo');hide('emaildiv');hide('gmail');hide('aol');hide('hotmail');hide('emailctct');
						break;
			case 'emailctct':	
						show('emailctct');hide('emaildiv');hide('gmail');hide('aol');hide('yahoo');hide('hotmail');
						break;
		}
		return;
	}else{
		
		switch(ediv){
			case 'hotmail':
						hide('hotmail');hide('gmail');hide('aol');hide('yahoo');hide('emailctct');
						break;
			case 'gmail':
						hide('gmail');hide('hotmail');hide('aol');hide('yahoo');hide('emailctct');
						break;
			case 'aol':
						hide('aol');hide('gmail');hide('hotmail');hide('yahoo');hide('emailctct');
						break;
			case 'yahoo':
						hide('yahoo');hide('gmail');hide('aol');hide('hotmail');hide('emailctct');
						break;
			case 'emailctct':
						hide('emailctct');hide('gmail');hide('aol');hide('yahoo');hide('hotmail');
						break;
		}
		
		var h = secu*25;
		
		$('emaildiv').style.display = "block";
	$('emaildiv').style.height = h+"px";
	if(secu == 3)
			$('emaildiv').innerHTML = "loading...";
	secu++;	
	setTimeout("opencountdown('"+ediv+"')",100);
	}
}
//end ajax sending a message form_user_message.php

//ajax read message

var fileReadMess="../ajx_readMessAjax.php";

function readMessAjax(id)
{
	
       ajaxObjectArray[ajaxObjectArray.length] = new sack();
       var ajaxIndex = ajaxObjectArray.length-1;
       ajaxObjectArray[ajaxIndex].setVar('id',id);
	   
       ajaxObjectArray[ajaxIndex].requestFile  = fileReadMess;
       ajaxObjectArray[ajaxIndex].onCompletion = function()
       {
		   
               sendMess(ajaxIndex)
       };
       // Specify function that will be executed after file has been found
       ajaxObjectArray[ajaxIndex].runAJAX();// Execute AJAX function
}

function readMess(ajaxIndex)
{
	
       response=ajaxObjectArray[ajaxIndex].response;
		if(response != 'read')
		{
			alert("The sender won't know that you read this email!");
		  }
}

//end ajax read message

//ajax delete message

var fileDelMess="../ajx_delMessAjax.php";

function delMessAjax(idm,type)
{
	 	
	   if(!confirm("Are you sure you want to delete this message?")) return;
	   
       ajaxObjectArray[ajaxObjectArray.length] = new sack();
       var ajaxIndex = ajaxObjectArray.length-1;
       ajaxObjectArray[ajaxIndex].setVar('idm',idm);
	  
	   ajaxObjectArray[ajaxIndex].setVar('type',type);
	   
       ajaxObjectArray[ajaxIndex].requestFile  = fileDelMess;
       ajaxObjectArray[ajaxIndex].onCompletion = function()
       {
		   
               DelMess(ajaxIndex,idm)
       };
       // Specify function that will be executed after file has been found
       ajaxObjectArray[ajaxIndex].runAJAX();// Execute AJAX function
}

function DelMess(ajaxIndex,idm)
{
	
       response=ajaxObjectArray[ajaxIndex].response;
		if(response)
		{
			$('del'+idm).innerHTML = "message deleted";
		  }else $('del'+idm).innerHTML = "message not deleted";
}

//end ajax delete message


//check available login name
var fileAvailable="../ajx_availableAjax.php";
function checkAvailableAjax(name){

	 ajaxObjectArray[ajaxObjectArray.length] = new sack();
       var ajaxIndex = ajaxObjectArray.length-1;
       ajaxObjectArray[ajaxIndex].setVar('name',name);
	   
       ajaxObjectArray[ajaxIndex].requestFile  = fileAvailable;
       ajaxObjectArray[ajaxIndex].onCompletion = function()
       {
		   
               checkAvailable(ajaxIndex,name)
       };
       // Specify function that will be executed after file has been found
       ajaxObjectArray[ajaxIndex].runAJAX();// Execute AJAX function
}

function checkAvailable(ajaxIndex,name)
{	
       response=ajaxObjectArray[ajaxIndex].response;
	   	$('available').style.display = "block";
		if(response == 1)
		
		{
			$('available').className = "notav";
			$('available').innerHTML = 'Login <b>'+name+'</b> is not available <img src="/img/x.gif" alt="ok" border="0"  />';
		  }else 
		  {	
		  $('available').className = "av";
		  $('available').innerHTML = 'Login <b>'+name+'</b> is available <img src="/img/checkmark.gif" alt="ok" border="0"  />';
		  }
}
	
	
	
	
