///////////////////// common_js.js///////////////////////////////////////
String.prototype.trim = function() {
  return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
    return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
    return this.replace(/\s+$/,"");
}
/////////////////////// js_blog_function.js///////////////////////////////////
function CheckDraft( DraftID ){
     new Ajax.Updater('',JsSiteVar + 'check_draft_blog.php?request=Ajax&draft_id=' + DraftID,
		   {
		   asynchronous:true,
		   evalScripts:true,
		   parameters:Form.serialize('manage_blog'),
		   requestHeaders:['X-Update', 'ajax'],
		   onComplete:showResponseCheckDraft
		   }
	   );
 }
function showResponseCheckDraft(originalRequest) {
    //put returned XML in div
    var tmp=originalRequest.responseText;
    if( tmp != "-1" ){
	   if(  confirm( "Are you sure want to Overwrite" )){
	       location.href = JsSiteVar + 'restore.php?draft_id=' + tmp;
	   }
	}
  }

function AddTOFav( BlogID, divid ){
	GetbAjaxLoader(divid);
     new Ajax.Updater('',JsSiteVar + 'add_to_favourite.php?request=AJAX&blog_id=' + BlogID,
		   {
		   asynchronous:true,
		   evalScripts:true,
		   parameters:Form.serialize('manage_blog'),
		   requestHeaders:['X-Update', 'ajax'],
		   onComplete:showResponseFav
		   }
	   );
	   setTimeout('BlockbAjaxLoader()',500);
 }

 function AddTOblogFav( BlogID, divid ){
 	GetbAjaxLoader(divid);
     new Ajax.Updater('',JsSiteVar + 'add_to_favourite.php?request=AJAX&blog_id=' + BlogID,
		   {
		   asynchronous:true,
		   evalScripts:true,
		   parameters:Form.serialize('manage_blog'),
		   requestHeaders:['X-Update', 'ajax'],
		   onComplete:showResponseblogFav
		   }
	   );
	   setTimeout('BlockbAjaxLoader()',500);
 }

function showResponseFav(originalRequest) {
    //put returned XML in div
   var tmp=originalRequest.responseText.split('|');
    new_id=tmp[0];
    $('DivFav_' + tmp[0]).innerHTML = tmp[1];
    //$('blog_post_autosave').value='false';
}

function showResponseblogFav(originalRequest) {
    //put returned XML in div
   var tmp=originalRequest.responseText.split('|');
    new_id=tmp[0];
    $('DivFav').innerHTML = tmp[1];
    //$('blog_post_autosave').value='false';
}

function callquick_jump(blog_parent1, blog_child1)
{
	//alert("hi");
	at_attach_quickjump(blog_parent1, blog_child1, "hover", "y", "pointer");

}

