// JavaScript Document
var i='';
var http_request = false;
   function makePOSTRequest(url, parameters,from) {
   //alert("url="+url);alert("parameters="+parameters);//alert("from="+from);
      http_request = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
         	// set type accordingly to anticipated content type
            //http_request.overrideMimeType('text/xml');
            http_request.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }
      
	  switch(from)
	  {
		  case 'registration':
		  	http_request.onreadystatechange = postCustomerRegistration;
			break;
		  case 'login':
		    http_request.onreadystatechange = postCustomerLogin;
		  	break;
		  case 'login_using':
		    http_request.onreadystatechange = postCustomerLoginUsing;
		  	break;
		case 'link':
		    http_request.onreadystatechange = getSubmittedLinkAjax;
		  	break;	
		case 'save_a_link':
		    http_request.onreadystatechange = saveSubmittedLinkAjax;
		  	break;	
		case 'image':
		    http_request.onreadystatechange = getSubmitAImage;
		  	break;
		case 'save_a_image':
		    http_request.onreadystatechange = saveAImage;
		  	break;
		case 'video':
		    http_request.onreadystatechange = getSubmitAVideo;
		  	break;
		case 'save_a_video':
		    http_request.onreadystatechange = saveAVideo;
		  	break;
		case 'save_comments':
		    http_request.onreadystatechange = saveComments;
		  	break;
		case 'save_comments1':
		    http_request.onreadystatechange = saveComments1;
		  	break;
		case 'save_comments_from_bookmarking':
		    http_request.onreadystatechange = saveCommentsFromBookmarking;
		  	break;
		case 'post_discussion':
		    http_request.onreadystatechange = postDiscussion;
		  	break;
		case 'send_email_user':
		    http_request.onreadystatechange = sendEmailUserAjax;
		  	break;
		case 'send_messege_user':
		    http_request.onreadystatechange = sendMessegeUserAjax;
		  	break;
		case 'forgot_pswd':
			http_request.onreadystatechange = forgotPswd;
			break;
	  }
      
      http_request.open('POST', url, true);
      http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      http_request.setRequestHeader("Content-length", parameters.length);
      http_request.setRequestHeader("Connection", "close");
      http_request.send(parameters);
   }

   function postCustomerRegistration() {
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
			var result = http_request.responseText;
			switch(result)
			{
				case '1':
					document.getElementById('emp_reg_email_id').innerHTML='E-Mail Id Exists';
					document.getElementById('emp_reg_user_name').innerHTML='Username Exists';
					document.getElementById('reg_ajax_loader').style.visibility='hidden';
					break;
				case '2':
					document.getElementById('emp_reg_email_id').innerHTML='E-Mail Id Exists';
					document.getElementById('reg_ajax_loader').style.visibility='hidden';
					break;
				case '3':
					document.getElementById('emp_reg_user_name').innerHTML='Username Exists';
					document.getElementById('reg_ajax_loader').style.visibility='hidden';
					break;
				case '0':
					//location.href=root_url;
					alert("You will get a confirmation mail shortly. Please click on the link in the mail to activate your account.");
					window.location.reload();
					break;
			}
         } else {
            alert('There was a problem with the request.');
         }
      }
   }
   function postCustomerLogin() {
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
           var result = http_request.responseText;
			switch(result)
				{
					case '1':
						document.getElementById('login_ajax_loader').style.visibility='hidden';
						document.getElementById('login_invalid_data').innerHTML='Invalid Username/E-Mail Id or Password';
						break;
					case '0':
						window.location.reload();
						break;
				}
         } else {
            alert('There was a problem with the request.');
         }
      }
   }
   
   function postCustomerLoginUsing() {
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
           var result = http_request.responseText;
			switch(result)
				{
					case '1':
						document.getElementById('login_using_ajax_loader').style.visibility='hidden';
						document.getElementById('login_using_invalid_data').innerHTML='Invalid Username/E-Mail Id or Password';
						break;
					case '0':
						window.location.reload();
						break;
				}
         } else {
            alert('There was a problem with the request.');
         }
      }
   }
   
   
   function postDiscussion() {
      if (http_request.readyState == 4) {
         if(http_request.status==200)
		 {
           var result = http_request.responseText;
		    var resultArr = result.split("~sep~");
			//alert(resultArr.length);
			if(resultArr.length > 1){
				alert(resultArr[1]);
				window.location=resultArr[0];
			}else{
				alert(result);				
			}
			document.getElementById('discussion_title').value='';
			document.getElementById('discussions_desc').value='';
			document.getElementById('checkbox').checked=false;
			document.getElementById('discussion_loader_id').style.display='none';
			document.getElementById('new_thread_id').style.display='none';
         }
		 else
		 {
            alert('There was a problem with the request.');
         }
      }
   }
   function sendEmailUserAjax() {
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
           var result = http_request.responseText;
		   document.getElementById(glb_loader_id).style.visibility='hidden';
		   alert(result);
			window.location.reload();
         } else {
            alert('There was a problem with the request.');
         }
      }
   }
   function sendMessegeUserAjax() {
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
           var result = http_request.responseText;
		   document.getElementById(glb_loader_id).style.visibility='hidden';
		   alert("Your Messege Successfully Sent");
			window.location.reload();
         } else {
            alert('There was a problem with the request.');
         }
      }
   }
   
   
   function getSubmittedLinkAjax() {
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
           var result = http_request.responseText;
		   //alert(result);
		   document.getElementById('submit_a_link_ajax_loader').style.visibility='hidden';
		   document.getElementById('inner_submit_a_link').innerHTML=result;
			
         } else {
            alert('There was a problem with the request.');
         }
      }
   }
    function getSubmitAImage() {
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
           var result = http_request.responseText;
		  document.getElementById('submit_a_image_ajax_loader').style.visibility='hidden';
		  document.getElementById('inner_submit_a_image').innerHTML=result;
			
         } else {
            alert('There was a problem with the request.');
         }
      }
   }
    function getSubmitAVideo() {
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
           var result = http_request.responseText;
		  document.getElementById('submit_a_video_ajax_loader').style.visibility='hidden';
		  document.getElementById('inner_submit_a_video').innerHTML=result;
			
         } else {
            alert('There was a problem with the request.');
         }
      }
   }
   function saveSubmittedLinkAjax() {
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
           var result = http_request.responseText;
		  document.getElementById('submit_a_link_ajax_loader').style.visibility='hidden';
		  alert("Your link successfully submitted.");
		  window.location.reload();
			
         } else {
            alert('There was a problem with the request.');
         }
      }
   }
   
   function saveAImage() {
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
           var result = http_request.responseText;
		  document.getElementById('submit_a_link_ajax_loader').style.visibility='hidden';
		  alert("Your image successfully submitted.");
		  window.location.reload();
			
         } else {
            alert('There was a problem with the request.');
         }
      }
   }
   function saveAVideo() {
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
           var result = http_request.responseText;
		  document.getElementById('submit_a_link_ajax_loader').style.visibility='hidden';
		  alert("Your video successfully submitted.");
		  window.location.reload();
			
         } else {
            alert('There was a problem with the request.');
         }
      }
   }
   function saveComments() {
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
           var result = http_request.responseText;
		  document.getElementById(glb_loader_id).style.visibility='hidden'; 
		  //alert("Your comments successfully submitted.");
		  document.getElementById('tot_comments_id_'+glbI).innerHTML=result;
		  document.getElementById('comments_'+glbI).value='';
		  document.getElementById('comments_id_'+glbI).style.display='none';
		  //window.location.reload();
			
         } else {
            alert('There was a problem with the request.');
         }
      }
   }
   function saveComments1() {
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
           var result = http_request.responseText;
		  document.getElementById(glb_loader_id).style.visibility='hidden'; 
		  //alert("Your comments successfully submitted.");
		  document.getElementById('tot_comments_id_'+glbI).innerHTML=result;
		  document.getElementById('comments_'+glbI).value='';
		  document.getElementById('quick_comments_div').style.display='none';
		   window.location.reload();
         } else {
            alert('There was a problem with the request.');
         }
      }
   }
   function saveCommentsFromBookmarking() {
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
           var result = http_request.responseText;
		 
		  window.location.reload();
			
         } else {
            alert('There was a problem with the request.');
         }
      }
   }
   /***********************newly added response function************************/
   function forgotPswd()
   {
	   if (http_request.readyState == 4) {
         if (http_request.status == 200) {
           var result = http_request.responseText;
		   //alert(result);
		 	if(result)
		  	{
				document.getElementById('emp_email_id').innerHTML='Login Details Sent Successfully!';
				document.getElementById('reg_ajax_loader1').style.visibility='hidden';
			}
			else
		  	{
				document.getElementById('emp_email_id').innerHTML='Error In Sending Mail!';
				document.getElementById('reg_ajax_loader1').style.visibility='hidden';
			}
			
         } else {
            alert('There was a problem with the request.');
         }
	   }
   }
   
   
   
   
   function post_registration() 
   {
	    var flag=0;
		var reg_email_id=document.getElementById('reg_email_id').value;
		var reg_user_name=document.getElementById('reg_user_name').value;
		var reg_password=document.getElementById('reg_password').value;
		
		
		if(reg_email_id=='' || reg_email_id=='Email Address')
		{
			flag=1;
			document.getElementById('emp_reg_email_id').innerHTML='Please enter your email id';
		}
		else if(validateEmailv2(reg_email_id)==false)
		{
			flag=1;
			document.getElementById('emp_reg_email_id').innerHTML='Please enter your valid email id';
		}
		else
		{
			document.getElementById('emp_reg_email_id').innerHTML='';
		}
		
		if(reg_user_name=='' || reg_user_name=='Username')
		{
			flag=1;
			document.getElementById('emp_reg_user_name').innerHTML='Please enter your username';
		}
		else
		{
			document.getElementById('emp_reg_user_name').innerHTML='';
		}
		
		if(reg_password=='' || reg_password=='Password')
		{
			flag=1;
			document.getElementById('emp_reg_password').innerHTML='Please enter your password';
		}
		else
		{
			if(reg_password == reg_user_name){
				flag=1;
				document.getElementById('emp_reg_password').innerHTML='Password cannot be same as username. Please try another.';
			}else{
				document.getElementById('emp_reg_password').innerHTML='';
			}
		}

	   if(flag==0)
	   {
		    document.getElementById('reg_ajax_loader').style.visibility='visible';
			var poststr = "email_id=" + encodeURI( reg_email_id )+"&user_name=" + encodeURI(reg_user_name)+"&password=" + encodeURI(reg_password)+"&from=registration";
			makePOSTRequest(root_url+'ajax/ajaxPost.php', poststr,'registration');
	   }
   }
   
   function post_login_using()
	{
		document.getElementById('login_using_invalid_data').innerHTML='';
		document.getElementById('login_using_ajax_loader').style.visibility='hidden';
	   	var flag=0;
     	var email_id=document.getElementById('login_using_email_id').value;
		var password=document.getElementById('login_using_password').value;
		
		if(email_id=='' || email_id=='Username/Email Address')
		{
			flag=1;
			document.getElementById('emp_login_using_email_id').innerHTML='Please enter your Username or Email Address';
		}
		else
		{
			document.getElementById('emp_login_using_email_id').innerHTML='';
		}

		
		if(password=='' || password=='Password')
		{
			flag=1;
			document.getElementById('emp_login_using_password').innerHTML='Please enter your password';
		}
		else
		{
			document.getElementById('emp_login_using_password').innerHTML='';
		}

	   if(flag==0)
	   {
		    document.getElementById('login_using_ajax_loader').style.visibility='visible';
			 var poststr = "email_id=" + encodeURI(email_id)+"&password=" + encodeURI(password)+"&from=login";
			// alert(root_url+'ajax/ajaxPost.php'+poststr);
			 makePOSTRequest(root_url+'ajax/ajaxPost.php', poststr,'login_using');
	   }
	   return false;
	}
   

	function post_login()
	{
		document.getElementById('login_invalid_data').innerHTML='';
	   var flag=0;
     	var email_id=document.getElementById('login_email_id').value;
		var password=document.getElementById('login_password').value;
		
		if(email_id=='' || email_id=='Username/Email Address')
		{
			flag=1;
			document.getElementById('emp_login_email_id').innerHTML='Please enter your Username or Email Address';
		}
		else
		{
			document.getElementById('emp_login_email_id').innerHTML='';
		}

		
		if(password=='' || password=='Password')
		{
			flag=1;
			document.getElementById('emp_login_password').innerHTML='Please enter your password';
		}
		else
		{
			document.getElementById('emp_login_password').innerHTML='';
		}

	   if(flag==0)
	   {
		    document.getElementById('login_ajax_loader').style.visibility='visible';
			 var poststr = "email_id=" + encodeURI(email_id)+"&password=" + encodeURI(password)+"&from=login";
			// alert(root_url+'ajax/ajaxPost.php'+poststr);
			 makePOSTRequest(root_url+'ajax/ajaxPost.php', poststr,'login');
	   }
	}

	
	function get_submitted_link_ajax(source_id,from,target_inner_id)
	{
		var flag=0;
		var source=document.getElementById(source_id).value;
		if(source=='' || source=='Submit a link')
		{
			flag=1;
			alert("Please enter a link");
			
		}
		if(flag==0)
		{
			 document.getElementById('submit_a_link_ajax_loader').style.visibility='visible';
			 var poststr = "sourcelink=" + encodeURI(source)+"&from="+from;
			 //alert("poststr="+poststr);
			 makePOSTRequest(root_url+'ajax/ajaxPost.php', poststr,from);
		}
	}
	function save_submitted_link_ajax()
	{
		
		var flag=0;
		var err='';
		var submit_a_link=document.getElementById('submit_a_link').value;
		if(submit_a_link=='' || submit_a_link=='Submit a link')
		{
			flag=1;
			 err +="Please enter a link\n";
		}
		
		var is_no_image='N';
		if(document.getElementById('is_no_image').checked==true)
		{
			is_no_image='Y';
		}

		var page_title=document.getElementById('page_title').value;
		if(page_title=='')
		{
			flag=1;
			 err +="Please enter page title\n";
		}
		
		var meta_description=document.getElementById('meta_description').value;
		if(meta_description=='')
		{
			flag=1;
			 err +="Please enter page description\n";
		}
		
		var topic_id=document.getElementById('topic_id').value;
		if(topic_id=='')
		{
			flag=1;
			 err +="Please select a topics\n";
		}
		
		var news_type=document.getElementById('news_type').value;
		if(news_type=='')
		{
			flag=1;
			 err +="Please select a media\n";
		}
		
		
		var choosen_image_link=document.getElementById('choosen_image_link').value;
		//var is_no_image=document.getElementById('is_no_image').value;
		
		if(flag==0)
		{
			 document.getElementById('save_a_link_ajax_loader').style.visibility='visible';
			 var poststr = "link=" + encodeURI(submit_a_link)+"&is_no_image="+encodeURI(is_no_image)+"&page_title="+encodeURIComponent(page_title)+"&meta_description="+encodeURIComponent(meta_description)+"&topic_id="+encodeURI(topic_id)+"&news_type="+encodeURI(news_type)+"&choosen_image_link="+encodeURI(choosen_image_link)+"&from=save_a_link";
			 //alert(poststr);
			 makePOSTRequest(root_url+'ajax/ajaxPost.php', poststr,'save_a_link');
		}
		else
		{
			alert(err);
		}
	}
	
	
	function save_submitted_image_ajax()
	{
		var flag=0;
		var err='';
		var page_title=document.getElementById('page_title').value;
		if(page_title=='')
		{
			flag=1;
			 err +="Please enter page title\n";
		}
		
		var meta_description=document.getElementById('meta_description').value;
		if(meta_description=='')
		{
			flag=1;
			 err +="Please enter page description\n";
		}
		var topic_id=document.getElementById('topic_id').value;
		if(topic_id=='')
		{
			flag=1;
			 err +="Please select a topics\n";
		}
		var news_type=document.getElementById('news_type').value;
		if(news_type=='')
		{
			flag=1;
			 err +="Please select a media\n";
		}
		var choosen_image_link=document.getElementById('choosen_image_link').value;
		if(flag==0)
		{
			 document.getElementById('save_a_link_ajax_loader').style.visibility='visible';
			/* var poststr ="page_title="+page_title+"&meta_description="+meta_description+"&topic_id="+topic_id+"&news_type="+news_type+"&choosen_image_link="+choosen_image_link+"&from=save_a_image";*/
			 var poststr = "page_title=" + encodeURIComponent(page_title)+"&meta_description="+encodeURIComponent(meta_description)+"&topic_id="+encodeURI(topic_id)+"&news_type="+encodeURI(news_type)+"&choosen_image_link="+encodeURI(choosen_image_link)+"&from=save_a_image";
			 makePOSTRequest(root_url+'ajax/ajaxPost.php', poststr,'save_a_image');
		}
		else
		{
			alert(err);
		}
	}
	
	function save_submitted_video_ajax()
	{
		var flag=0;
		var err='';
		var page_title=document.getElementById('page_title').value;
		if(page_title=='')
		{
			flag=1;
			 err +="Please enter page title\n";
		}
		
		var meta_description=document.getElementById('meta_description').value;
		if(meta_description=='')
		{
			flag=1;
			 err +="Please enter page description\n";
		}
		var topic_id=document.getElementById('topic_id').value;
		if(topic_id=='')
		{
			flag=1;
			 err +="Please select a topics\n";
		}
		var news_type=document.getElementById('news_type').value;
		if(news_type=='')
		{
			flag=1;
			 err +="Please select a media\n";
		}
		var choosen_image_link=document.getElementById('choosen_image_link').value;
		if(flag==0)
		{
			 document.getElementById('save_a_link_ajax_loader').style.visibility='visible';
			 var poststr ="page_title="+page_title+"&meta_description="+meta_description+"&topic_id="+topic_id+"&news_type="+news_type+"&choosen_image_link="+choosen_image_link+"&from=save_a_video";
			 
			 makePOSTRequest(root_url+'ajax/ajaxPost.php', poststr,'save_a_video');
		}
		else
		{
			alert(err);
		}
	}
	
	
	
	function get_submit_a_image(imgSrc,from)
	{
		 var poststr = "imgSrc=" + encodeURI(imgSrc)+"&from="+from;
		 makePOSTRequest(root_url+'ajax/ajaxPost.php', poststr,from);
	}
	
	function get_submit_a_video(vSrc,from)
	{
		 var poststr = "vSrc=" + encodeURI(vSrc)+"&from="+from;
		 makePOSTRequest(root_url+'ajax/ajaxPost.php', poststr,from);
	}
	
	
	
	//Functions fo comments posting
	var glb_loader_id;
	var glbI;
	function save_comments(i,item_id,parent_id,loader_id)
	{
		var flag=0;
		var comments=document.getElementById('comments_'+i).value;
		if(comments=='')
		{
			err="Please enter your comments.";
			flag=1;
		}
		
		if(flag==0)
		{
			glb_loader_id=loader_id;
			glbI=i;
			 document.getElementById(loader_id).style.visibility='visible';
			  var poststr =root_url+'ajax/ajaxPost.php?comments=' + encodeURIComponent(comments)+'&item_id='+item_id+'&parent_id='+parent_id+'&from=save_comments';
			 $.post(poststr,function(){
				window.location.reload();	 
				 
				 });
			
			 
		}
		else
		{
			alert(err);
		}
	}
	function save_comments1(i,item_id,parent_id,loader_id)
	{
		var flag=0;
		var comments=document.getElementById('comments_'+i).value;
		if(comments=='')
		{
			err="Please enter your comments.";
			flag=1;
		}
		
		if(flag==0)
		{
			glb_loader_id=loader_id;
			glbI=i;
			 document.getElementById(loader_id).style.visibility='visible';
			 var poststr = "comments=" + encodeURIComponent(comments)+"&item_id="+item_id+"&parent_id="+parent_id+"&from=save_comments";
			 
			 makePOSTRequest(root_url+'ajax/ajaxPost.php', poststr,'save_comments1');
			 
		}
		else
		{
			alert(err);
		}
	}
	
	function save_comments_from_bookmarking1(i,item_id,parent_id,loader_id,last_page,topic_id,discussion_id)
	{
		var flag=0;
		var comments=document.getElementById('comments_'+i).value;
		var no_spam=document.getElementById('comments_no_spam_'+i).checked;
		var err='';
		if(comments=='')
		{
			err +="Please enter your comments.\n";
			flag=1;
		}
		var sex='';
		if(document.getElementById('is_gender_exists_reply_'+i).value=='1')
		{
			if(document.getElementById('sex1_reply_'+i).checked==false && document.getElementById('sex2_reply_'+i).checked==false)
			{
				err +="Please select your gender.\n";
				flag=1;
			}
			
			if(document.getElementById('sex1_reply_'+i).checked==true)
			{
				sex='m';
			}
			if(document.getElementById('sex2_reply_'+i).checked==true)
			{
				sex='f';
			}
		}
		if(no_spam==false)
		{
			err +="Please checked 'My Post is not a Spam; it is written in Good English & is Not an Insult to Anybody.'";
			flag=1;
		}
		if(flag==0)
		{
			glb_loader_id=loader_id;
			glbI=i;
			 document.getElementById(loader_id).style.visibility='visible';
			  var poststr = root_url+"ajax/ajaxPost.php?comments=" + encodeURIComponent(comments)+"&item_id="+item_id+"&sex="+sex+"&parent_id="+parent_id+"&from=save_comments";
			 
			  // makePOSTRequest(root_url+'ajax/ajaxPost.php', poststr,'save_comments_from_bookmarking');
			  $.post(poststr,function(data){
			  	if(parseInt(data) > 0){
					window.location=root_url+'comments/'+topic_id+discussion_id+'-page='+data+'-last';
				}else{
					if(data != ""){ alert(data); }
					window.location.reload();
					 //window.location=root_url+'comments/'+topic_id+discussion_id;
				}
			  });
			 
		}
		else
		{
			alert(err);
		}
	}
	function save_comments_from_bookmarking(i,item_id,parent_id,loader_id)
	{
	
		var flag=0;
		var comments=document.getElementById('comments_'+i).value;
		var no_spam=document.getElementById('comments_no_spam_'+i).checked;
		var err='';
		if(comments=='')
		{
			err +="Please enter your comments.\n";
			flag=1;
		}
		var sex='';
		if(document.getElementById('is_gender_exists_reply_'+i).value=='1')
		{
			if(document.getElementById('sex1_reply_'+i).checked==false && document.getElementById('sex2_reply_'+i).checked==false)
			{
				err +="Please select your gender.\n";
				flag=1;
			}
			
			if(document.getElementById('sex1_reply_'+i).checked==true)
			{
				sex='m';
			}
			if(document.getElementById('sex2_reply_'+i).checked==true)
			{
				sex='f';
			}
		}
		if(no_spam==false)
		{
			err +="Please checked 'My Post is not a Spam; it is written in Good English & is Not an Insult to Anybody.'";
			flag=1;
		}
		if(flag==0)
		{
			glb_loader_id=loader_id;
			glbI=i;
			 document.getElementById(loader_id).style.visibility='visible';
			  var poststr = "comments=" + encodeURIComponent(comments)+"&item_id="+item_id+"&sex="+sex+"&parent_id="+parent_id+"&from=save_comments";
			 
			 makePOSTRequest(root_url+'ajax/ajaxPost.php', poststr,'save_comments_from_bookmarking');

			 
		}
		else
		{
			alert(err);
		}
	}
	
	function save_quote_from_bookmarking1(comments_id,item_id,parent_id,loader_id,last_page,topic_id,discussion_id)
	{
		
		
		var flag=0;
		
		var comments=document.getElementById('quote_'+comments_id).value;
		var no_spam=document.getElementById('quote_no_spam_'+comments_id).checked;
		var err='';
		if(comments=='')
		{
			err +="Please enter your comments.\n";
			flag=1;
		}
		
		var sex='';
		if(document.getElementById('is_gender_exists_quote_'+comments_id).value=='1')
		{
			if(document.getElementById('sex1_quote_'+comments_id).checked==false && document.getElementById('sex2_quote_'+comments_id).checked==false)
			{
				err +="Please select your gender.\n";
				flag=1;
			}
			
			if(document.getElementById('sex1_quote_'+comments_id).checked==true)
			{
				sex='m';
			}
			if(document.getElementById('sex2_quote_'+comments_id).checked==true)
			{
				sex='f';
			}
		}
		
		
		if(no_spam==false)
		{
			err +="Please checked 'My Post is not a Spam; it is written in Good English & is Not an Insult to Anybody.'";
			flag=1;
		}
		if(flag==0)
		{
			glb_loader_id=loader_id;
			glbI=i;
			 document.getElementById(loader_id).style.visibility='visible';
			  var poststr = root_url+"ajax/ajaxPost.php?comments=" + encodeURIComponent(comments)+"&item_id="+item_id+"&parent_id="+parent_id+"&sex="+sex+"&from=save_quote";
			 
			 $.post(poststr,function(data){
					if(parseInt(data) > 0){
						window.location=root_url+'comments/'+topic_id+discussion_id+'-page='+data+'-last';						
					}else{
						alert(data);
						window.location.reload();
					 	//window.location=root_url+'comments/'+topic_id+discussion_id;
					}
				 });
			 
		}
		else
		{
			alert(err);
		}
	}
	
	function save_quote_from_bookmarking(comments_id,item_id,parent_id,loader_id)
	{
		var flag=0;
		
		var comments=document.getElementById('quote_'+comments_id).value;
		var no_spam=document.getElementById('quote_no_spam_'+comments_id).checked;
		var err='';
		if(comments=='')
		{
			err +="Please enter your comments.\n";
			flag=1;
		}
		
		var sex='';
		if(document.getElementById('is_gender_exists_quote_'+comments_id).value=='1')
		{
			if(document.getElementById('sex1_quote_'+comments_id).checked==false && document.getElementById('sex2_quote_'+comments_id).checked==false)
			{
				err +="Please select your gender.\n";
				flag=1;
			}
			
			if(document.getElementById('sex1_quote_'+comments_id).checked==true)
			{
				sex='m';
			}
			if(document.getElementById('sex2_quote_'+comments_id).checked==true)
			{
				sex='f';
			}
		}
		
		
		if(no_spam==false)
		{
			err +="Please checked 'My Post is not a Spam; it is written in Good English & is Not an Insult to Anybody.'";
			flag=1;
		}
		if(flag==0)
		{
			glb_loader_id=loader_id;
			glbI=i;
			 document.getElementById(loader_id).style.visibility='visible';
			  var poststr = "comments=" + encodeURIComponent(comments)+"&item_id="+item_id+"&parent_id="+parent_id+"&sex="+sex+"&from=save_quote";
			  makePOSTRequest(root_url+'ajax/ajaxPost.php', poststr,'save_comments_from_bookmarking');
			
			 
		}
		else
		{
			alert(err);
		}
	}
	
	
	
	
	
	/**************************************************************************/
