var app_key_id=app_key_id;
var version_number=version_number;
var current_userId=partyId;
var aSectionName=new Array();
var aSectionImg=new Array();

function viewBlogComment(obj) {
	if(navigation==true){
		saveChanges();
	}
	var createDate=$(obj).attr("createDate");
    var userName=$(obj).attr("username");
    var desc=$(obj).attr("fullDesc");
    showComment(createDate,userName,desc);
}


function addBlogcomment() {
       
 var commentdesc=$("#commentdesc").val();
    var errMsg="";
 
    if ((commentdesc==null)||(isBlank(commentdesc)==true))
	{		
			errMsg=errMsg+"Please enter your comment \n"
	}
 	if (commentdesc.length>100)
	{		
			errMsg=errMsg+"Comment Description should not be more than 100 characters \n"
	}
 
 
 if(errMsg!="")
 {
     //var errMsg="Enter your comment~";
     //showAlert(errMsg,'ERROR');
	 //var errMsg="Enter your comment";
	 alert(errMsg);
	 errMsg="";
 }
 else
 {
 var commentrequest='<Blog>'
            +'<ArticleList>'
                +'<article>'
                    +'<articleId>'+document.getElementById("articleId").value+'</articleId>'
                        +'<comment>'
		         +'<commentDesc>'+escape(commentdesc)+'</commentDesc>'
		         +'<createDate>2008-06-12</createDate>'
		         +'<appKeyId>'+app_key_id+'</appKeyId>'
		         +'<version>'+version_number+'</version>'
		         +'<author>'
		            +'<partyId>'+current_userId+'</partyId>'
		            +'<partyTypeId>0</partyTypeId>'
		            +'<appKeyId>'+app_key_id+'</appKeyId>'
		            +'<versionNo>'+version_number+'</versionNo>'
		            +'<isActive>false</isActive>'
		            +'<nameList/>'
		            +'<relationShipList/>'
		            +'<contactsList/>'
		            +'<countryList/>'
		            +'<stateList/>'
		            +'<cityList/>'
		            +'<postalList/>'
		        +'</author>'
		   +'</comment>'
              +'</article>'
           +'</ArticleList>'
        +'</Blog>'; 
		 commentrequest=encodeURIComponent(commentrequest);
		 $.ajax(
		      {
			   type: "POST", url: "../public/blog.htm",data:"mode=addcomment&xml="+commentrequest,dataType: "text",cache: false, success: function (responseText)
			   {
				  window.location.href="../public/blog.htm?mode=viewblog&blogId="+document.getElementById("blogId").value;
			   }
		   });
         
  }
}

function addArticle(id){
	if(navigation==true){
		saveChanges();
	}
	aSectionName=new Array();
    aSectionImg=new Array();
	 window.location.href="../secure/blog.htm?mode=addarticle&blogId="+id;
}

