var obj_timer = null;
var interval = 60000;
var morezeoles ="";
var morebutton=1;
//var xmlHttp = null;

function test(){
 alert("testfun");
}

function fbs_click(id,title) {
    var url="http://www.zeole.com/s.php?z="+id;
    u=location.href;
    t=document.title;
    window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(url)+'&t='+encodeURIComponent(title),'sharer','toolbar=0,status=0,width=626,height=436');
    return false;
}

function getAjax(){
    //    var xmlHttp;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    try
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    catch (e)
      {
      alert("Your browser does not support AJAX!");
      return false;
      }
    } //End Catch

  }//EndCatch
  return   xmlHttp;
}

//xmlHttp = getAjax();
 function zeoleMouseClick() {
     //    alert(user );
    var user = document.zeoleform.uname.value;
    if( user == "" ){
	//alert("redirecting to login");
	window.location = "http://zeole.com/PHP/login.php";
	return;
    }
    var container=document.getElementById("zingcontainer");
    container.style.height=630;
    var loc_name = document.getElementById('loc_name').value;
    container.innerHTML='<div>\
                         <div class="zeoleinputheader">Write to the people of '+loc_name+'</div><br>\
                         <div class="zingboxtext"><p><b>Title (Optional)</b></p> </div> \
                         <textarea class="inputbox" name="title" id="title"></textarea> \
                          <div class="zingboxtext"><p><b> Optional image or video </b></p></div>\
                          <div class="no_br"><b> Image </b> <input type="radio" name="img_or_vdo" onclick="load_image()"/></div>\
                          <div class="no_br"><b> Video </b> <input type="radio" name="img_or_vdo" onclick="load_video()"/>\
                          <div class="no_br"><b> No image or video </b> <input type="radio" name="img_or_vdo" onclick="unload_image_or_video()" checked/>\
                          </div><br>\
                          <div name="img_or_vdo" id="img_vdo_div"> </div>\
                           <div class="zingboxtext"><p><b>Zeole (1400 Characters) </b></p></div>\
                           <textarea class="inputbox inputboxlong" name="zeole" id="zeole" onKeyUp="limitText(this.zeoleform.zeole,this.zeoleform.countdown,5000);" \
                           onKeyUp="limitText(this.zeoleform.zeole,this.zeoleform.countdown,25000);" ></textarea> \
	      </div>\
              <br/><div class="zingboxtext">Category (Example: Sports, football, world cup)<textarea class="inputbox inputboxshort"  id="tags" name="tags"></textarea></div>\
	      <div  style="height:100px;width500px;">\
	           <br>\
                   <input type="button" class="button_example" style="left:150px;" id="shout" value="Zeole It!" onclick="sendzing();" />\
        <input type="button" class="button_example" id="shoutcancel"  value="Cancel" style="left:250px;" onclick="minimizeZing();" /><br/> </div>\
      <div class="clearboth"></div>';
    var obj=document.getElementById("zeole");
    obj.style.height=300;
    obj.value = "";
    obj.select();
    document.zeoleform.title.focus();
    load_zeole_draft();
}

function minimizeZing(){
    var container=document.getElementById("zingcontainer");
    container.style.height=40;

    var loc_name = document.getElementById('loc_name').value;
    container.innerHTML='<input class="box-start" id="zing" \
                  onclick="zeoleMouseClick();" value="Write to the people of '+loc_name+'..."/>';

    var obj=document.getElementById("zeole");
    obj.style.height=30;
}

function minimizeComment(id) {
    //alert("minimizeComment");
    var container=document.getElementById("commentcontainer"+id);
    container.style.height=25;
    //container.innerHTML='<input type="submit" value="Add Comment" class="button_comment" onclick="maximizeComment('+id+');return false;"/>';
    container.innerHTML="";
    //if ( obj_timer == null){
    //obj_timer= self.setInterval("ajaxFunction()",interval);
	//alert(obj_timer);
    //}

}