/**************************************************************************/
/*************************DISCUSSION MANAGEMENT****************************/
/**************************************************************************/
/**************************************************************************/
function ajax_discussion_insert(topic_id)
{
	var discussion_title=document.getElementById('discussion_title').value;
	var discussions_desc=document.getElementById('discussions_desc').value;
	var err='';
	if(discussion_title=='')
	{
		err +='Please enter discussion title\n';
	}
	if(discussions_desc=='')
	{
		err +='Please enter discussions description\n';
	}
	
	
	if(err=='')
	{
		document.getElementById('discussion_loader_id').style.display='block';
		var poststr = "discussion_title=" + encodeURIComponent(discussion_title)+"&discussions_desc="+encodeURIComponent(discussions_desc)+"&topic_id="+encodeURI(topic_id)+"&from=post_discussion";
		makePOSTRequest(root_url+'ajax/ajaxPost.php', poststr,'post_discussion');
	}
	else
	{
		alert(err);
	}
}



function save_comments_from_discussion1(i,item_id,parent_id,loader_id,last_page,topic_id,discussion_id)
	{
		//alert(i);
		var flag=0;
		var comments=document.getElementById('comments_dis_'+i).value;
		var no_spam=document.getElementById('comments_dis_no_spam_'+i).checked;
		var err='';
		if(comments=='')
		{
			err +="Please enter your comments.\n";
			flag=1;
		}
		var sex='';
		if(document.getElementById('is_gender_exists_reply').value=='1')
		{
			if(document.getElementById('sex1_reply').checked==false && document.getElementById('sex2_reply').checked==false)
			{
				err +="Please select your gender.\n";
				flag=1;
			}
			
			if(document.getElementById('sex1_reply').checked==true)
			{
				sex='m';
			}
			if(document.getElementById('sex2_reply').checked==true)
			{
				sex='f';
			}
		}
		if(no_spam==false)
		{
			err +="Please checked 'My Post is not a Spam; it is written in Good English & is Not an Insult to Anybody.'";
			flag=1;
		}
		if(flag==0)
		{
			glb_loader_id=loader_id;
			glbI=i;
			 document.getElementById(loader_id).style.visibility='visible';
			  var poststr = root_url+"ajax/ajaxPost.php?comments=" + encodeURIComponent(comments)+"&item_id="+item_id+"&parent_id="+parent_id+"&sex="+sex+"&from=save_comments&parent_type=discussion";
			  $.post(poststr,function(data){
				 if(parseInt(data) > 0){
					 window.location=root_url+'comments/'+topic_id+discussion_id+'-page='+data+'-last';
				 }else{
					 alert(data);
					 window.location.reload();
					 //window.location=root_url+'comments/'+topic_id+discussion_id;
				 }
			 });
			// makePOSTRequest( poststr,'save_comments_from_bookmarking');
			 
		}
		else
		{
			alert(err);
		}
	}
	function save_comments_from_discussion(i,item_id,parent_id,loader_id)
	{
		//alert(i);
		var flag=0;
		var comments=document.getElementById('comments_dis_'+i).value;
		var no_spam=document.getElementById('comments_dis_no_spam_'+i).checked;
		var err='';
		if(comments=='')
		{
			err +="Please enter your comments.\n";
			flag=1;
		}
		var sex='';
		if(document.getElementById('is_gender_exists_reply').value=='1')
		{
			if(document.getElementById('sex1_reply').checked==false && document.getElementById('sex2_reply').checked==false)
			{
				err +="Please select your gender.\n";
				flag=1;
			}
			
			if(document.getElementById('sex1_reply').checked==true)
			{
				sex='m';
			}
			if(document.getElementById('sex2_reply').checked==true)
			{
				sex='f';
			}
		}
		if(no_spam==false)
		{
			err +="Please checked 'My Post is not a Spam; it is written in Good English & is Not an Insult to Anybody.'";
			flag=1;
		}
		if(flag==0)
		{
			glb_loader_id=loader_id;
			glbI=i;
			 document.getElementById(loader_id).style.visibility='visible';
			  var poststr = root_url+"ajax/ajaxPost.php?comments=" + encodeURIComponent(comments)+"&item_id="+item_id+"&parent_id="+parent_id+"&sex="+sex+"&from=save_comments&parent_type=discussion";
			 
			 makePOSTRequest( poststr,'save_comments_from_bookmarking');
			 
		}
		else
		{
			alert(err);
		}
	}
	
	function save_quote_from_discussion1(comments_id,item_id,parent_id,loader_id,last_page,topic_id,discussion_id)
	{
		
		var flag=0;
		
		var comments=document.getElementById('quote_dis_'+comments_id).value;
		var no_spam=document.getElementById('quote_dis_no_spam_'+comments_id).checked;
		
		var err='';
		if(comments=='')
		{
			err +="Please enter your comments.\n";
			flag=1;
		}
		var sex='';
		if(document.getElementById('is_gender_exists_quote').value=='1')
		{
			if(document.getElementById('sex1_quote').checked==false && document.getElementById('sex2_quote').checked==false)
			{
				err +="Please select your gender.\n";
			}
			
			if(document.getElementById('sex1_quote').checked==true)
			{
				sex='m';
			}
			if(document.getElementById('sex2_quote').checked==true)
			{
				sex='f';
			}
		}
		
		if(no_spam==false)
		{
			err +="Please checked 'My Post is not a Spam; it is written in Good English & is Not an Insult to Anybody.'";
			flag=1;
		}
		if(flag==0)
		{
			glb_loader_id=loader_id;
			glbI=i;
			 document.getElementById(loader_id).style.visibility='visible';
			  var poststr =root_url+"ajax/ajaxPost.php?comments=" + encodeURIComponent(comments)+"&item_id="+item_id+"&parent_id="+parent_id+"&sex="+sex+"&from=save_quote&parent_type=discussion";
			 //alert(poststr);
		//	 makePOSTRequest(root_url+'ajax/ajaxPost.php', poststr,'save_comments_from_bookmarking');
		
			 $.post(poststr,function(data){
				 if(parseInt(data) > 0){
					 window.location=root_url+'comments/'+topic_id+discussion_id+'-page='+data+'-last';
				 }else{
					 alert(data);
					 window.location.reload();
					 //window.location=root_url+'comments/'+topic_id+discussion_id;
				 }
			 });
		}
		else
		{
			alert(err);
		}
	}
	
	function save_quote_from_discussion(comments_id,item_id,parent_id,loader_id)
	{
		
		var flag=0;
		
		var comments=document.getElementById('quote_dis_'+comments_id).value;
		var no_spam=document.getElementById('quote_dis_no_spam_'+comments_id).checked;
		
		var err='';
		if(comments=='')
		{
			err +="Please enter your comments.\n";
			flag=1;
		}
		var sex='';
		if(document.getElementById('is_gender_exists_quote').value=='1')
		{
			if(document.getElementById('sex1_quote').checked==false && document.getElementById('sex2_quote').checked==false)
			{
				err +="Please select your gender.\n";
			}
			
			if(document.getElementById('sex1_quote').checked==true)
			{
				sex='m';
			}
			if(document.getElementById('sex2_quote').checked==true)
			{
				sex='f';
			}
		}
		
		if(no_spam==false)
		{
			err +="Please checked 'My Post is not a Spam; it is written in Good English & is Not an Insult to Anybody.'";
			flag=1;
		}
		if(flag==0)
		{
			glb_loader_id=loader_id;
			glbI=i;
			 document.getElementById(loader_id).style.visibility='visible';
			  var poststr =root_url+"ajax/ajaxPost.php?comments=" + encodeURIComponent(comments)+"&item_id="+item_id+"&parent_id="+parent_id+"&sex="+sex+"&from=save_quote&parent_type=discussion";
			 //alert(poststr);
			 makePOSTRequest(root_url+'ajax/ajaxPost.php', poststr,'save_comments_from_bookmarking');
			
		}
		else
		{
			alert(err);
		}
	}
	
	function send_mail_to_user_ajax(loader_id)
	{
		var email_text=document.getElementById('email_text').value;
		var email_user_id=document.getElementById('email_user_id').value;
		var err='';
		if(email_text=='')
		{
			err +="Please enter email text.";
		}
		
		if(err=='')
		{
			 glb_loader_id=loader_id;
			 document.getElementById(loader_id).style.visibility='visible';
			 var poststr = "email_text=" + encodeURIComponent(email_text)+"&email_user_id="+email_user_id+"&from=send_email_user";
			 makePOSTRequest(root_url+'ajax/ajaxPost.php', poststr,'send_email_user');
			 
		}
		else
		{
			alert(err);
		}
	}
	function send_messege_to_user_ajax(loader_id)
	{
		var message_text=document.getElementById('message_text').value;
		var messege_user_id=document.getElementById('messege_user_id').value;
		//var no_spam=document.getElementById('messege_check_id').checked;
		var err='';
		if(message_text=='')
		{
			err +="Please enter your messege.\n";
		}
		/*if(no_spam=='')
		{
			err +="Please Checked 'This New Thread is Written in Good English & is No Insult to Anybody.'";
		}*/
		if(err=='')
		{
			 glb_loader_id=loader_id;
			 document.getElementById(loader_id).style.visibility='visible';
			 var poststr = "message_text=" + encodeURIComponent(message_text)+"&messege_user_id="+messege_user_id+"&from=send_messege_user";
			 makePOSTRequest(root_url+'ajax/ajaxPost.php', poststr,'send_messege_user');
		}
		else
		{
			alert(err);
		}
	}
	
	function enter_pressed(e){
		var keycode;
		if (window.event) keycode = window.event.keyCode;
		else if (e) keycode = e.which;
		else return false;
		return (keycode == 13);
	}
	
	
	/****************************************New Function for forgot password Created(24-01-2012)*****************************************/
	
	function forgot_pswd() 
   {
	    var flag=0;
		var reg_email_id=document.getElementById('user_email_id').value;
		/*var reg_user_name=document.getElementById('reg_user_name').value;
		var reg_password=document.getElementById('reg_password').value;*/
		
		if(reg_email_id=='' || reg_email_id=='Email Address')
		{
			flag=1; 
			document.getElementById('emp_email_id').innerHTML='Please enter your email id';
			document.getElementById('reg_ajax_loader1').style.visibility='hidden';
			
		}
		else if(validateEmailv2(reg_email_id)==false)
		{
			flag=1; 
			document.getElementById('emp_email_id').innerHTML='Please enter your valid email id';
			document.getElementById('reg_ajax_loader1').style.visibility='hidden';
			
		}
			
		
	   if(flag==0)
	   {
			document.getElementById('reg_ajax_loader1').style.visibility='visible';
			var poststr = "email_id=" + encodeURI( reg_email_id )+"&from=forgot_pswd";
			makePOSTRequest(root_url+'ajax/ajaxPost.php', poststr,'forgot_pswd');
			
	   }
   }