function postArticle(val){
	var errMsg="";
	if(val=='add') {
		if ((document.getElementById('articleName').value==null)||(isBlank(document.getElementById('articleName').value)==true))
		{		
			errMsg=errMsg+"Please enter Article Name \n"
		}
		if ((tinyMCE.get('articleSectionName').getContent()==null)||(isBlank(tinyMCE.get('articleSectionName').getContent())==true))
		{		
			errMsg=errMsg+"Please enter Article Description \n"
		}
		if (tinyMCE.get('articleSectionName').getContent().length>5000)
		{		
			errMsg=errMsg+"Article Description should not be more that 5000 characters \n"
		}
		if(errMsg=="") {
		
		aSectionName[aSectionName.length]=escape(tinyMCE.get('articleSectionName').getContent());
        aSectionImg[aSectionImg.length]=document.getElementById('mediaName0').value.split(".")[0];
		insertArticle();
		}
		else
		{
			alert(errMsg);
			errMsg="";
		}
	}
	else {
		if ((document.getElementById('articleName').value==null)||(isBlank(document.getElementById('articleName').value)==true))
		{		
			errMsg=errMsg+"Please enter Article Name \n"
		}
			if ((tinyMCE.get('articleSectionName').getContent()==null)||(isBlank(tinyMCE.get('articleSectionName').getContent())==true))
		{		
			errMsg=errMsg+"Please enter Article Desccription \n"
		}
		if (tinyMCE.get('articleSectionName').getContent().length>5000)
		{		
			errMsg=errMsg+"Article Description should not be more that 5000 characters \n"
		}
		if(errMsg=="") {		
		aSectionName[aSectionName.length]=escape(tinyMCE.get('articleSectionName').getContent());
        aSectionImg[aSectionImg.length]=document.getElementById('mediaName0').value.split(".")[0];
		$.ajax({type: "GET", url: "../secure/blog.htm?mode=addarticlesection",dataType: "text",cache: false, success: function (responseText)
                       {
                           $("#articleSection").html(responseText);
			   //$("#uploadFrame").attr("src","../secure/addmedia.htm?version=0&appKeyId="+app_key_id+"&versionNo="+version_number);
                           if(document.getElementById("articleSectionName")){
                                tinyMCE.init({
                                mode : "exact",
                                elements : "articleSectionName",
                                theme : "advanced",
                                skin : "o2k7",
                                skin_variant : "silver",
                                plugins : "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras",
                                theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,styleselect,formatselect,fontselect,fontsizeselect",
                                theme_advanced_buttons2 : "cut,copy,paste,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,code,|,insertdate,inserttime,preview",
                                theme_advanced_buttons3 : "justifyleft,justifycenter,justifyright,justifyfull,|,hr,visualaid,|,sub,sup,|,styleprops,moveforward,movebackward,|,charmap,image,iespell,advhr,|,forecolor,backcolor,|,fullscreen,|,newdocument",
                                theme_advanced_toolbar_location : "top",
                                theme_advanced_toolbar_align : "left",
                                theme_advanced_statusbar_location : "bottom",
                                theme_advanced_resizing : true,        
                                content_css : "../tinymce/css/content.css"                  
                                });
                           }
                        }   
		     });
	}
	else {
		alert(errMsg);
		errMsg="";
	}
	}

}


function insertArticle(){
	var blogId=document.getElementById('blogId').value;
	var blogstatus=document.getElementById('blogstatus').value;
	var reqTxt='<Blog><blogId>'+blogId+'</blogId>'
                   +'<myDesc></myDesc>'
                   +'<UserDetail>'
                   +'<partyId>'+current_userId+'</partyId>'
                   +'</UserDetail>'
                    +'<ArticleList>'
                    +'<article>'
                    +'<articleName>'+escape(document.getElementById('articleName').value)+'</articleName>'
                    +'<appKeyId>'+app_key_id+'</appKeyId>'
                    +'<version>'+version_number+'</version>'
					+'<mediaResource>'
                    +'<mediaResourceId></mediaResourceId>'
                    +'</mediaResource>'
                    +'<articleSectionList>';
                    for(i=0;i<aSectionName.length;i++) {    
                       reqTxt = reqTxt+'<articleSection>'
                                +'<articleSectionDesc>'+aSectionName[i]+'</articleSectionDesc>'
                                +'<appKeyId>'+app_key_id+'</appKeyId>'
                                +'<version>'+version_number+'</version>'
                                +'<mediaResource>'
                                +'<mediaResourceId>'+aSectionImg[i]+'</mediaResourceId>'
                                +'</mediaResource>'
                                +'</articleSection>';            
                    }    
                    reqTxt = reqTxt+'</articleSectionList>' 
                    +'</article>'     
                    +'</ArticleList>'
                    +'</Blog>';
                    reqTxt=encodeURIComponent(reqTxt);
					if(blogstatus=='new'){
						$.ajax(
                          {
                            type: "POST", url: "../public/blog.htm",data:"mode=addblogandarticle&xml="+reqTxt,dataType: "text",cache: false, success: function (responseText)
                            {
				              //window.location.href="../public/blog.htm?mode=blog&blogId="+blogId;
							  alert("Your Blog has been added Succesfully.");
							  window.location.href="../public/blog.htm?mode=viewblog&blogId="+parseInt(responseText);
			                }
                          }
                    );
					}
					else {
					$.ajax(
                          {
                            type: "POST", url: "../public/blog.htm",data:"mode=insertarticle&xml="+reqTxt,dataType: "text",cache: false, success: function (responseText)
                            {
				              //showBlog();
							  alert("Your Article has been added Succesfully.");
							  window.location.href="../public/blog.htm?mode=viewblog&blogId="+blogId;
							  
			                }
                          }
                    );
					}
}