function set_value(status_set,frmTypeName)
{
	if( frmTypeName == 'add'){
	document.add_blog.setmsg.value="true";
	 	 document.add_blog.post_status.value=status_set;
	 	 if(status_set=="publish")
		{
			 document.add_blog.publish_post.value="publish";
		}
		else if(status_set=="save")
		{
			document.add_blog.save_post.value="save";
		}
		document.add_blog.submit();

	}else if( frmTypeName == 'edit'){
	document.edit_blog.setmsg.value="true";
		 document.edit_blog.post_status.value=status_set;
		 if(status_set=="publish")
		{
			 document.edit_blog.publish_post.value="publish";
		}
		else if(status_set=="save")
		{
			document.edit_blog.save_post.value="save";
		}
		document.edit_blog.submit();
	}

}
function checkForm(){
	if( document.getElementById( "name" ).value == "" ){
	   document.getElementById( "name" ).focus()
	   alert( "Please Enter Your Name" );
	   return false;
	}
	if( document.getElementById( "user_email" ).value == "" ){
	   alert( "Please Enter Your Email" );
	   document.getElementById( "user_email" ).focus()
	   return false;
	}
	if( document.getElementById( "to_email" ).value == "" ){
	   alert( "Please Enter Your Friend's Email" );
	   document.getElementById( "to_email" ).focus()
	   return false;
	}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function AjaxBlogListing( RecordType,Page,FormName,AjaxPage){
	if( RecordType == 'publish'){
	  document.getElementById('div_p').style.display = "block";
	  document.getElementById('div_d').style.display = "none";
	  document.getElementById('div_t').style.display = "none";
   }else if( RecordType == 'draft'){
	  document.getElementById('div_p').style.display = "none";
	  document.getElementById('div_d').style.display = "block";
	  document.getElementById('div_t').style.display = "none";
   }else if( RecordType == 'trash'){
	  document.getElementById('div_p').style.display = "none";
	  document.getElementById('div_d').style.display = "none";
	  document.getElementById('div_t').style.display = "block";
   }else if( RecordType == 'favourite'){
		document.getElementById('div_p').style.display = "none";
		document.getElementById('div_d').style.display = "none";
		document.getElementById('div_t').style.display = "block";
   }
   new Ajax.Updater('',JsSiteVar + 'ajax_blog_listing.php?request=Ajax&record_type=' + RecordType + "&page=" + Page + "&ajax_page=" + AjaxPage ,
		   {
			   asynchronous:true,
 			   evalScripts:true,
			   parameters:Form.serialize(FormName),
			   requestHeaders:['X-Update', 'ajax'],
			   onComplete:AjaxBlogListingshowResponse
		   }
	   );

 }
function AjaxBlogListingshowResponse(originalRequest) {
    //put returned XML in div
  var tmp=originalRequest.responseText;
	// alert( tmp )
	if( originalRequest.status == 200){
 	  $('DivAjaxListing').innerHTML = tmp;
	}else{
 	   $('DivAjaxListing').innerHTML = "Loading...";
	}
}
//////////////////////////////////////////// default ajax Listing////////////////////////////////////
function DefaultAjaxListing( ReqAction,ReqOrder,ReqChar,Page ,AjaxPage){
  //  alert( Page )
	new Ajax.Updater('',JsSiteVar + 'ajax_default_listing.php?request=AJAX&action=' + ReqAction + "&order=" + ReqOrder + "&char=" + ReqChar + "&page=" + Page + "&ajax_page=" +  AjaxPage,
		   {
		   asynchronous:true,
		   evalScripts:true,
		   parameters:Form.serialize('manage_blog'),
		   requestHeaders:['X-Update', 'ajax'],
		   onComplete:showDefaultAjaxListing
		   }
	   );
 }
function showDefaultAjaxListing(originalRequest) {
    //put returned XML in div
    var tmp=originalRequest.responseText.split('|');
   // alert( tmp )
	$('DivAjaxListing').innerHTML = tmp;
    //$('blog_post_autosave').value='false';
}

//////////////////////////////////////////// Delete Blog Entry Using AJAX AND Populated Blog List///////////////////////////////
var RecordTypeGlobal = '';
var PageGlobal = '';
var FormNameGlobal = '';
var AjaxPageGlobal = '';
function DeleteRecordEntry( FileName,BlogID,RecordType,Page,FormName,AjaxPage ){
  //  alert( Page )
 	RecordTypeGlobal = RecordType;
	PageGlobal = Page;
	FormNameGlobal = FormName;
    AjaxPageGlobal = AjaxPage;
	new Ajax.Updater('',FileName + '?request=AJAX&blog_id=' + BlogID + "&record_type=" + RecordType,
		   {
		   asynchronous:true,
		   evalScripts:true,
		   parameters:Form.serialize('manage_blog'),
		   requestHeaders:['X-Update', 'ajax'],
		   onComplete:DeleteBlogAjax
		   }
	   );
 }
function DeleteBlogAjax(originalRequest) {
    //put returned XML in div
    var tmp=originalRequest.responseText.split('|');
    $('DivAjaxListing').style.display = "block"
	$('DivAjaxListing').innerHTML = tmp;
   AjaxBlogListing( RecordTypeGlobal,PageGlobal,FormNameGlobal,AjaxPageGlobal)
   //$('blog_post_autosave').value='false';
}

function shoveblog(site_url,blogid,type)
{
	if(!pagedisable){
		url="http://"+site_url+"/shove/add_shove.php?media_id="+blogid+"&type="+type;
		var myAjax = new Ajax.Updater(
				{success: 'shoveblog_'+blogid},
				url,
				{
					method: 'get',
					evalScripts:true,
					onFailure: reportError
				});
	}
}

////////////////////////////////////// custom title/url request.////////////////////////
function showHideEditModeCustomRequest( CurrentName  ){
   TRName = document.getElementById(CurrentName);
   if( TRName.style.display == "none"){
      TRName.style.display = "block";
   }else{
   	  TRName.style.display = "none"	;
   }
}
function submitTitleCustomRequestForm( TitleID ){
    document.getElementById( "custom_title_id" ).value = TitleID;
   document.manage_blog.submit();
}
function submitTitleForm( TitleID ){
    document.getElementById( "custom_title_id" ).value = TitleID;
    document.manage_blog.submit();
}
///////////////////blog_details.js////////////////////////
function ShowablogCommentBox( DivName ){
	DivObj = document.getElementById( DivName );
    document.getElementById( "div_post_comment").style.display = "none";
    document.getElementById( "DivPostedCommentMessage").style.display = 'none';
    if( DivObj.style.display == 'none'){
		document.getElementById( "div_post_comment").style.display = "block";
	 	DivObj.style.display = 'block';
	}else{
		document.getElementById( "div_post_comment").style.display = "none";
		DivObj.style.display = 'none';
	}
 	//$('comment_operation_message').style.display = "none";
}

 // Replaces all instances of the given substring.
 String.prototype.replaceAll = function(
	 strTarget, // The substring you want to replace
	 strSubString // The string you want to replace in.
	 ){
	 var strText = this;
	 var intIndexOfMatch = strText.indexOf( strTarget );
	  
	 // Keep looping while an instance of the target string
	 // still exists in the string.
	 while (intIndexOfMatch != -1){
	 // Relace out the current instance.
	 strText = strText.replace( strTarget, strSubString )
	  
	 // Get the index of any next matching substring.
	 intIndexOfMatch = strText.indexOf( strTarget );
	 }
	  
	 // Return the updated string with ALL the target strings
	 // replaced out with the new substring.
	 return( strText );
 }

var ShowCommentBlogID = '';
function PostablogComment( BlogID,ActionType,EditCommentMsg ){
 	ShowCommentBlogID = BlogID;
	var CommentTitle = "";
	var CommentComment = "";
	var processRequest = true;
	 $('comment_operation_message').style.display = "block";
 	  if( ActionType == 'add' ){
	     CommentTitle  = document.getElementById( "comment_title" ).value;
		 CommentComment = document.getElementById( "comment_comment" ).value;
		 CommentComment =  CommentComment.replaceAll( "+", "_|-|_" );	 
		// alert(CommentComment);
		 
		if( CommentTitle == "" ||  CommentTitle == ""){
			processRequest = false;
			//$('comment_operation_message').innerHTML = "Please Enter Required Field";
		}
		/*if( document.getElementById( "add_coment" ).checked == true){
			CommentAddChk =  document.getElementById( "add_coment" ).value;
		}else{*/
			CommentAddChk = 0 ;
		//}
		if( document.getElementById( "email_add_coment" ).checked == true){
			CommentAddEmailChk =  document.getElementById( "email_add_coment" ).value;
		}else{
			CommentAddEmailChk = 0 ;
		}
		URLQueryStr = JsSiteVar +   "post_comment.php?request=AJAX&blog_id="+BlogID + "&title=" + CommentTitle + "&comment=" + CommentComment + "&add_comment=" + CommentAddChk + "&add_email=" + CommentAddEmailChk + "&action_mode=add";
 		processRequest = false;
 		new Ajax.Updater('',URLQueryStr,
		   {
		   asynchronous:true,
		   evalScripts:true,
		   parameters:Form.serialize('manage_blog'),
		   requestHeaders:['X-Update', 'ajax'],
		   onComplete:showResponsePostablogComment
		   }
	   );

	}else if( ActionType == 'edit' ){
		CommentTitle  = document.getElementById( "comment_title_" + BlogID ).value;
		CommentComment = document.getElementById( "comment_comment_" + BlogID ).value;
		CommentComment =  CommentComment.replaceAll( "+", "_|-|_" );
		//alert( CommentComment.replaceAll( "+", "_|-|_" ) );
		
		if( CommentTitle == "" ||  CommentTitle == ""){
   		    processRequest = false;
		    $('comment_operation_message').style.display = "block";
		    //$('comment_operation_message').innerHTML = "Please Enter Required Field";
		}

		$('comment_operation_message').style.display = "block";
 		URLQueryStr = JsSiteVar +   "post_comment.php?request=AJAX&blog_id="+BlogID + "&title=" + CommentTitle + "&comment=" + CommentComment +  "&action_mode=edit";
  		new Ajax.Updater('',URLQueryStr,
		   {
		   asynchronous:true,
		   evalScripts:true,
		   parameters:Form.serialize('manage_blog'),
		   requestHeaders:['X-Update', 'ajax'],
		   onComplete:showResponsePostablogComment
		   }
	   );
 	}
}

function showResponsePostablogComment(originalRequest) {
	//alert("hi");
    //put returned XML in div
 	//document.getElementById( "comment_title" ).value = "";
	document.getElementById( "comment_comment" ).value = "";

	var tmp=originalRequest.responseText.split( "!@#$%" );
 	if( tmp[1] == 'Edit'){
	  //DivnameEdit = "div_edit_" + tmp[0];
 	  //$(DivnameEdit).style.display = "none";
	$('comment_operation_message').style.display = "block";
	$('comment_operation_message').innerHTML =  tmp[4];
	document.getElementById( "td_comment_title_" + tmp[0] ).innerHTML = tmp[2];
	document.getElementById( "td_comment_description_" + tmp[0] ).innerHTML = tmp[3];
	document.getElementById( "div_edit_comment_box_" + tmp[0] ).style.display = 'none';
	}else if(tmp[1] == 'EditFailed'){
	    //DivnameEdit = "div_edit_" + tmp[0];
 	  //$(DivnameEdit).style.display = "none";
	$('comment_operation_message').style.display = "block";
	$('comment_operation_message').innerHTML =  tmp[4];
	}else{
		//document.getElementById( "div_comment_box" ).style.display = 'none';

		//document.getElementById( "comment_title" ).value = '';
		document.getElementById( "comment_comment" ).value = '';
		//document.getElementById( "add_coment" ).checked = false;
		document.getElementById( "email_add_coment" ).checked = false;
		document.getElementById( "divCommentCounter").innerHTML = tmp[1];
		document.getElementById( "comment_operation_message" ).innerHTML = tmp[2];
 		//$('DivPostedCommentMessage').innerHTML = tmp[1];

 		//alert(tmp[0]);

		$('div_comment_box_' +  ShowCommentBlogID ).innerHTML = tmp[0];
		//$('blog_post_autosave').value='false';
   }

	//ShowCommentAjaxList( ShowCommentBlogID );
}
//////////////////////////////////// all_blog_details_function.js////////////////////////////////////
var BlogIDForCommmentLIst = '';
function ShowaCommentBox( DivName ){
	DivObj = document.getElementById( DivName );
	SplitName = DivName.split( "_" );
	if( DivObj.style.display == 'none'){
         DivObj.style.display = 'block';
	     document.getElementById( "div_post_comment_" + SplitName[ ( SplitName.length ) - 1 ] ).style.display = 'block';
      }else{
         DivObj.style.display = 'none';
         document.getElementById( "div_post_comment_" + SplitName[ ( SplitName.length ) - 1 ] ).style.display = 'none';
	  }
}

function PostComments_blog( BlogID,ActionType,Message,BlogIDNew  ){

	BlogIDForCommmentLIst = BlogID;
    BlogIDForCommmentLIstNew = BlogIDNew;
      //alert( BlogIDForCommmentLIstNew )
      var sendToServer = true;
      if( ActionType == 'add' ){
            CommentTitle  = document.getElementById( "comment_title_" + BlogID ).value;
            CommentComment = document.getElementById( "comment_comment_" + BlogID ).value;
            CommentComment =  CommentComment.replaceAll( "+", "_|-|_" );
            CommentComment =  CommentComment.replaceAll( "\n", "<br />" );
			///alert( CommentComment.replaceAll( "+", "_|-|_" ) );
            /*if( document.getElementById( "add_coment_" + BlogID ).checked == true){
              CommentAddChk =  document.getElementById( "add_coment_" + BlogID ).value;
            }else{*/
              CommentAddChk = 0 ;
            //}
            if( document.getElementById( "email_add_coment_" + BlogID ).checked == true){
                  CommentAddEmailChk =  document.getElementById( "email_add_coment_" + BlogID ).value;
             }else{
               CommentAddEmailChk = 0 ;
             }
            if( CommentTitle == "" ){
                  document.getElementById( "comment_title_" + BlogID ).focus();
                  sendToServer = false;
            }
            if( CommentComment  == "" ){
                  document.getElementById( "comment_comment_" + BlogID ).value;
                  sendToServer = false;
            }
            if( sendToServer  ){
            URLQueryStr = JsSiteVar + "post_comment.php?request=AJAX&blog_id="+BlogID + "&title=" + CommentTitle + "&comment=" + CommentComment + "&add_comment=" + CommentAddChk + "&add_email=" + CommentAddEmailChk + "&action_mode=add";
            }else{
               $('DivPostedCommentMessage_' + BlogIDForCommmentLIst).innerHTML ="Please Enter Required Field";//tmp[2];
            }
      }else if( ActionType == 'edit' ){
            CommentTitle  = document.getElementById( "comment_title_" + BlogID ).value;
            CommentComment = document.getElementById( "comment_comment_" + BlogID ).value;
           
			//alert( CommentComment.replaceAll( "+", "_|-|_" ) );
            if( CommentTitle == "" ){
                  document.getElementById( "comment_title_" + BlogID ).focus();
                  sendToServer = false;
            }
            if( CommentComment  == "" ){
                  document.getElementById( "comment_comment_" + BlogID ).value;
                  sendToServer = false;
            }
            ////////////////////////////////////////////////////////////////////////////////
			 CommentComment =  CommentComment.replaceAll( "\n", "<br />" );
            //document.getElementById( "td_comment_title_" + BlogID ).innerHTML = CommentTitle;
          document.getElementById( "td_comment_description_" + BlogID ).innerHTML = CommentComment;
           CommentComment =  CommentComment.replaceAll( "+", "_|-|_" );
          
            //////////////////////////////////////////////////////////////////////////////////////
            if( sendToServer  ){
            //$("DivPostedCommentMessage_" +  BlogIDForCommmentLIstNew).innerHTML = "";
            URLQueryStr = JsSiteVar + "post_comment.php?request=AJAX&blog_id="+BlogID + "&title=" + CommentTitle + "&comment=" + CommentComment +  "&action_mode=edit";
            }else{
             $('div_edit_message_comment_box' ).innerHTML = "Please Enter Required Field";
            }

      }//alert( URLQueryStr  );
      if( sendToServer  ){
            new Ajax.Updater('',URLQueryStr,
                     {

                     asynchronous:true,
                     evalScripts:true,
                     parameters:Form.serialize('manage_blog'),
                     requestHeaders:['X-Update', 'ajax'],
                     onComplete:showResponsePostComment
                     }
				);
		 }
 }

function showResponsePostComment(originalRequest) {
    //put returned XML in div
      //alert( originalRequest.responseText )
      //CommentComment =  CommentComment.replaceAll( "+", "_|-|_" );
      var tmp=originalRequest.responseText.split( "!@#$%" );
          
      if( tmp[1] == 'Edit'){
             DivnameEdit = "div_edit_comment_box_" + BlogIDForCommmentLIst;
          $(DivnameEdit).style.display = "none";
            $('div_edit_message_comment_box'  ).innerHTML = 'Comment Edited';
          $('DivPostedCommentMessage_' + BlogIDForCommmentLIstNew ).innerHTML = "";
          //$('div_comment_box_' +  BlogIDForCommmentLIst ).innerHTML = tmp[3];
         // $('DivPostedCommentMessage_' + BlogIDForCommmentLIst).style.display = 'none';
      }else{
            //document.getElementById( "div_comment_box" ).style.display = 'none';

            //document.getElementById( "comment_title_" + BlogIDForCommmentLIst ).value = '';
            document.getElementById( "comment_comment_" + BlogIDForCommmentLIst ).value = '';
            //document.getElementById( "add_coment_" + BlogIDForCommmentLIst ).checked = false;
            document.getElementById( "email_add_coment_" + BlogIDForCommmentLIst ).checked = false;
            document.getElementById( "divCommentCounter_" + BlogIDForCommmentLIst).innerHTML = tmp[1];
            $('DivPostedCommentMessage_' + BlogIDForCommmentLIst).innerHTML ="Comment Saved";//tmp[2];
            $('div_comment_box_' +  BlogIDForCommmentLIst ).innerHTML = tmp[0];
            //$('blog_post_autosave').value='false';
            //alert( "ELSE  " + tmp[0] + " " + tmp[1]  + " " +tmp[2] )
   }
}

function DeleteBlogComment( BlogID,DivName){
 //alert( 'delete_blog_coment.php?request=AJAX&blog_comment_id=' + BlogID )
  if( confirm( "Are you sure want to delete ?" ) ){
	new Ajax.Updater('DivPostedCommentMessage',JsSiteVar + 'delete_blog_coment.php?request=AJAX&blog_comment_id=' + BlogID,
		   {
			   asynchronous:true,
			   evalScripts:true,
			   parameters:Form.serialize('manage_blog'),
			   requestHeaders:['X-Update', 'ajax'],
			   onComplete:showResponseDeleteBlog
		   }
	);
 	$(DivName).innerHTML = '';
  }
 }
function showResponseDeleteBlog(originalRequest) {
    //put returned XML in div
    var tmp=originalRequest.responseText.split( "|" );
	$('divCommentCounter_' +  tmp[0]).innerHTML = tmp[1]
	$('DivPostedCommentMessage').innerHTML = tmp[1] ;
    //$('blog_post_autosave').value='false';
  }
  /***************DISPLAY EDIT MODE**********/
function EditBlogComment( DivName ) {
  ShowaCommentBox( DivName )
}
function OpenPOPUpWin( ID ){
    newwindow=window.open(JsSiteVar + "send_to_friend.php?id="+ID,'send_to_friend','height=300,width=460');
}
////////////////////////////////////////////////////////Comment post LIsting //////////////////////////////////
function ShowCommentAjaxList( BlogID ){

	new Ajax.Updater('',JsSiteVar + 'comment_listing.php?request=AJAX&blog_id=' + BlogID,
		   {
		   asynchronous:true,
		   evalScripts:true,
		   parameters:Form.serialize('manage_blog'),
		   requestHeaders:['X-Update', 'ajax'],
		   onComplete:showResponseShowCommentAjaxList
		   }
	   );
 }

function showResponseShowCommentAjaxList( originalRequest ) {
    //put returned XML in div
 	var tmp=originalRequest.responseText;
	$('div_comment_box_' + BlogIDForCommmentLIst ).innerHTML = tmp;
}

//////////////////////////////////////////////////////////////////////////////////////////////////
function DeleteBlogPost( FileName,BlogID,RecordType,FormName){
   //  alert( Page )
 	$('blog_post_listing_'+BlogID).style.display = 'none';
	new Ajax.Updater('',FileName + '?request=AJAX&blog_id=' + BlogID + "&record_type=" + RecordType,
		   {
		   asynchronous:true,
		   evalScripts:true,
		   parameters:Form.serialize('manage_blog'),
		   requestHeaders:['X-Update', 'ajax'],
		   onComplete:DeleteBlogAjax
		   }
	   );
 }

/////////////////////create/edit blog function /////////////////////////////////////////////////
function SubmitForm(FrmName,URL ){
	document.getElementById( FrmName ).action = URL;
	document.getElementById( FrmName ).submit();
}
// ***** blog quick jump *****
function at_attach_quickjump(parent, child, showtype, position, cursor)
{
  var p = document.getElementById(parent);
  var c = document.getElementById(child);

  p["at_parent"]     = p.id;
  c["at_parent"]     = p.id;
  p["at_child"]      = c.id;
  c["at_child"]      = c.id;
  p["at_position"]   = position;
  c["at_position"]   = position;

  quickjump_at_show_aux(p.id, c.id);
  c.style.position   = "absolute";
  c.style.visibility = "visible";
  c.style.display = "block";

  if (cursor != undefined) p.style.cursor = cursor;

  switch (showtype)
  {
    case "click":
      p.onclick     = at_attach_click_quickjump;
      p.onmouseout  = at_attach_hide_quickjump;
      c.onmouseover = at_attach_show_quickjump;
      c.onmouseout  = at_attach_hide_quickjump;
      break;
    case "hover":
      p.onmouseover = at_attach_show_quickjump;
      p.onmouseout  = at_attach_hide_quickjump;
      c.onmouseover = at_attach_show_quickjump;
      c.onmouseout  = at_attach_hide_quickjump;
      break;
  }
}
function quickjump_at_show_aux(parent, child)
{
  var p = document.getElementById(parent);
  var c = document.getElementById(child );
  pos_x = findPosX(p);

  var top  = (c["at_position"] == "y") ? p.offsetHeight+0 : 0;
  var left = (c["at_position"] == "x") ? p.offsetWidth +2 : 10;

  for (; p; p = p.offsetParent)
  {
    top  += p.offsetTop;
    //left += p.offsetLeft;
  }
  left = pos_x-185;
  top = top + 10;
  c.style.position   = "absolute";
  c.style.top        = top +'px';
  c.style.left       = left+'px';
  c.style.visibility = "visible";
}
function at_attach_hide_quickjump()
{
  var p = document.getElementById(this["at_parent"]);
  var c = document.getElementById(this["at_child" ]);

  c["at_timeout"] = setTimeout("document.getElementById('"+c.id+"').style.visibility = 'hidden'", 333);
}
function at_attach_click_quickjump()
{
  var p = document.getElementById(this["at_parent"]);
  var c = document.getElementById(this["at_child" ]);

  if (c.style.visibility != "visible") quickjump_at_show_aux(p.id, c.id); else c.style.visibility = "hidden";
  return false;
}
function at_attach_show_quickjump()
{
  var p = document.getElementById(this["at_parent"]);
  var c = document.getElementById(this["at_child" ]);

  quickjump_at_show_aux(p.id, c.id);
  clearTimeout(c["at_timeout"]);
}
function findPosX(obj){
	var curleft = 0;

	if (obj.offsetParent){
		while(1){
			curleft+=obj.offsetLeft;
			if (!obj.offsetParent){break}
			 obj=obj.offsetParent;
		 }

	}else if(obj.x){curleft+=obj.x}
	return curleft;
}

function findPosY(obj){
	var curtop = 0;
	if (obj.offsetParent){
		while(1){
			curtop+=obj.offsetTop;
			if (!obj.offsetParent){break}
			 obj=obj.offsetParent;
		 }
	}else if(obj.y){curtop+=obj.y}
	return curtop;
}
function checkdraft(flag)
{
	if(document.drafts.draft_id.value==""){
          alert("You must a select draft to edit");
          return false;
    }
    else
    {
    	document.location.href="edit_blog.php?blog_id="+document.drafts.draft_id.value+"&type=draft";
    }
}
function checkdrafttrash(flag)
{
	if(document.drafts.draft_id.value==""){
          alert("You must a select draft to move to trash");
          return false;
    }
    else
    {
    	document.location.href="delete_blog.php?blog_id="+document.drafts.draft_id.value+"&record_type=draft&flag_blog="+flag;
    }
}
function checkdraftrestore(flag)
{
	if(document.trashes.trash_id.value==""){
          alert("You must select a draft entry from trash to restore");
          return false;
    }
    else
    {
    	document.location.href="restore.php?blog_id="+document.trashes.trash_id.value+"&flag_blog="+flag;
    }
}
function checkdraftdelete(flag)
{
	if(document.trashes.trash_id.value==""){
          alert("You must select a draft entry from trash to delete");
          return false;
    }
    else
    {
    	document.location.href="delete_blog_from_trash.php?blog_id="+document.trashes.trash_id.value+"&flag_blog="+flag;
    }
}
function checkdraftdeleteall(flag)
{
	var result =confirm("Are you sure you want to empty your trash folder");
	if(result==true)
		document.location.href="clear_trash.php?flag_blog="+flag;
}

function show_published(el)
{
  			document.getElementById(el).style.display = "block";
 			document.getElementById('draftEntries').style.display = "none";
			document.getElementById('trashEntries').style.display = "none";
}
function show_drafts(el)
{
  			document.getElementById(el).style.display = "block";
 			document.getElementById('publishedEntries').style.display = "none";
			document.getElementById('trashEntries').style.display = "none";
}
function show_trash(el)
{
  			document.getElementById(el).style.display = "block";
 			document.getElementById('publishedEntries').style.display = "none";
			document.getElementById('draftEntries').style.display = "none";
}


///////////////////create_blog.js///////////////////////////
function AutocreateSaveDraft(){
    tinyMCE.triggerSave();
  if($('description').value.trim() != '') {
    new Ajax.Updater('autoSaveMessage',JsSiteVar + 'create_blog.php?request=Ajax&dummy='+ Math.random(), {asynchronous:true, evalScripts:true, parameters:Form.serialize('add_blog'), requestHeaders:['X-Update', 'ajax'], onComplete:showResponsecreate});
  }
}

function createperiodicalUpdate() {
      new PeriodicalExecuter(AutocreateSaveDraft,60);
}

function showResponsecreate(originalRequest) {
    //put returned XML in div
//     alert( originalRequest.responseText )

	//alert( originalRequest.responseText );
	 var tmp=originalRequest.responseText.split('|');
	new_id=tmp[0];
    $('draftId').value=new_id;
    $('autoSaveMessage').innerHTML = tmp[1];
    //$('blog_post_autosave').value='false';
  }
/////////////////////////////////////////////////////////////////////////////////////////////////////////

////////////////////////////edit_blog_function.js//////////////////////////
function AutoSaveDraft(){
   tinyMCE.triggerSave();
  if($('description').value.trim() != '') {
    new Ajax.Updater('autoSaveMessage',JsSiteVar + 'edit_blog.php?request=Ajax', {asynchronous:true, evalScripts:true, parameters:Form.serialize('edit_blog'), requestHeaders:['X-Update', 'ajax'], onComplete:showResponse});
  }
}

function periodicalUpdate() {
      new PeriodicalExecuter(AutoSaveDraft,60);
}

function showResponse(originalRequest) {
    //put returned XML in div
  // alert( originalRequest.responseText )

   var tmp=originalRequest.responseText.split('|');
    new_id=tmp[0];
    $('draftId').value=new_id;
    $('autoSaveMessage').innerHTML = tmp[1];
    //$('blog_post_autosave').value='false';
  }

function GetbAjaxLoader(ajaxdivid)
{

	var b = document.getElementById(ajaxdivid);
	var i = document.getElementById(ajaxdivid);

	var a = document.getElementById('ajax_loading');
	var l = document.getElementById(ajaxdivid);

	var top  = (a["at_position"] == "y") ? i.offsetHeight+0 : 0;
  	var left = (a["at_position"] == "x") ? i.offsetWidth +2 : 10;

	pos_x = findPosX(l);
	pos_y = findPosX(i);

	for (; i; i = i.offsetParent)
	{
	 top  += i.offsetTop;
	 left += i.offsetLeft;
	}

	left = pos_x + 100;
	top = top ;

	a.style.position   = "absolute";
    a.style.top        = top +'px';
    a.style.left       = left+'px';
	a.style.visibility= "visible";
	a.style.display = "block";
}

function BlockbAjaxLoader()
{
	var a = document.getElementById("ajax_loading");
	var b = document.getElementById('notesDiv');
	if(b!=null){
		a.style.visibility= "hidden";
		a.style.display = "none";
		//b.style.backgroundColor='white';
		b.style.filter='alpha(opacity=110)';
		b.style.opacity='1'; /* Safari, Opera */
		b.style.MozOpacity='1'; /* FireFox */
		b.disabled = false;
	}
}
function callattach_blog_shove(menu_shove_parent1,sample_attach_shove_child1)
{
	//alert(sample_attach_shove_child1);	
	at_attach(menu_shove_parent1, sample_attach_shove_child1, "hover", "y", "pointer");

}
function callattach_shove_type()
{
	at_attach("menu_shove_parent", "sample_attach_shove_child", "hover", "y", "pointer");
	
}
/////////////////////////////////////////////////////////////////////////////////////