function maximizeComment(id) {
    var user =  document.zeoleform.uname.value;
    //    var user = user_obj.value;
    //alert(user);

    if( user == "" ){
	window.location = "/PHP/login.php";
        return;
    }

    //if (obj_timer){
    //clearInterval(obj_timer);
    //obj_timer = null;
    //} 
    //alert(obj_timer);
    //alert(id);
    
    var container=document.getElementById("commentcontainer"+id);
    container.style.height=300;

    container.innerHTML="<br><br>Posts your comments <br> <textarea type='text'  class='inputbox commentinput' id='commentTextarea"+id+"'></textarea>\
        <br><br>								\
        <a href='javascript:void(0);' class='addcomment' onclick='sendComment("+id+");'>Post</a> \
        <a href='javascript:void(0);' class='hidecomments' onclick='minimizeComment("+id+");'>Cancel</a><br>";
    var obj=document.getElementById("commentTextarea"+id);
    obj.style.height=200;
}

function sendComment(id){
	var zing_id = id;
	var result = "";
	//alert(id);
	result = document.getElementById("commentTextarea"+id).value;
	minimizeComment(id);
	
	result=commentreplace(result);

	if (obj_timer == null){
	    obj_timer= self.setInterval("ajaxFunction()",interval); 
	    //alert(obj_timer);
	}

	var params = "zeole_id="+zing_id+"&comment=" +encodeURIComponent(result);

	var xmlHttp = getAjax();
	xmlHttp.onreadystatechange=function() {
	    if(xmlHttp.readyState==4) {
		var ob=document.getElementById("commentcontainer"+id);
		ob.style.height=25;
		//ob.innerHTML='<input type="submit" value="Add Comment" class="button_comment" onclick="maximizeComment('+id+');return false;"/>';
		ob.innerHTML='';
	    }
	}

	var url = "/PHP/serveraddcomment.php?"+new Date().getTime();
	xmlHttp.open("POST",url,true);
	xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xmlHttp.send(params);
	// WARNING: any code after send will hang firefox!
	//document.getElementById("commentTextarea").value = "";
	//settimeout("minimizeComment()",1000);
	//self.setTimeout("ajaxFunction()",500);
	var maxc="showComment("+id +")";
	self.setTimeout(maxc,1500);
}


function sendzeoleComment(id){
	var zing_id = id;
	var result = "";
	//alert(id);
	result = document.getElementById("commenttextbox").value;

	result=commentreplace(result);
	var params = "zeole_id="+zing_id+"&comment=" +encodeURIComponent(result);

	var xmlHttp = getAjax();
	xmlHttp.onreadystatechange=function() {
	    if(xmlHttp.readyState==4) {
		var ob=document.getElementById("commentcontainer"+id);
		ob.style.height=25;
		//ob.innerHTML='<input type="submit" value="Add Comment" class="button_comment" onclick="maximizeComment('+id+');return false;"/>';
		ob.innerHTML='';
	    }
	}

	var url = "/PHP/serveraddcomment.php?"+new Date().getTime();
	xmlHttp.open("POST",url,true);
	xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xmlHttp.send(params);
	document.getElementById("commenttextbox").value = "";
	setTimeout("location.reload(true);",2000);
}