var article=0;
var articleId="";

function selectedArticle(obj){ 
		if(navigation==true){
		 // setTimeout("saveChanges();",200);
		 saveChanges();
		}
		navigation=false;
		$("#previousblog").css("display","inline");
		$("#nextblog").css("display","inline");
		var articlecount=document.getElementById('articlecount').value;
        var clickedTd=$(obj).attr("id");
        articleId=clickedTd;
        var pos=0;
         $("li.articlenames > a").each(function ()
         {
         if (parseInt($(this).attr("id"))==clickedTd)
         {
         article=pos;
         }
         pos++;
         });
		 $.ajax(
             {
                type: "GET", url: "../public/blog.htm?mode=viewarticle&articleId="+clickedTd,dataType: "text",cache: false, success: function (responseText)
                 {
				     $("#articleContent").html(responseText);
					  doWordWrap();		  
							  
			      }
              }
        );
		if(article==0){
			$("#previousblog").css("display","none");
		}
		else if(article==(articlecount-1)){
			$("#nextblog").css("display","none");
		}
    
}

function nextArticle() {
	$("#previousblog").css("display","inline");
	if(articleId==""){
		article=document.getElementById('article').value;
	}
	var articlecount=document.getElementById('articlecount').value;
	if(article<articlecount) 
        {
              // if(article==(articlecount-1))
               // article=(articlecount-2);  
            
         var x=$("li.articlenames > a").get(++article);
         var articleid=$(x).attr("id");
         articleId=articleid;
		 	if(article==(articlecount-1)){
				$("#nextblog").css("display","none"); 
			}
			
		 $.ajax(
             {
                type: "GET", url: "../public/blog.htm?mode=viewarticle&articleId="+articleid,dataType: "text",cache: false, success: function (responseText)
                 {
				     $("#articleContent").html(responseText);
					 doWordWrap();		  	  
			      }
               }
          );
         }
}

function previousArticle() {
	$("#nextblog").css("display","inline"); 
	if(articleId==""){
		article=document.getElementById('article').value;
	}
       if(article>=0)
        {
        if(article>0)
            article--;
         var x=$("li.articlenames > a").get(article);
         var articleid=$(x).attr("id");
         articleId=articleid;
		 $.ajax(
             {
                type: "GET", url: "../public/blog.htm?mode=viewarticle&articleId="+articleid,dataType: "text",cache: false, success: function (responseText)
                 {
				     $("#articleContent").html(responseText);
					  doWordWrap();		  
							  
			      }
               }
          );
		 
         if(article==0) {
			 article=0;
			 $("#previousblog").css("display","none"); 
		 }
         
        }
       /* else
        {
			alert(article+"insideelse");
            article=0;
			$("#previousblog").css("display","none"); 
			
        }*/
		
}

function createBlog(){
	window.location.href="../secure/blog.htm?mode=addblog";
}

function addBlog() {
	   
    var errMsg="";
	if ((document.getElementById('blogname').value==null)||(isBlank(document.getElementById('blogname').value)==true))
	{		
		errMsg=errMsg+"Please enter Blog Name \n";
	}
    if ((tinyMCE.get('authorDesc').getContent()==null)||(isBlank(tinyMCE.get('authorDesc').getContent())==true))
	{		
		errMsg=errMsg+"Please enter Your Description \n";
	} else if(tinyMCE.get('authorDesc').getContent().length>5000) {
		errMsg=errMsg+"Author Description should not be more than 5000 characters \n";
	}
	/*if ((document.getElementById('mediaName0').value==null)||(isBlank(document.getElementById('mediaName0').value)==true))
	{		
		errMsg=errMsg+"Please upload Image \n"
	}*/
	 if (document.getElementById('tagId').value=="_" && document.getElementById('tagName').value=="")
	{		
		errMsg=errMsg+"Please select a category\n";
	}
	
	if(document.getElementById('tagId').value=="addTag") {
		if (document.getElementById('tagName').value=="") {
			errMsg=errMsg+"Please add new category\n";
		}
	}
         
        if(errMsg!="") {
            alert(errMsg);
			errMsg="";
        }
        else{        
        var reqTxt='<Blog>'
         +'<blogName>'+escape(document.getElementById('blogname').value)+'</blogName>'
         +'<authorDesc>'+escape(tinyMCE.get('authorDesc').getContent())+'</authorDesc>'
         +'<appKeyId>'+app_key_id+'</appKeyId>'
        +'<version>'+version_number+'</version>'
        +'<TagList>'
		if(document.getElementById('tagId').value=="addTag"){
		reqTxt+='<tag>'
        +'<tagName>'+escape(document.getElementById('tagName').value)+'</tagName>'
        +'</tag>'
		} else {
        reqTxt+='<tag>'
        +'<tagId>'+document.getElementById('tagId').value+'</tagId>'
        +'</tag>'
		}
		reqTxt+='</TagList>'
        +'<ArticleList/>'
        +'<mediaResource>'
        +'<mediaResourceId>'+document.getElementById('mediaName0').value.split(".")[0]+'</mediaResourceId>'
        +'</mediaResource>'
         +'<UserDetail>'
        +'<partyId>'+current_userId+'</partyId>'
        +'<partyTypeId>0</partyTypeId>'
        +'<appKeyId>'+app_key_id+'</appKeyId>'
        +'<versionNo>'+version_number+'</versionNo>'
        +'<isActive>false</isActive>'
        +'<nameList/>'
        +'<relationShipList/>'
        +'<contactsList/>'
        +'<countryList/>'
        +'<stateList/>'
        +'<cityList/>'
        +'<postalList/>'
    +'</UserDetail>'
        +'</Blog>'; 
        reqTxt=encodeURIComponent(reqTxt);
		$.ajax({
                type: "POST", url: "../public/blog.htm",data:"mode=insertblog&xml="+reqTxt,dataType: "text",cache: false, success: function (responseText)
                 {
					 
				   //window.location.href="../secure/blog.htm?mode=addnewarticle";
				   alert("Your Blog is added");
				   window.location.href="../public/blog.htm?mode=viewblog&blogId="+parseInt(responseText);		  
							  
			      }
               }
          );
		}
                  
  }
  
  var navigation=false;
  var articleSectionId;
  var status=false;
  var newArticleSectionId;

function editArticle(id){
	if(navigation==true){
		newArticleSectionId=id;
		//newArticleDesc=document.getElementById('articleDesc'+newArticleSectionId).value;
		status=true;
		saveChanges();
	}
	articleSectionId=id;
	//articleDesc=document.getElementById('articleDesc'+articleSectionId).value;
	//alert(articleDesc);
	$(".articlesection"+id).css("display","inline");
        $(".articlesec"+id).css("display","none");
	$("#previousblog").css("display","none"); 
	$("#nextblog").css("display","none"); 
	$("#BlogComment").css("display","none"); 
	navigation=true;
}

function editShowBlog(){
   var blogId=document.getElementById('blogId').value;    
   location.href=httpUrl+"/secure/blog.htm?mode=editBlog&blogId="+blogId;	
}

function deleteArticleSection(id){    
    if(confirm("Are you sure want to Delete?")){
    	$.ajax({type: "POST", url: "../public/blog.htm",data:"mode=deleteArticleSelection&articleSectionId="+id,dataType: "text",cache: false, success: function (responseText){
              location.reload(true);
              }
              });
    }    
}


function deleteArticle(){
   var articleId=document.getElementById('articleId').value; 
   if(confirm("Are you sure to Delete?")){
    	$.ajax({type: "POST", url: "../public/blog.htm",data:"mode=deleteArticle&articleId="+articleId,dataType: "text",cache: false, success: function (responseText){
              location.reload(true);
              }
              });
    }     
}