function replace( zingText ){
    var replaced_string = "";
    replaced_string = zingText.replace(/</g,"&lt;");
    replaced_string = replaced_string.replace(/>/g,"&gt;");
    replaced_string = replaced_string.replace(/'/g,"&#39;");
    replaced_string = replaced_string.replace(/[\s\t\r\n\v\f]+$/,"");
    //    replaced_string = replaced_string.replace(/\n/g,"<br>");
    return replaced_string;
}


function commentreplace( zingText ){
    var replaced_string = "";
    replaced_string = zingText.replace(/</g,"&lt;");
    replaced_string = replaced_string.replace(/>/g,"&gt;");
    replaced_string = replaced_string.replace(/[\s\t\r\n\v\f]+$/,"");
    replaced_string = replaced_string.replace(/'/g,"&#39;");
    replaced_string = replacelink(replaced_string);
    replaced_string = replaced_string.replace(/\n/g,"<br>");
    return replaced_string;
}

function replacelink( zing ){
    var index;
    var result="";
    var rest="";
    var spaceChar;
    var link;

index = linkStart ( zing );

	while ( index != -1 ) {
	        //store eveything before the link
		result += zing.substring(0,index) ;

		//Extract rest of the sentence
		rest = zing.substring( index );

		//Now to Extract the link from this link ends with a blank line 
		spaceChar = linkEnd ( rest );

		if( spaceChar != -1) {
			link = rest.substring(0,spaceChar);
		}
		else{
			link = rest;
			spaceChar = -1;
		}

		//Create anchor tag
		if( rest.substring(0,3)  == "www" ){
			link = "<a target=\"_blank\" href='http://" + link + "'>" + link + "</a>";
		}
		else{
			link = "<a target=\"_blank\" href='" + link + "'>" + link + "</a>";
		}
		result += link ;

		//one link sucessfully processed
		//Start with the next link if its present.
		if( spaceChar == -1 ){
		    zing = "";
		    break;
		}
		
		//New Search String
		zing = rest.substring(spaceChar);
		index = linkStart( zing );
	}

	result += zing;

	return result;
}

function updateZingDiv ( title, zing ){
    zing = zing.replace(/\n/g,"<br>");
    var zingbox = document.getElementById("zings");
    var user = document.zeoleform.uname.value;
    
    var newzing =  "<div class='zmessagenew'>\
                          <div class='messagetitle'>" + title + "</div> \
		          <div class='message'><br> " + zing + " <br><br></div> \
		          <div class='nameAndTime'>\
			      <div class='name'> " + user + "</div>\
			      <div class='time'>0 minuites ago</div>\
		          </div>\
                          <div class='zingseparator'></div>\
	            </div>";

    //    var newzing = "<div class='zmessagenew'><div class='nameAndTime'><span class='name'> " + user +"</span><span class='time'> 0 minuites ago</span></div><div class='message'> <p>" + zing + "</p> </div></div> ";

    zingbox.innerHTML = newzing + zingbox.innerHTML;
}


function linkStart( data ) {
    var startindex = -1;
    var indexhttp = -1;
    var indexwww = -1;
    indexhttp = data.search("http");
    indexwww = data.search("www");
    if (indexhttp < indexwww ){
	startindex = (indexhttp != -1 )? indexhttp: indexwww;
    }
    else {
	startindex = (indexwww != -1 )? indexwww: indexhttp;
    }

    return startindex;
}

function linkEnd( data ) {
    var endindex = -1;
    var indexspace = -1;
    var indexenter = -1;
    indexspace = data.search(" ");
    indexenter = data.search("\n");
    if (indexenter < indexspace ){
	endindex = (indexenter != -1 )? indexenter: indexspace;
    }
    else {
	endindex = (indexspace != -1 )? indexspace: indexenter;
    }

    return endindex;
}

function sendzing(){
	var index=0;
	var spaceChar = 0;
	var link = "";
	var oldindex = 0;
	var zing = "";
	var result = "";
	var afterLink = "";

	update_cookies();
	zing = replace(document.zeoleform.zeole.value);
	//zing = document.zeoleform.zing.value;
	index = linkStart ( zing );
	//	alert(zing);
	while ( index != -1 ) {
	        //store eveything before the link
		result += zing.substring(0,index) ;

		//Extract rest of the sentence
		rest = zing.substring( index );

		//Now to Extract the link from this link ends with a blank line 
		spaceChar = linkEnd ( rest );

		if( spaceChar != -1) {
			link = rest.substring(0,spaceChar);
		}
		else{
			link = rest;
			spaceChar = -1;
		}

		//Create anchor tag
		if( rest.substring(0,3)  == "www" ){
			link = "<a target=\"_blank\" href='http://" + link + "'>" + link + "</a>";
		}
		else{
			link = "<a target=\"_blank\" href='" + link + "'>" + link + "</a>";
		}
		result += link ;

		//one link sucessfully processed
		//Start with the next link if its present.
		if( spaceChar == -1 ){
		    zing = "";
		    break;
		}
		
		//New Search String
		zing = rest.substring(spaceChar);
		index = linkStart( zing );
	}

	result += zing;
	result = result.replace(/\n/g,"<br />");
	
	//result = document.zeoleform.zing.value;
	var titlestr=replace(document.zeoleform.title.value);
	var tagsstr=replace(document.zeoleform.tags.value);
	var video = null;
	if (document.getElementById("video")){
	    video = document.getElementById("video").value;
	}
	
	var params = "zeole=" + encodeURIComponent(result) + "&title=" +encodeURIComponent(titlestr) + "&tags=" + encodeURIComponent(tagsstr);
	if (video){
	    params = params + "&video=" + encodeURIComponent(video);
	}
	
	//kanna
	document.getElementById("zeole").value = result;
	document.forms["zeoleform"].submit();
	
	/*	
	var xmlHttp = getAjax();
	var url = "uploader.php?"+new Date().getTime();
	var url = "/PHP/serveraddzeoledetail.php?"+new Date().getTime();
	xmlHttp.open("POST",url,true);
	xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xmlHttp.send(params);
	*/
	document.getElementById("zeole").value = "";
	self.setTimeout("ajaxFunction()",1000);
	minimizeZing();
}

function delete_zing(id){
    var user = document.zeoleform.uname.value;
    var userConfirm = false;
    var confirmstring = user + " are you sure you want to delete this zeole?";

    userConfirm = confirm(confirmstring,"Delete Warning");

    if( userConfirm == false ){
	return false;
    }

    var params = "zeole_id=" + id;
    var xmlHttp = getAjax();
    var url = "/PHP/serverdeletezing.php?"+new Date().getTime();
    xmlHttp.open("POST",url,true);

    xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    xmlHttp.send(params);

    self.setTimeout("ajaxFunction()",500);
    ajaxFunction();

    return true;
}


function ajaxFunction(){
    var user = document.zeoleform.uname.value;
    var loc_id = document.getElementById('loc_id').value;
    var loc_name = document.getElementById('loc_name').value;
    
    var input_str ='<input class="box-start" id="zing" \
                  onclick="zeoleMouseClick();" value="Write to the people of '+loc_name+'..."/>';

    var zeolebox="<div class='section'>\
	<form action='/PHP/serveraddzeoledetail.php' method='post' name='zeoleform' id='form' enctype='multipart/form-data'>\
	<div id='zingcontainer' >" +  input_str + "</div>\
        <input type='hidden' value='"+ user +"' name='uname' id = 'uname'/>\
        <input type='hidden' value='"+ loc_id +"' name='loc_id' id = 'loc_id'/>\
        <input type='hidden' value='"+ loc_name +"' name='loc_name' id = 'loc_name'/>\
       </form></div>";


    //alert('2');
    //  document.statusbar(); //displays statusbar 
    //alert("abc");
    var  xmlHttp = getAjax();
  xmlHttp.onreadystatechange=function()
    {
    if(xmlHttp.readyState==4 && xmlHttp.status == 200)
      {
	  //	  alert(xmlHttp.responseCode);
	  //	  alert(morezeoles);
      var ob=document.getElementById("zings");
      var more="<div name='morediv'><a class='More' href='javascript:zeolenext();'>More ...</a></div>";
      //bug here. new post will push the 15th zeole out.
      ob.innerHTML =  zeolebox+xmlHttp.responseText + morezeoles;
      if( morebutton == 1 ){
	  ob.innerHTML = ob.innerHTML + more;
      }
      }
    }
  xmlHttp.open("POST","/PHP/serverside.php",true);
  xmlHttp.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
  xmlHttp.setRequestHeader("Pragma", "no-cache");
  xmlHttp.setRequestHeader("Expires", "-1");
  xmlHttp.send(null);
}

function logout(){
    window.location="/PHP/logout.php";
}


function draw(){
         var value= "<tr valign='top'>                                                     \
         <td bgcolor='rgb(120, 160, 160)' width='80'>                                       \
             <table width='80' cellspacing='0' cellpadding='0' height='80'>                  \
             <tr bgcolor='#FFFFFF'>                                                           \
             <td><img src='/IMAGES/PROFILES/$image' width='80' height='80'></td>         \
             </tr>                                                                              \
             </table>                                                                           \
         </td>                                                                                  \
         <td bgcolor='#C3D9FF' width='800'>                                                     \
             <table width='100%' border='0' cellspacing='0' cellpadding='3' height='80%'>       \
             <tr valign='top'>                                                                  \
                 <td align='right'>                                                             \
                 <font face='Verdana, Arial, Helvetica, sans-serif' size='1'>                   \
                   Posted by $username on $time                                                 \
                 </font>                                                                        \
                 </td> \
             </tr>            \
             <tr valign='center'> \
                 <td>      \
                     $message   \
                 </td>     \
             </tr>    \
             </table>    \
         </td>           \
     </tr>";
     var ob=document.getElementById("zings");
     ob.innerHTML   = value;

}

function get_client_location(){
    document.getElementbyId('Country').innerHTML="Initial";
    if(google.loader.ClientLocation)
	{
	    visitor_lat = google.loader.ClientLocation.latitude;
	    visitor_lon = google.loader.ClientLocation.longitude;
	    visitor_city = google.loader.ClientLocation.address.city;
	    visitor_region = google.loader.ClientLocation.address.region;
	    visitor_country = google.loader.ClientLocation.address.country;
	    visitor_countrycode = google.loader.ClientLocation.address.country_code;
	    document.getElementbyId("Country").innerHTML="if";
	}
    else
	{
	    // ClientLocation not found or not populated
	    // so perform error handling
	    document.getElementbyId('Country').innerHTML="Error";
	}
}

function showcommentBox(id){

    // var divbox=document.getElementbyId('comdiv-940');
    //divbox.innerHTML="<textarea rows='4' cols='40'></textarea>";
        alert(id);

}



function registerpopup(){
   
   var container=document.getElementById("popupcontainer");
   var popupbox=document.getElementById("popup");

   var registerpop='<div id="login">\
      <div class="auth_box">\
	<form name="login" action="/PHP/register.php" method="post">	\
	  <h2>New user registration</h2>\
	  Email_id &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp<input type="text" name="email_id" class="login"/>\
          <br>	  <br>\
	  Preferred name&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp <input type="text" name="username" class="login"/>\
	  <br>   <br>\
	  Password  &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp <input type="password" name="password1" class="login"/>\
	  <br>   <br>\
	  Retype Password &nbsp&nbsp <input type="password" name="password2" class="login"/>\
	  <br>   <br>\
	  Your home city &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp<input type="text" name="location" class="login"/>\
	  <br>   <br>\
	  <input type="submit" value="Register" class="button_2"/>\
	  <br>\
	  <br>\
	</form>\
      </div>\
 <a href="#" style="position:absolute;left:30px;top:5px" onclick="loginpopup()">Login</a>\
 |\
 <a href="#" style="position:absolute;left:100px;top:5px" onclick="registerpopup()">Register</a>\
 <a href="#" style="position:absolute;right:15px;top:5px" onclick="hide()">close</a>';



   popupbox.style.visibility="visible";
   container.innerHTML=registerpop;
   //   alert("inside");

 }


   function loginpopup(){
   var container=document.getElementById("popupcontainer");
   var popupbox=document.getElementById("popup");
var loginpop='<div id="login">	\
      <div class="auth_box">\
      <div class="loginheading">Login</div><br>\
        <form name="login" action="/PHP/authenticate.php" method="post">\
	  <div class="login_text">Email ID  &nbsp; </div>\
	  <input type="text" name="email" class="login"/>\
	  <br>\
	  <div class="login_text">Password </div>\
	  <input type="password" name="password" class="login"/>\
	  <br>\
	  <span align=center> \
	  <input type="submit" value="Login" class="button_example"/>\
	  </span>\
          <br>\
	  <br>\
	  <a href="#" onclick="registerpopup()"> Click here to Register as new user</a>\
       </form>\
    </div>\
 </div> \
 <a href="#" style="position:absolute;left:30px;top:5px" onclick="loginpopup()">Login</a>\
 |\
 <a href="#" style="position:absolute;left:100px;top:5px" onclick="registerpopup()">Register</a>\
 <a href="#" style="position:absolute;right:15px;top:5px" onclick="hide()">close</a>';

   popupbox.style.visibility="visible";
   container.innerHTML=loginpop;
   //   alert("inside");
 }


   function hide(){


   var popupbox=document.getElementById("popup");
   popupbox.style.visibility="hidden";

   }


function zeoleprev(){

    var zeoles=document.getElementsByName("zeolediv");
    var firstzeoleId = zeoles[0].id;
    getprevzeoles(firstzeoleId);
}

function zeolenext(){

    var zeoles=document.getElementsByName("zeolediv");
    var lastzeoleId = zeoles[zeoles.length - 1 ].id;
    lastzeoleId = lastzeoleId.substr(4);
    getnextzeoles(lastzeoleId);
}


function checkfrontPage(){

    var zeoles=document.getElementsByName("zeolediv");
    var lastzeoleId = zeoles[zeoles.length - 1 ].id;
    if( lastzeoleId >= maxzeoleId){

	alert("frontPage");
    }

}


function getprevzeoles( zeoleId )
{

    var  xmlHttp = getAjax();
  xmlHttp.onreadystatechange=function()
    {
    if(xmlHttp.readyState==4)
      {
      var ob=document.getElementById("zings");
      var response = trim(xmlHttp.responseText);
      if(response != "" ){
	  ob.innerHTML =  xmlHttp.responseText + ob.innerHTML;
      }
      }
    }
  var params="operation=prev&id="+zeoleId;
  xmlHttp.open("POST","/PHP/getnextprevzeoles.php",true);
  xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  xmlHttp.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
  xmlHttp.setRequestHeader("Pragma", "no-cache");
  xmlHttp.setRequestHeader("Expires", "-1");
  xmlHttp.send(params);
  //  self.setTimeout("checkfrontPage()",500);
  //self.setTimeout("checkfrontPage()",500);

}


function getnextzeoles(zeoleId)
{

    var  xmlHttp = getAjax();
  xmlHttp.onreadystatechange=function()
    {
    if(xmlHttp.readyState==4)
      {
	  if( xmlHttp.responseText == ""){
	      morebutton=0;
	  }	  
      var ob=document.getElementById("zings");
      morezeoles = morezeoles + xmlHttp.responseText;
      ajaxFunction();
      }
    }

  var params="operation=next&id="+zeoleId;
  xmlHttp.open("POST","/PHP/getnextprevzeoles.php",true);
  xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  xmlHttp.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
  xmlHttp.setRequestHeader("Pragma", "no-cache");
  xmlHttp.setRequestHeader("Expires", "-1");
  xmlHttp.send(params);

}

function hideComment(id){
    var numcomment=document.getElementById("numcom_"+id);
    var count=numcomment.value;
    var commentview=document.getElementById("viewcom_"+id);
    commentview.innerHTML = "<a class='showcomments' onclick='showComment(" + id + ");'>View "+count+" Comments</a>";
    var comment_container=document.getElementById("co-"+id);
    comment_container.innerHTML = "";
}

function showComment(id){

    if (obj_timer){
        clearInterval(obj_timer);
        obj_timer = null;
    }

    var commentview=document.getElementById("viewcom_"+id);
    commentview.innerHTML = "<a  href='javascript:void(0);' class='hidecomments' onclick='hideComment("+id +");'>Hide Comments</a>";
    var container=document.getElementById("commentcontainer"+id);
    var  xmlHttp = getAjax();
    xmlHttp.onreadystatechange=function()
	{
    
	    if(xmlHttp.readyState==4)
		{
		    var comment_container=document.getElementById("co-"+id);
		    comment_container.innerHTML = xmlHttp.responseText;

		}
	}

    var params="cid="+id;
    xmlHttp.open("POST","/PHP/getcomments.php",true);
    xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
    xmlHttp.setRequestHeader("Pragma", "no-cache");
    xmlHttp.setRequestHeader("Expires", "-1");
    xmlHttp.send(params);

}


function getuserzeole(uid)
{
    //  document.statusbar(); //displays statusbar 
    //alert("abc");
    var  xmlHttp = getAjax();
  xmlHttp.onreadystatechange=function()
    {
    if(xmlHttp.readyState==4)
      {
	  //	  alert(morezeoles);
      var ob=document.getElementById("zings");
      //bug here. new post will push the 15th zeole out.
      ob.innerHTML =  xmlHttp.responseText + morezeoles;
      }
    }
  url="/PHP/getuserzeoles.php/?uid="+uid;
  xmlHttp.open("GET",url,true);
  xmlHttp.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
  xmlHttp.setRequestHeader("Pragma", "no-cache");
  xmlHttp.setRequestHeader("Expires", "-1");
  xmlHttp.send(null);
}

function slideshow() {
    PicCurrentNum++;
    if (PicCurrentNum == howMany) {
	PicCurrentNum = 0;
    }
    PicCurrent.src = Pix[PicCurrentNum];
    //$('ChangingPix').morph('src = PicCurrent.src;');
    document["ChangingPix"].src = PicCurrent.src;
}


function startPix() {
    setTimeout("slideshow()",0);
    setInterval("slideshow()", 10000);
}



function getRecomendation(id){
    var zing_id = id;
    var result = "";
    //alert(id);
    result = document.getElementById("recomendation");

    var params = "zid="+zing_id;

    var xmlHttp = getAjax();
    xmlHttp.onreadystatechange=function() {
	if(xmlHttp.readyState==4) {
	    var ob=document.getElementById("recomendation");
	    ob.innerHTML=xmlHttp.responseText;
	}
    }

    var url = "/PHP/getRecomendation.php?";
    xmlHttp.open("POST",url,true);
    xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    xmlHttp.send(params);
}


function setCookie(c_name,value,expiredays)
{
  var exdate=new Date();
  exdate.setDate(exdate.getDate()+expiredays);
  document.cookie=c_name+ "=" +escape(value)+
    ((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function getCookie(c_name)
{
  if (document.cookie.length>0)
    {
      c_start=document.cookie.indexOf(c_name + "=");
      if (c_start!=-1)
	{
	  c_start=c_start + c_name.length+1;
	  c_end=document.cookie.indexOf(";",c_start);
	  if (c_end==-1) c_end=document.cookie.length;
	  return unescape(document.cookie.substring(c_start,c_end));
	}
    }
  return "";
}

function load_zeole_draft(){  
    var cur_loc_id = document.getElementById("loc_id").value;
    //alert("cur_loc_id "+cur_loc_id);

    var draft_loc_id = getCookie("draft_loc_id");
    if (draft_loc_id == cur_loc_id){


	var title_draft = getCookie("title");
	var container_t=document.getElementById("title");
	container_t.value=title_draft;
	
	var zeole_draft = getCookie("zeole");
	var container_z=document.getElementById("zeole");
	container_z.value=zeole_draft;
	
	var tags_draft = getCookie("tags");
	var container_tags=document.getElementById("tags");
	container_tags.value=tags_draft;
	
	
	var video_draft = getCookie("video");
	if (document.getElementById("video")){
	    var container_v=document.getElementById("video");
	    container_v.value=video_draft;
	}
    }
}

function update_cookies(){
    var loc_id = document.getElementById("loc_id").value;
    setCookie("draft_loc_id",loc_id,1);
    
    var title_draft=document.getElementById("title").value;
    setCookie("title",title_draft,1);
    
    var zeole_draft=document.getElementById("zeole").value;
    setCookie("zeole",zeole_draft,1);
    
    var tag_draft=document.getElementById("tags").value;
    setCookie("tags",tag_draft,1);
    
    if (document.getElementById("video")){
	var video_draft=document.getElementById("video").value;
	setCookie("video",video_draft,1);
    }
}

function load_image(){
    var container=document.getElementById("img_vdo_div");
    container.innerHTML='<div class="zingboxtext" <p><b>Image upload <br>\
                        Max size 100KB <br>\
                        Max Width,height:500 x 500px <br></b></p></div>\
                        <input type="hidden" name="MAX_FILE_SIZE" value="200000" />\
                        <input name="uploadedfile"  type="file" /><br /><br/>';

    var zc=document.getElementById("zingcontainer");
    zc.style.height=750;
}

function load_video(){
    var container=document.getElementById("img_vdo_div");
    container.innerHTML='<div class="zingboxtext"><p>\
                    <b>Embedded video (Copy the embedded link from youtube)</b></p> \
                    </div> <!-- zingboxtext -->    \
                    <input type="text" class="inputbox" name="video" id="video"/>';
    var zc=document.getElementById("zingcontainer");
    zc.style.height=700;
}

function unload_image_or_video(){
    var container=document.getElementById("img_vdo_div");
    container.innerHTML='';

    var zc=document.getElementById("zingcontainer");
    zc.style.height=630;
}


function limitText(limitField, limitCount, limitNum) {
    
  if (limitField.value.length > limitNum) {
    limitField.value = limitField.value.substring(0, limitNum);
  } else {
    limitCount.value = limitNum - limitField.value.length;
  }
}


function morebutton(){
    var zeoles=document.getElementsByName("zeolediv");
    var num = zeoles.length;
    var morediv=document.getElementsByName("morediv");

    if( num >= 15 ){
        morediv[0].innerHTML="<a class='More' href='javascript:zeolenext();'>More ...</a>";
    }
    else{
        morediv[0].innerHTML="";
    }

}