function editBlog(){
    var blogId=document.getElementById('blogId').value;
     var errMsg="";
	if ((document.getElementById('blogname').value==null)||(isBlank(document.getElementById('blogname').value)==true)){		
		errMsg=errMsg+"Please enter Blog Name \n"
	}
        if ((tinyMCE.get('authorDesc').getContent()==null)||(isBlank(tinyMCE.get('authorDesc').getContent())==true)){		
		errMsg=errMsg+"Please enter Your Description \n"
	} else if(tinyMCE.get('authorDesc').getContent().length>5000) {
		errMsg=errMsg+"Author Description should not be more than 5000 characters \n";
	}	
	if (document.getElementById('tagId').value=="_" && document.getElementById('tagName').value==""){		
		errMsg=errMsg+"Please select a category\n"
	}  
	
	if(document.getElementById('tagId').value=="addTag") {
		if (document.getElementById('tagName').value=="") {
			errMsg=errMsg+"Please add new category\n";
		}
	}
	
	
        if(errMsg!="") {
            alert(errMsg);
			errMsg="";
        }  else {        
        var reqTxt='<Blog>'
         +'<blogId>'+blogId+'</blogId>'
         +'<blogName>'+escape(document.getElementById('blogname').value)+'</blogName>'
         +'<authorDesc>'+escape(tinyMCE.get('authorDesc').getContent())+'</authorDesc>'
         +'<appKeyId>'+app_key_id+'</appKeyId>'
        +'<version>'+version_number+'</version>'
        +'<TagList>'
		if(document.getElementById('tagId').value=="addTag"){
            reqTxt+='<tag>'
            +'<tagName>'+escape(document.getElementById('tagName').value)+'</tagName>'
            +'</tag>'
		} else {
				reqTxt+='<tag>'
				+'<tagId>'+document.getElementById('tagId').value+'</tagId>'
				+'</tag>'
		}
	reqTxt+='</TagList>'
        +'<ArticleList/>'
        +'<mediaResource>'
        +'<mediaResourceId>'+document.getElementById('mediaName0').value.split(".")[0]+'</mediaResourceId>'
        +'</mediaResource>'
        +'<UserDetail>'
        +'<partyId>'+current_userId+'</partyId>'
        +'<partyTypeId>0</partyTypeId>'
        +'<appKeyId>'+app_key_id+'</appKeyId>'
        +'<versionNo>'+version_number+'</versionNo>'
        +'<isActive>false</isActive>'
        +'<nameList/>'
        +'<relationShipList/>'
        +'<contactsList/>'
        +'<countryList/>'
        +'<stateList/>'
        +'<cityList/>'
        +'<postalList/>'
        +'</UserDetail>'
        +'</Blog>';         
        reqTxt=encodeURIComponent(reqTxt);
		$.ajax({type: "POST", url: "../public/blog.htm",data:"mode=updateblog&xml="+reqTxt,dataType: "text",cache: false, success: function (responseText){                 
                 alert("Your Blog is Updated.");
		 window.location.href="../public/blog.htm?mode=viewblog&blogId="+blogId;
		 }
               });
    }
}

function updateArticle(id){
	navigation=false;
	$("#previousblog").css("display","inline"); 
	$("#nextblog").css("display","inline"); 
	$("#BlogComment").css("display","inline"); 
	if(isBlank(tinyMCE.get('articleDesc'+id).getContent())==true || tinyMCE.get('articleDesc'+id).getContent()==null) {
		alert("Artical Description should not be blank");
	} else if(tinyMCE.get('articleDesc'+id).getContent().length>5000) {
		alert("Atrical Description should not be more than 5000 characters");
	} else {
		if(tinyMCE.get('articleDesc'+id).getContent()==document.getElementById('oldArticleDesc'+id).value && document.getElementById('mediaName'+id).value==document.getElementById('oldImageId'+id).value){
			$(".articlesection"+id).css("display","none");
			$(".articlesec"+id).css("display","inline");
			if(status==true){
				//navigation=true;
				navigation=false;
				status=false;
			}
		}
		else{
		 var articleId=document.getElementById('articleId').value;
		 var resourceId=document.getElementById('mediaName'+id).value.split(".")[0];
				 var reqTxt='<Blog>'
					   +'<blogId></blogId>'
					   +'<UserDetail>'
					   +'<partyId>'+current_userId+'</partyId>'
					   +'</UserDetail>'
					   +'<ArticleList>'
							+'<article>'
							+'<articleSectionList>'
							+'<articleSection>'
							+'<articleSectionDesc>'+escape(tinyMCE.get('articleDesc'+id).getContent())+'</articleSectionDesc>'
							+'<articleSectionId>'+id+'</articleSectionId>'
							+'<appKeyId>'+app_key_id+'</appKeyId>'
							+'<version>'+version_number+'</version>'
							+'<mediaResource>'
							+'<mediaResourceId>'+resourceId+'</mediaResourceId>'
							+'</mediaResource>'
							+'</articleSection>'
							+'</articleSectionList>'
							+'</article>'
						+'</ArticleList>'
						+'</Blog>';
				reqTxt=encodeURIComponent(reqTxt);		
						$.ajax(
							  {
							   type: "POST", url: "../public/blog.htm",data:"mode=editarticle&xml="+reqTxt+"&articleId="+articleId,dataType: "text",cache: false, success: function (responseText)
								{
								// $(".articlesection"+id).css("display","none");
								 //$(".articlesec"+id).css("display","inline");
								 $("#articleContent").html(responseText);
								  doWordWrap();		  
								 alert("Updated Successfully");
								 if(status==true){
									$(".articlesection"+newArticleSectionId).css("display","inline");
									$(".articlesec"+newArticleSectionId).css("display","none");
									//$(".articlesection"+id).css("display","none");
									//$(".articlesec"+id).css("display","inline");
									navigation=true;
									status=false;
								 }
								}
							  }
						);
		}
	}
}

function previousComment(){
	 if(navigation==true){
		saveChanges();
	}
	navigation=false;
     var start=parseInt(document.getElementById("startpos").value)-4;
     var count=parseInt(document.getElementById("countvalue").value);
	 if(start>-4 && start<0){
		 start=0
	 }
     hidePrevNext(count,start,4,'blogCommentPrev1','blogCommentNext1'); 
     hidePrevNext(count,start,4,'blogCommentPrev2','blogCommentNext2');     
     if(start<0)
     {
         alert("No comments to display");
     }
     else
         {
         $.ajax(
             {
                type: "GET", url: "../public/blog.htm?mode=viewcomment&navigation=yes&position="+start,dataType: "text",cache: false, success: function (responseText)
                 {
				     $("#innerBlogComment").html(responseText);
			      }
               }
          );
     }
 }

function nextComment(){
	 if(navigation==true){
		saveChanges();
	 }
	 navigation=false;
     var start=parseInt(document.getElementById("startpos").value)+4;
     var count=parseInt(document.getElementById("countvalue").value);
    hidePrevNext(count,start,4,'blogCommentPrev1','blogCommentNext1'); 
    hidePrevNext(count,start,4,'blogCommentPrev2','blogCommentNext2');
	 if(start>count)
     {
         alert("No comments to display");
     }
     else
         {
         $.ajax(
             {
                type: "GET", url: "../public/blog.htm?mode=viewcomment&navigation=yes&position="+start,dataType: "text",cache: false, success: function (responseText)
                 {
				     $("#innerBlogComment").html(responseText);
							  
			      }
               }
          );
     }
}

function viewBlogHome(){
	window.location.href="../public/blog.htm";
}

function goBack(tagId){
	window.location.href="../public/blog.htm?mode=blogs&tagId="+tagId;
}

function addFavorite() {
    var errMsg="";
    
        if ((document.getElementById('desc').value==null)||(isBlank(document.getElementById('desc').value)==true))
	{		
		errMsg=errMsg+"Please enter Your Description \n"
	}
        if ((document.getElementById('url').value==null)||(isBlank(document.getElementById('url').value)==true))
	{		
		errMsg=errMsg+"Please enter Url \n"
	}
        if ((document.getElementById('label').value==null)||(isBlank(document.getElementById('label').value)==true))
	{		
		errMsg=errMsg+"Please enter Label \n"
	}
        
        if(errMsg!="") {
            //showAlert(errMsg,'ERROR');
			alert(errMsg);
        }
        
        else
        {
        
       var reqTxt='<Blog>'
         +'<blogId>'+document.getElementById('blogId').value+'</blogId>'
         +'<myDesc>'+document.getElementById('desc').value+'</myDesc>'
         +'<url>'+document.getElementById('url').value+'</url>'
         +'<label>'+document.getElementById('label').value+'</label>'
         +'<appKeyId>'+app_key_id+'</appKeyId>'
        +'<version>'+version_number+'</version>'
        +'<TagList/>'
        +'<ArticleList/>'
        +'<UserDetail>'
        +'<partyId>'+current_userId+'</partyId>'
        +'<partyTypeId>0</partyTypeId>'
        +'<appKeyId>'+app_key_id+'</appKeyId>'
        +'<versionNo>'+version_number+'</versionNo>'
        +'<isActive>false</isActive>'
        +'<nameList/>'
        +'<relationShipList/>'
        +'<contactsList/>'
        +'<countryList/>'
        +'<stateList/>'
        +'<cityList/>'
        +'<postalList/>'
        +'</UserDetail>'
        +'</Blog>'; 
       reqTxt=encodeURIComponent(reqTxt);           
  /* $.post("../crossdomain/public/blog", reqTxt,function(data){
alert("Blog is Added as your favorite\n"); 
displayBlog(blogId,'blogPage')
}, "application/atom+xml;type=entry");

}*/   if(document.getElementById('favoriteBlogId').value==document.getElementById('blogId').value){
      		alert("Already you have added this blog as your favorite");
			window.location.href="../public/blog.htm?mode=viewblog&blogId="+document.getElementById('blogId').value;	
	  }
	  else{
		$.ajax(
             {
                type: "POST", url: "../public/blog.htm",data:"mode=addfavorite&xml="+reqTxt,dataType: "text",cache: false, success: function (responseText)
                 {
				     //$("#blogcomments").html(responseText);
					 alert("This blog is added as your favorite");
					window.location.href="../public/blog.htm?mode=viewblog&blogId="+parseInt(responseText);		  
			      }
               }
          );
	  }
}


}

function viewBlogs(tagId,tagName){
	window.location.href="../public/blog.htm?mode=blogs&tagId="+tagId+"&tagName="+tagName;
	/*$.ajax(
             {
                type: "GET", url: "../public/blog.htm?mode=blogs&tagId="+tagId+"&tagName="+tagName,dataType: "text", success: function (responseText)
                 {
				    $("#blogs").html(responseText);
			      }
               }
          );*/
}

function checkTextAreaMaxLength(){
	var value=document.getElementById('articleSectionName').value;
	var length=document.getElementById('articleSectionName').value.length;
		if(length>500){
			alert("Article desc length should be less than 500 characters");
		}
}

function doCancel(id){
	navigation=false;
	document.getElementById('articleDesc'+id).value=document.getElementById('oldArticleDesc'+id).value;
	document.getElementById('mediaName'+id).value=document.getElementById('oldImageId'+id).value;
	$(".articlesection"+id).css("display","none");
    $(".articlesec"+id).css("display","inline");
	$("#previousblog").css("display","inline"); 
	$("#nextblog").css("display","inline"); 
	$("#BlogComment").css("display","inline"); 
}



function saveChanges(){
	//alert(articleDesc);
	//alert(document.getElementById('articleDesc'+articleSectionId).value);
	//if(articleDesc==document.getElementById('articleDesc'+articleSectionId).value){
	//}
	//else{
		if(document.getElementById('articleDesc'+articleSectionId).value==document.getElementById('oldArticleDesc'+articleSectionId).value && document.getElementById('mediaName'+articleSectionId).value==document.getElementById('oldImageId'+articleSectionId).value){
			 navigation=false;
			 doCancel(articleSectionId);
		}
		else{
			 var confirmStaus=confirm("You have made Changes.htm you want to save?");  
			 if(confirmStaus==true){
				 navigation=false;
				updateArticle(articleSectionId);
				
			 }
			 else {
				 navigation=false;
				 doCancel(articleSectionId);
			 }
		}
//	}
}

function checkTextAreaMaxLengthForComments(){
	var value=document.getElementById('commentdesc').value;
	var length=document.getElementById('commentdesc').value.length;
		if(length>100){
			alert("Comment desc length should be less than 100 char");
		}
}

function checkBlogEditStatus(url){
	if(navigation==true){
		saveChanges();
	}
	navigation=false;
	location.href=httpUrl+url   
	
}
function blogComment(startPos,type){    
	$.ajax(
             {
                type: "GET", url: "../public/blog.htm?mode=viewcomment&position="+startPos,dataType: "text",cache: false, success: function (responseText)
                 {
				    $("#blogpopup").html(responseText);                                     
                                        var count=parseInt(document.getElementById("countvalue").value);                                        
                                        if(count!=0) {                                            
                                            hidePrevNext(count,startPos,4,'blogCommentPrev1','blogCommentNext1'); 
                                            hidePrevNext(count,startPos,4,'blogCommentPrev2','blogCommentNext2');
                                        }
					if(type==0){
					    hidePostBlogcomment()	
					}else if(type==1){
					    hideNewBlogcomment();
					}
					addViewBlogComment('blogpopup');
                 }
               }
          );
}
function newBlogcomment(type){
    if(partyId){
        if(type==0) {
            blogComment(0,1)
        }else if(type==1){
            hideNewBlogcomment();
        }
                
    }else {
	alert("Please login to add blog comments");
    }    
}
function hidePostBlogcomment(){
    $("#commentdesc").val("");         
    $("#blogPostComment").css("display","none");    
    $("#blogNewComment").css("display","inline");
}
function hideNewBlogcomment(){
    $("#commentdesc").val("");
    $("#blogPostComment").css("display","inline");    
    $("#blogNewComment").css("display","none");
}
function showPopularArticle(articleId){
	$.ajax(
             {
                type: "GET", url: "../public/blog.htm?mode=popularArticle&articleId="+articleId,dataType: "text", success: function (responseText)
                 {
				   window.location.href="../public/blog.htm?mode=viewblog&blogId="+parseInt(responseText)+"&articleId="+articleId;
			      }
               }
          );
}

function addFavoriteBlog(){ 
		if(navigation==true){
		 saveChanges();
		}
		$.ajax(
             {
                type: "GET", url: "../secure/blog.htm?mode=favoriteblog",dataType: "text", success: function (responseText)
                 {
				   window.location.href="../public/blog.htm?mode=viewblog&blogId="+parseInt(responseText);	
			      }
               }
          );
}

function changeBlogImage(){
	 $("#changeBlogImage").css("display","none");    
     $("#editBlogImage").css("display","inline");
}

function cancelBlogImageChange(){
	 $("#changeBlogImage").css("display","inline");    
     $("#editBlogImage").css("display","none");
}

function editBlogImage(){
	var blogId=document.getElementById('blogId').value;
	var blogImageId=document.getElementById('mediaName0').value.split(".")[0];
	if(document.getElementById('mediaName0').value==document.getElementById('oldImageId0').value){
		$("#changeBlogImage").css("display","inline");    
        $("#editBlogImage").css("display","none");
	} else {
		$("#changeBlogImage").css("display","inline");    
        $("#editBlogImage").css("display","none");
		$.ajax(
             {
                type: "GET", url: "../secure/blog.htm?mode=changeBlogImage&imageId="+blogImageId+"&blogId="+blogId,dataType: "text", success: function (responseText)
                 {
					 alert("Your Photo has been changed");
				   window.location.href="../public/blog.htm?mode=viewblog&blogId="+blogId;	
			      }
               }
          );
	}
	
}

function showAddTagForBlog() {
	if($("#tagId").val()=="addTag") {
		$(".blogTag").removeAttr("style");
	} else {
		$(".blogTag").css("display","none");
	}
}
