/*

Web Developer: Jaypee de Real

*/


var count_imgx = 1; 
var count_branchx = 0;

function MM_preloadImages() {
   var d = document;
   if(d.images) {
      if(!d.MM_p)
         d.MM_p=new Array();
      var i,j=d.MM_p.length,a=MM_preloadImages.arguments;
      for(i = 0; i < a.length; i++)
         if (a[i].indexOf("#")!=0) {
            d.MM_p[j] = new Image;
            d.MM_p[j++].src=a[i];
         }
   }
}



function urlencode (str) {

    str = (str+'').toString();
    
    return encodeURIComponent(str).replace(/!/g, '%21').replace(/'/g, '%27').replace(/\(/g, '%28').replace(/\)/g, '%29').replace(/\*/g, '%2A').replace(/%20/g, '+');
}


//TRIM FUNCTION 

String.prototype.trim = function() {

a = this.replace(/^\s+/, '');

return a.replace(/\s+$/, '');

};



function EnterPressed(e)
 {
// Code adapted from Jennifer Madden
// http://jennifermadden.com/162/examples/stringEnterKeyDetector.html

  var characterCode
  if(e && e.which){           // NN4 specific code
    e = e
    characterCode = e.which
  }
  else {
    e = event
    characterCode = e.keyCode // IE specific code
  }
  if (characterCode == 13) return true   // Enter key is 13
  else return false
}






function get_radio_value(obj)
{

	var length = obj.length;
	
	if(length > 0)
	 {
		 
		for (var i=0; i < obj.length; i++)
		   {
			  if (obj[i].checked)
				{
				  
				  var rad_val = obj[i].value;
				  
				}
		   }
	 
	 }
	else
	 {
		
		if(obj.checked)
		 {
			 
	 		var rad_val = obj.value; 
		
		 }
		 
	 }
	 
	 return rad_val;   
	   
}



function reloadCaptcha()
 {
	document.getElementById('captcha').src = document.getElementById('captcha').src+ '?' +new Date();
 }



function Register(){

	document.getElementById("RegMessage").innerHTML = "";
	document.getElementById("RegMessage").style.display = "none";


	var error=""; 
	
	obj=document.registration_form;

	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;

  	var address = document.getElementById('Email').value.trim();

	var email = urlencode(document.getElementById('Email').value.trim());	
	var username = urlencode(document.getElementById('Username').value.trim());
	var password = urlencode(document.getElementById('UPassword').value.trim());
	var cpassword = urlencode(document.getElementById('CPassword').value.trim());
	var country = urlencode(document.getElementById('Country').value.trim());
	//var captcha_response = urlencode(document.getElementById('recaptcha_response_field').value.trim());
	//var captcha_challenge = urlencode(document.getElementById('recaptcha_challenge_field').value.trim());

	
	
	var gender = get_radio_value(obj.gender);
	var agreement = get_radio_value(obj.agreement);
	var updates = get_radio_value(obj.updates);
	
	if(updates == null || updates == "")
	 {
		 updates = 'N';
	 }

	if (email==""){

		error = error + "* Enter email address. <br>";

	}
	else if(reg.test(address) == false) {

		error = error + "* Enter a valid Email Address <br>";

	}

	
	if (username==""){

		error = error + "* Enter username <br>";

	}
	
	
	if ((password=="") || (password != cpassword)){	

		error = error + "* Please check the passwords you entered. <br>";

	}
	
	if (country==""){

		error = error + "* Select country. <br>";

	}
	
	if (gender == null || gender==""){

		error = error + "* Select gender. <br>";

	}
	
	if (agreement== null || agreement == ""){
		
		error = error + "* You must agree terms and conditions. <br>";

	}
	
	
	
	

	if(error == "")
	 {
		 
		 var xmlHttp;
			
		try
		 {    // Firefox, Opera 8.0+, Safari    
			
			xmlHttp=new XMLHttpRequest();  
			
		 }
		 
	   catch (e)
		{    // Internet Explorer    
		try
		  {      
		  
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");      
		  
		  }
		  
			catch (e)
			  {   
			  try
				{        
				 
				 xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");        
				 
				}
			  catch (e)
				{        
					alert("Your browser does not support AJAX!");        
					return false;        
					
				}      
			  }    
		  
		  }
				 
		 xmlHttp.onreadystatechange=function()
		  {
			  
			  if(xmlHttp.readyState==4)
				{
					
					
					document.getElementById("LoadingRegister").style.display = "none";
					
					var response = xmlHttp.responseText.trim();
					
					var result = response.split("|");
					
					document.getElementById("RegMessage").style.display = "block";
					
					if(result[0] == 0)
					 {
						
						scroll(0,0);
	
						document.getElementById("RegMessage").innerHTML = result[1];
						
						document.getElementById('Email').value = "";	
						document.getElementById('Username').value = "";
						document.getElementById('UPassword').value = "";
						document.getElementById('CPassword').value = "";
						document.getElementById('Country').value = "Philippines";
	
						document.getElementById('RegistrationForm').style.visibility = 'hidden';
														
						
					 }
					else
					 {
						scroll(0,0);
	 
						 document.getElementById("RegMessage").innerHTML = result[1];
						 //Recaptcha.reload();
					 }
					 
					 
				
					
				}
			  else
			   {
				   
				  document.getElementById("LoadingRegister").style.display = "block";
				  
			   }
			 
			
				
		 }
	
	
	

	   //remove comment if captcha is activated
	   //var param = 'action=register&rand=' + Math.random() + '&email=' + email + '&username=' + username + '&password=' + password + '&country=' + country + '&gender=' + gender + '&updates=' + updates + '&recaptcha_response_field=' + captcha_response + '&recaptcha_challenge_field=' + captcha_challenge;
	   
	   var param = 'action=register&rand=' + Math.random() + '&email=' + email + '&username=' + username + '&password=' + password + '&country=' + country + '&gender=' + gender + '&updates=' + updates;
	   
		xmlHttp.open('POST', 'ajax_return.php', true);    
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");    
		xmlHttp.setRequestHeader("Content-length", param.length);    
		xmlHttp.setRequestHeader("Connection", "close");    
		xmlHttp.send(param);
		 
	 }
	else
	 {
		
		scroll(0,0);
	 
		document.getElementById("RegMessage").style.display = "block";
		document.getElementById("RegMessage").innerHTML = error;
		 
	 }



}




function loginMember(back_target)
 {
	 
	var username_in = urlencode(document.getElementById('username-input').value.trim());
	var password_in = urlencode(document.getElementById('password-input').value);
	
	
	
	var remember = 'N';
	
	var error = "";
	
	
	if(username_in == "")
	 {
		 
		 error += "Enter your username. \n"
	 }
	
	if(password_in == "")
	 {
		 
		 error += "Enter your password. \n"
		 
	 }
	
	if(error == "")
	 {
		 
		var xmlHttp;
		try
		 {    // Firefox, Opera 8.0+, Safari    
			
			xmlHttp=new XMLHttpRequest();  
			
		 }
		 
	   catch (e)
		{    // Internet Explorer    
		try
		  {      
		  
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");      
		  
		  }
		  
			catch (e)
			  {   
			  try
				{        
				 
				 xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");        
				 
				}
			  catch (e)
				{        
					alert("Your browser does not support AJAX!");        
					return false;        
					
				}      
			  }    
		  
		  }
				 
		 xmlHttp.onreadystatechange=function()
		  {
			  
			  if(xmlHttp.readyState==4)
				{
				
					var response = xmlHttp.responseText;
					var result = response.split("|");
					
					var islog = result[0];
					var target = result[1];
					
					if(target == "")
					 {
						 
						 target = back_target;
						 
					 }
					 
					if(islog == '1')
					 {
						 
					 	
						window.location = target;
				
						 
					 }
					else
					 {
						
						 alert("Username and Password did not Match. "); 
						 document.getElementById('LoginLoader').style.display = 'none';
						
					 }
					
				}
			
			  else
				{
					
					document.getElementById('LoginLoader').style.display = 'block';
					
				}
			
			
				
		 }
	
		
	   var param = 'action=login_member&rand=' + Math.random() + '&username_in='+ username_in + '&password_in='+ password_in + '&remember='+ remember;
	   
		xmlHttp.open('POST', 'ajax_return.php', true);    
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");    
		xmlHttp.setRequestHeader("Content-length", param.length);    
		xmlHttp.setRequestHeader("Connection", "close");    
		xmlHttp.send(param);
	 
	 }
	else
	 {
		
		alert(error);
		 
	 }
	 
 }





function updateProfile(){

	
	var error=""; 
	
	obj=document.myaccount_form;

	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;

  	var address = document.getElementById('Email').value.trim();

	var email = urlencode(document.getElementById('Email').value.trim());	
	var username = urlencode(document.getElementById('UsernameLog').value.trim());
	
	var password = urlencode(document.getElementById('PasswordLog').value.trim());
	var cpassword = urlencode(document.getElementById('ConPasswordLog').value.trim());
	
	var country = urlencode(document.getElementById('Country').value.trim());
	

	var gender = get_radio_value(obj.gender);
	var updates = get_radio_value(obj.updates);
	
	var actualimg = document.getElementById("UploadImg").value.trim();
	
	
	if(updates == null || updates == "")
	 {
		 updates = 'N';
	 }

	if (email==""){

		error = error + "* Enter email address. <br>";

	}
	else if(reg.test(address) == false) {

		error = error + "* Enter a valid Email Address <br>";

	}

	
	if (username==""){

		error = error + "* Enter username <br>";

	}
	
	
	if (password != cpassword){	

		error = error + "* Please check the passwords you entered. <br>";

	}
	
	if (country==""){

		error = error + "* Select country. <br>";

	}
	
	if (gender == null || gender==""){

		error = error + "* Select gender. <br>";

	}
	
	if(actualimg)
	 {
		 
		if((actualimg.lastIndexOf(".jpg")==-1)&&(actualimg.lastIndexOf(".JPG")==-1)&&(actualimg.lastIndexOf(".jpeg")==-1)&&(actualimg.lastIndexOf(".JPEG")==-1))
		{
			
			error += "Please upload only .jpg extension file. <br>"; 
			
		}
	
	 }
	
	
	if(error == "")
	 {
		 
		 document.getElementById("LoadingRegister").style.display = "block";
		 obj.submit();

	 }
	else
	 {
		 
		  document.getElementById("RegMessage").style.display = "block";
		 document.getElementById("RegMessage").innerHTML = error;
						
	 }



}




function showAddBranch(category)
 {
	 
	 count_branchx = 0;
	 
	 document.getElementById("BranchAdd").innerHTML = "";
	 
	 if((category!="") && (category == "travel" || category == "food" || category == "festivals" ))
	  {
		
		document.getElementById("ShowBranch").style.display = "block";
		
		addBranch();
		  
	  }
	 else
	  {
		  
		document.getElementById("ShowBranch").style.display = "none";
			
	  }
	 
 }
 
 
 
function addBranch()
 {
	 
	var objs = document.getElementsByName('branch[]');
	//if the element exists on this page
	var count_branch = count_branchx + 1; 
	
	
	 var xmlHttp;
			
		try
		 {    // Firefox, Opera 8.0+, Safari    
			
			xmlHttp=new XMLHttpRequest();  
			
		 }
		 
	   catch (e)
		{    // Internet Explorer    
		try
		  {      
		  
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");      
		  
		  }
		  
			catch (e)
			  {   
			  try
				{        
				 
				 xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");        
				 
				}
			  catch (e)
				{        
					alert("Your browser does not support AJAX!");        
					return false;        
					
				}      
			  }    
		  
		  }
				 
		 xmlHttp.onreadystatechange=function()
		  {
			  
			  if(xmlHttp.readyState==4)
				{
					
					
					var response = xmlHttp.responseText.trim();
			
				
					var div = document.getElementById('BranchAdd');
			
					
					var newdiv = document.createElement("div");
					newdiv.setAttribute("id", "OtherBranch"+count_branch)
					newdiv.innerHTML = (response);
					
					 
					div.appendChild(newdiv);
					count_branchx++;
				
					
				}
	
				
		 }
	
	
	

	   
	   var param = 'action=add_branch_form&rand=' + Math.random() + '&count_branch=' + count_branch;
	   
		xmlHttp.open('POST', 'insert_branch_form.php', true);    
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");    
		xmlHttp.setRequestHeader("Content-length", param.length);    
		xmlHttp.setRequestHeader("Connection", "close");    
		xmlHttp.send(param);
	
	 
 }
 


function getKeywords(id) 
 {
	
	var street = document.getElementById("Street"+id).value.trim();
	var city = document.getElementById("City"+id).value.trim();
	var province = document.getElementById("Province"+id).value.trim();
	
	var keywords = (street + " " + city + " " + province).trim();
	 
	document.getElementById("Keywords"+id).value = keywords;
	
 }

 
function changeMap(id)
 {

	
	var branch = urlencode(document.getElementById("BranchName"+id).value.trim());
	
	var street = document.getElementById("Street"+id).value.trim();
	
	var city = document.getElementById("City"+id).value.trim();
	
	var province = document.getElementById("Province"+id).value.trim();
	
	var zoom = 4;
	
	var error = "";
	
	
	
	if(street != "")
	 {
		 
		 zoom += 10;
		 
	 }
	 

	 
	 var keywords = urlencode(document.getElementById("Keywords"+id).value.trim());
	 

	 
	 if(keywords == "")
	  {
		
		//keywords = (street + " " + city + " " + province).trim();	
		//keywords = urlencode(keywords).trim();
		zoom = 4; 
		
	  }
	

	
	 
	 if(error == "")
	  {
		 
		 
		 
		 var xmlHttp;
				
			try
			 {    // Firefox, Opera 8.0+, Safari    
				
				xmlHttp=new XMLHttpRequest();  
				
			 }
			 
		   catch (e)
			{    // Internet Explorer    
			try
			  {      
			  
				xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");      
			  
			  }
			  
				catch (e)
				  {   
				  try
					{        
					 
					 xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");        
					 
					}
				  catch (e)
					{        
						alert("Your browser does not support AJAX!");        
						return false;        
						
					}      
				  }    
			  
			  }
					 
			 xmlHttp.onreadystatechange=function()
			  {
				  
				  if(xmlHttp.readyState==4)
					{
						
						var response = xmlHttp.responseText.trim();
						
						document.getElementById("MapDiv"+id).innerHTML = response; 
						
						document.getElementById("GpsCode"+id).value = response;
						
						
						
					}
		
					
			 }
		
		
		
	
		   
		   var param = 'action=change_map&rand=' + Math.random() + '&keywords=' + keywords + '&branch=' + branch  + '&zoom=' + zoom;
		   
			xmlHttp.open('POST', 'insert_branch_form.php', true);    
			xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");    
			xmlHttp.setRequestHeader("Content-length", param.length);    
			xmlHttp.setRequestHeader("Connection", "close");    
			xmlHttp.send(param);
		
	  }
	 else
	  {
		  
	  	alert(error);
		
	  }
	 
 }
 
 
 
 

 function addImage()
 {
	 
	var objs = document.getElementsByName('imageupload[]');
	//if the element exists on this page
	var count_img = count_imgx + 1;
	
	 var xmlHttp;
			
		try
		 {    // Firefox, Opera 8.0+, Safari    
			
			xmlHttp=new XMLHttpRequest();  
			
		 }
		 
	   catch (e)
		{    // Internet Explorer    
		try
		  {      
		  
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");      
		  
		  }
		  
			catch (e)
			  {   
			  try
				{        
				 
				 xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");        
				 
				}
			  catch (e)
				{        
					alert("Your browser does not support AJAX!");        
					return false;        
					
				}      
			  }    
		  
		  }
				 
		 xmlHttp.onreadystatechange=function()
		  {
			  
			  if(xmlHttp.readyState==4)
				{
					
					var response = xmlHttp.responseText.trim();
			
					//document.getElementById("ImageUp").innerHTML += response; 
					 
				
					var div = document.getElementById('ImageUp');
					 //var oI = document.getElementById('Image1').cloneNode(true);
					 //oI.id = 'Image' + count_img;
					 //oI.value = '';
					
					
					var newdiv = document.createElement("div");
					newdiv.setAttribute("id", "Image"+count_img)
					newdiv.innerHTML = (response);
					
					 
					div.appendChild(newdiv);
					count_imgx++;
						
						
					
				}
	
				
		 }
	
	
	

	   
	   var param = 'action=add_image_form&rand=' + Math.random() + '&count_img=' + count_img;
	   
		xmlHttp.open('POST', 'insert_branch_form.php', true);    
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");    
		xmlHttp.setRequestHeader("Content-length", param.length);    
		xmlHttp.setRequestHeader("Connection", "close");    
		xmlHttp.send(param);
	
	 
 }



function removeDivWho(who) {
	if(typeof who== 'string') who=document.getElementById(who);
	if(who && who.parentNode)who.parentNode.removeChild(who);
}


	
function removeExtra(divid)
 {
	 
	 document.getElementById(divid).style.display = "none";
	 removeDivWho(divid);
	 
 }
 
 
 
function checkPage(action)
 {
	
	document.getElementById("HiddenAction").value = action; 
	
	var error = "";
	var obj = document.create_page_form;
	
	var title = urlencode(document.getElementById("Title").value.trim());
	var category = get_radio_value(obj.category);
	var budget = document.getElementById("Budget").value.trim();
	//var content = document.getElementById("ArticleContent").value.trim();
	var content = tinyMCE.get("ArticleContent").getContent();
	var intro = document.getElementById("ArticleIntro").value.trim();
	var tags = document.getElementById("ArticleTags").value.trim();

	
	var count_img = (document.getElementsByName('imageupload[]')).length;
	var count_branch = (document.getElementsByName('branch[]')).length;
	
	document.getElementById("HiddenCountImg").value= count_imgx;
	document.getElementById("HiddenCountBranch").value= count_branchx;
	
	var countimg = 0;
	var countbranch = 0;
	
	
	
	if(title == "")
	 {
		 
		 error += "* Enter title for article. <br>";
	 }
	 
	if(category == "" || category == null)
	 {
		 
		error += "* Select category. <br>"; 
		 
	 }
	
	if(intro == "")
	 {
		 
		error += "* Enter intro of article. <br>"; 
		 
	 }
	 
	
	if(content == "")
	 {
		 
		error += "* Enter content of article. <br>"; 
		 
	 }
	 
	if(tags == "")
	 {
		 
		error += "* Enter tags of article. <br>"; 
		 
	 }
	 
	
	 for(var i=1; i<=count_imgx; i++)
	  {
		 
		 var this_id = "imagefile" + i;
		
		 
		 if(document.getElementById(this_id))
		  {
		
			 var actualimg = document.getElementById(this_id).value.trim();
			 
			 if(actualimg != "")
			  {
				  
				 if((actualimg.lastIndexOf(".jpg")==-1)&&(actualimg.lastIndexOf(".JPG")==-1)&&(actualimg.lastIndexOf(".jpeg")==-1)&&(actualimg.lastIndexOf(".JPEG")==-1))
				  {
					
					 error += "Please upload only .jpg extension file. <br>"; 
					 countimg++;
					
				  }
				 else
				  {
					  
					  countimg++;
					  
				  }
		  
			  }//end actual_img != ""
		  
		  }
		  
	  }
	  
	  
	 
	   if(countimg == 0)
	   {
		
			 error += "* Please upload at least one image. <br>"; 
		
	   }
	   
	   
	   
	   
	   
	  //category is Travel, Food, Festivals
	  if(category == "travel" || category == "food" || category == "festivals")
	   {
		
		  
		  if(budget == "")
		  {
				 
			error += "* Select budget. <br>";
			
		  }
		  
		  
		  for(var i=1; i<=count_branchx; i++)
		  {
			 
			 if(document.getElementById("OtherBranch" + i))
			  {
				  
				 var error_branch = 0
				 
				 if(document.getElementById("BranchName" + i).value.trim() == "")
				  {
					  
					  error += "Enter branch name. <br> ";
					  
					  
				  }
			 
				 if(document.getElementById("City" + i).value.trim() == "")
				  {
					  
					  error += "Enter city or town. <br> ";
					  
					  
				  } 
				 
				 if(document.getElementById("Province" + i).value.trim() == "")
				  {
					  
					  error += "Enter province. <br> ";
					
					  
				  } 
				  
			  }
		
		  }
		  
		  
		  
	   
	   }
	  
	  
	  
	  
	 
	   
	   
	  
	  
	  if(error == "" )
	   {
		   
		  document.getElementById("LoadingCreate").style.display = "block";
		  
		  obj.submit(); 
		   
	   }
	  else
	   {
		   
		   
	  	 document.getElementById("RegMessage").style.display = "block";
		 document.getElementById("RegMessage").innerHTML = error;
		 scroll(0,0)
		
	   }
	   
	   
	  
	
 }
 
 
 
 
 function getComments(category, article_id, order, page)
 {
	 
	 document.getElementById("LoaderDisplayComments").style.display = "block";	
	 
	 if(category != "" && article_id != "" )
	  {
		  
		 var xmlHttp;
				
			try
			 {    // Firefox, Opera 8.0+, Safari    
				
				xmlHttp=new XMLHttpRequest();  
				
			 }
			 
		   catch (e)
			{    // Internet Explorer    
			try
			  {      
			  
				xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");      
			  
			  }
			  
				catch (e)
				  {   
				  try
					{        
					 
					 xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");        
					 
					}
				  catch (e)
					{        
						alert("Your browser does not support AJAX!");        
						return false;        
						
					}      
				  }    
			  
			  }
					 
			 xmlHttp.onreadystatechange=function()
			  {
				  
				  if(xmlHttp.readyState==4)
					{
						
						
						document.getElementById("LoaderDisplayComments").style.display = "none";	
						
						var response = xmlHttp.responseText.trim();
						
					
						
						var result = response.split("|*|");
						
						if(result[0] > 0)
						 {
							 
							 document.getElementById("CommentsContent").innerHTML = result[1];
							 
						 }
					
						
					}
				  else
					{
						
						document.getElementById("LoaderDisplayComments").style.display = "block";	
						
					}
		
					
			 }
		
		
		
	
		   
		   var param = 'action=display_comments&rand=' + Math.random() + '&category=' + category + '&article_id=' + article_id + '&order=' + order + '&page=' + page;
		   
			xmlHttp.open('POST', 'ajax_comments.php', true);    
			xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");    
			xmlHttp.setRequestHeader("Content-length", param.length);    
			xmlHttp.setRequestHeader("Connection", "close");    
			xmlHttp.send(param);
	 
	  }
	 
 }
 
 
 
 
 
 
 function addComments(category, article_id)
 {
	 
	 	
	 
	 //var name = document.getElementById("Username").value.trim();
	 //var email = document.getElementById("Email").value.trim();
	 var comments = urlencode(document.getElementById('CommentsTxt').value.trim());
	 
	 var error = "";
	 
	 if(comments == "")
	  {
		  
		  error = "Please enter comments. \n";
		  
	  }
	 
	 
	 if(error == "")
	  {
		  
		 var xmlHttp;
				
			try
			 {    // Firefox, Opera 8.0+, Safari    
				
				xmlHttp=new XMLHttpRequest();  
				
			 }
			 
		   catch (e)
			{    // Internet Explorer    
			try
			  {      
			  
				xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");      
			  
			  }
			  
				catch (e)
				  {   
				  try
					{        
					 
					 xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");        
					 
					}
				  catch (e)
					{        
						alert("Your browser does not support AJAX!");        
						return false;        
						
					}      
				  }    
			  
			  }
					 
			 xmlHttp.onreadystatechange=function()
			  {
				  
				  if(xmlHttp.readyState==4)
					{
						
						var response = xmlHttp.responseText.trim();
						
						
						
						var result = response.split("|*|");
						
						document.getElementById("LoaderAddComments").style.display = "none";
						
						if(result[0] == 1)
						 {
							
							document.getElementById('CommentsTxt').value = ""
							getComments(category, article_id, 'ASC', '1' );
							 
						 }
						else
						 {
							 
							alert("Comment not submitted. Please comeback soon. ");
							
						 }
						 
					}
				   else
				    {
						
						
					    document.getElementById("LoaderAddComments").style.display = "block";
					
					}
					
			 }
		
		
		
	
		   
		   var param = 'action=add_comments&rand=' + Math.random() + '&comments=' + comments + '&article_id=' + article_id + '&category=' + category;
		   
			xmlHttp.open('POST', 'ajax_comments.php', true);    
			xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");    
			xmlHttp.setRequestHeader("Content-length", param.length);    
			xmlHttp.setRequestHeader("Connection", "close");    
			xmlHttp.send(param);
	 
	  }
	 else
	  {
		  
			alert(error);
			
	  }
	 
 }
 
 
 
 
 
 function sendPassword(){

	
	var error=""; 
	
	obj=document.forget_password_form;

	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;

  	var address = document.getElementById('Email').value.trim();

	var email = urlencode(document.getElementById('Email').value.trim());	


	if (email==""){

		error = error + "* Enter email address. <br>";

	}
	else if(reg.test(address) == false) {

		error = error + "* Enter a valid Email Address <br>";

	}

	
	
	if(error == "")
	 {
		 
		 document.getElementById("LoadingRegister").style.display = "block";
		 obj.submit();

	 }
	else
	 {
		 
		 document.getElementById("RegMessage").style.display = "block";
		 document.getElementById("RegMessage").innerHTML = error;
						
	 }



}
 
 
 
 
function reportPage(page)
 {
	 
	 var url = urlencode(page.trim());
	 
	 var error = "";
	 
	 if(url == "")
	  {
		  
		  error = "URL not found";
		  
	  }
	 
	 
	 
	 if(error == "")
	  {
		  
		 var xmlHttp;
				
			try
			 {    // Firefox, Opera 8.0+, Safari    
				
				xmlHttp=new XMLHttpRequest();  
				
			 }
			 
		   catch (e)
			{    // Internet Explorer    
			try
			  {      
			  
				xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");      
			  
			  }
			  
				catch (e)
				  {   
				  try
					{        
					 
					 xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");        
					 
					}
				  catch (e)
					{        
						alert("Your browser does not support AJAX!");        
						return false;        
						
					}      
				  }    
			  
			  }
					 
			 xmlHttp.onreadystatechange=function()
			  {
				  
				  if(xmlHttp.readyState==4)
					{
						
						var response = xmlHttp.responseText.trim();
						
						
						
						var result = response.split("|*|");
						
						document.getElementById("ReportLoader").style.display = "none";
						
						if(result[0] == 1)
						 {
							
							document.getElementById("ReportLoader").style.display = "none";
							//document.getElementById("ReportLoader").style.display = "block";

							document.getElementById("reportAbuse").innerHTML = "This article has been reported to the Administrator.";
							
							 
						 }
						
						 
					}
				   else
				    {
						
						
					    document.getElementById("ReportLoader").style.display = "block";
					
					}
					
			 }
		
		
		
	
		   
		   var param = 'action=report_abuse&rand=' + Math.random() + '&url=' + url;
		   
			xmlHttp.open('POST', 'ajax_comments.php', true);    
			xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");    
			xmlHttp.setRequestHeader("Content-length", param.length);    
			xmlHttp.setRequestHeader("Connection", "close");    
			xmlHttp.send(param);
	 
	  }
	 else
	  {
		  
			alert(error);
			
	  }
	 
	 
	 
 }
 
 
 
 
 
 //STAR RATING..
function changeStar(action, rate, img1, img2)
 {
	 
	 var star1 = img1;
	 var star2 = img2;
	 
	
	  
	 var maxstar = 5; 
	 
	 var orig_rate = document.getElementById('OrigRate').value.trim();
	 
	 if(action == "over")
	  {
		  
	   	for(i=1; i<=rate; i++)
		  {
			  
			document["btnstar" + i].src = star2;
				
		  }
  
	  }
	 else if(action == "out")
	  {
		  
		 for(i=rate; i>orig_rate; i--)
		  {
			  
			document["btnstar" + i].src = star1;
				
		  } 
		  
	  }
	 else
	  {
		  
		 document.getElementById('MyRate').value = rate;			
		 document.getElementById('OrigRate').value = rate; 
		 
		 for(i=1; i<=maxstar; i++)
		  {
			  
			document["btnstar" + i].src = star1;
				
		  } 
		 
		 changeStar('over', rate, img1, img2);
		  
	  }
	  
	 
	 
 }
 
 
 
 
 

 
 
 function submitRating(article_id, category, orig_rate)
 {	
	
	 var rate = document.getElementById("MyRate").value;
	
	 var error = "";
	 
	 if(rate == "" || rate== 0)
	  {
		  
		  error = "Please select your rating. ";
		  
	  }
	 
	 
	 
	 if(error == "")
	  {
		  
		 var xmlHttp;
				
			try
			 {    // Firefox, Opera 8.0+, Safari    
				
				xmlHttp=new XMLHttpRequest();  
				
			 }
			 
		   catch (e)
			{    // Internet Explorer    
			try
			  {      
			  
				xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");      
			  
			  }
			  
				catch (e)
				  {   
				  try
					{        
					 
					 xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");        
					 
					}
				  catch (e)
					{        
						alert("Your browser does not support AJAX!");        
						return false;        
						
					}      
				  }    
			  
			  }
					 
			 xmlHttp.onreadystatechange=function()
			  {
				  
				  if(xmlHttp.readyState==4)
					{
						
						var response = xmlHttp.responseText.trim();
				
						
						var result = response.split("|*|");
						
						//document.getElementById("LoaderRating").style.display = "none";
						document.getElementById("LoaderRating").innerHTML = "You rated this article " + rate + " flags";

						
						if(result[0] == 0)
						 {
							
							alert("You can't rate at this time. Please checkback soon. ");
							 
						 }
						
						
						 
					}
				   else
				    {
						
						
					    document.getElementById("LoaderRating").style.display = "block";
					
					}
					
			 }
		
		
		
	
		   
		   var param = 'action=insert_rating&rand=' + Math.random() + '&article_id=' + article_id + '&category=' + category + '&orig_rate=' + orig_rate + '&rate=' + rate;
		   
			xmlHttp.open('POST', 'ajax_comments.php', true);    
			xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");    
			xmlHttp.setRequestHeader("Content-length", param.length);    
			xmlHttp.setRequestHeader("Connection", "close");    
			xmlHttp.send(param);
	 
	  }
	 else
	  {
		  
			alert(error);
			
	  }
	 
	 
	 
 }
 
 


function getPages(member_id, page)
 {
	 
	
	 document.getElementById("LoaderDisplayPage").style.display = "block";	
	 
	 if(member_id != "")
	  {
		  
		 
		 var xmlHttp;
				
			try
			 {    // Firefox, Opera 8.0+, Safari    
				
				xmlHttp=new XMLHttpRequest();  
				
			 }
			 
		   catch (e)
			{    // Internet Explorer    
			try
			  {      
			  
				xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");      
			  
			  }
			  
				catch (e)
				  {   
				  try
					{        
					 
					 xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");        
					 
					}
				  catch (e)
					{        
						alert("Your browser does not support AJAX!");        
						return false;        
						
					}      
				  }    
			  
			  }
					 
			 xmlHttp.onreadystatechange=function()
			  {
				  
				  if(xmlHttp.readyState==4)
					{
						
						
						document.getElementById("LoaderDisplayPage").style.display = "none";	
						
						var response = xmlHttp.responseText.trim();
						 
						
						var result = response.split("|*|");
						
						if(result[0] > 0)
						 {
							 
							 document.getElementById("YourPage").innerHTML = result[1];
							 
						 }
					
						
					}
				  else
					{
						
						document.getElementById("LoaderDisplayPage").style.display = "block";	
						
					}
		
					
			 }
		
		
		
	
		   
		   var param = 'action=get_pages&rand=' + Math.random() + '&member_id=' + member_id + '&page=' + page; 
		   
			xmlHttp.open('POST', 'ajax_comments.php', true);    
			xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");    
			xmlHttp.setRequestHeader("Content-length", param.length);    
			xmlHttp.setRequestHeader("Connection", "close");    
			xmlHttp.send(param);
	 
	  }
	 
 }


 function getEditingArticleBranches(category, article_id, branch_id)
 {
	 
	 if(category != "" && article_id != "" )
	  {
		  
		 var xmlHttp;
				
			try
			 {    // Firefox, Opera 8.0+, Safari    
				
				xmlHttp=new XMLHttpRequest();  
				
			 }
			 
		   catch (e)
			{    // Internet Explorer    
			try
			  {      
			  
				xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");      
			  
			  }
			  
				catch (e)
				  {   
				  try
					{        
					 
					 xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");        
					 
					}
				  catch (e)
					{        
						alert("Your browser does not support AJAX!");        
						return false;        
						
					}      
				  }    
			  
			  }
					 
			 xmlHttp.onreadystatechange=function()
			  {
				  
				  if(xmlHttp.readyState==4)
					{
						document.getElementById("BranchList").innerHTML = xmlHttp.responseText;
							 
					
					}
				  
			 }
		
		
		
	
		   
		   var param = 'action=display_branches&rand=' + Math.random() + '&category=' + category + '&article_id=' + article_id + '&branch_id=' + branch_id;
		   
			xmlHttp.open('POST', 'editArticleAssets.php', true);    
			xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");    
			xmlHttp.setRequestHeader("Content-length", param.length);    
			xmlHttp.setRequestHeader("Connection", "close");    
			xmlHttp.send(param);
	 
	  }
	 
 }



 function deleteEditingBranch(category, article_id, branch_id)
 {
	 
			 var xmlHttp;
				
			try
			 {    // Firefox, Opera 8.0+, Safari    
				
				xmlHttp=new XMLHttpRequest();  
				
			 }
			 
		   catch (e)
			{    // Internet Explorer    
			try
			  {      
			  
				xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");      
			  
			  }
			  
				catch (e)
				  {   
				  try
					{        
					 
					 xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");        
					 
					}
				  catch (e)
					{        
						alert("Your browser does not support AJAX!");        
						return false;        
						
					}      
				  }    
			  
			  }
					 
			 xmlHttp.onreadystatechange=function()
			  {
				  
				  if(xmlHttp.readyState==4)
					{
						getEditingArticleBranches(category, article_id);	 
					//document.getElementById("BranchList").innerHTML = xmlHttp.responseText;
					}
				  
			 }
		
		
		
	
		   
		   var param = 'action=delete_branch&rand=' + Math.random() + '&category=' + category + '&article_id=' + article_id + '&branch_id=' + branch_id;
		   
			xmlHttp.open('POST', 'editArticleAssets.php', true);    
			xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");    
			xmlHttp.setRequestHeader("Content-length", param.length);    
			xmlHttp.setRequestHeader("Connection", "close");    
			xmlHttp.send(param);
	 

	 
 }



function saveEditingBranch(category, article_id, branch_id)
 {
	 
			 var xmlHttp;
				
			try
			 {    // Firefox, Opera 8.0+, Safari    
				
				xmlHttp=new XMLHttpRequest();  
				
			 }
			 
		   catch (e)
			{    // Internet Explorer    
			try
			  {      
			  
				xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");      
			  
			  }
			  
				catch (e)
				  {   
				  try
					{        
					 
					 xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");        
					 
					}
				  catch (e)
					{        
						alert("Your browser does not support AJAX!");        
						return false;        
						
					}      
				  }    
			  
			  }
					 
			 xmlHttp.onreadystatechange=function()
			  {
				  
				  if(xmlHttp.readyState==4)
					{
						getEditingArticleBranches(category, article_id);	 
					//document.getElementById("BranchList").innerHTML = xmlHttp.responseText;
					}
				  
			 }
		var mainValue="";
		
		if (document.getElementById('mainB').checked == true) { mainValue = "Y"; }
	
		   
		   var param = 'action=save_branch&rand=' + Math.random() + '&category=' + category + '&article_id=' + article_id + '&branch_id=' + branch_id;
			param += '&BranchName=' + encodeURIComponent(document.getElementById('BranchNameB').value);
		   	param += '&Barangay=' + encodeURIComponent(document.getElementById('BarangayB').value);
		   param += '&Street=' + encodeURIComponent(document.getElementById('StreetB').value);
		   param += '&City=' + encodeURIComponent(document.getElementById('CityB').value);
		   param += '&Province=' + encodeURIComponent(document.getElementById('ProvinceB').value);
		   param += '&Number=' + encodeURIComponent(document.getElementById('NumberB').value);
		   param += '&Direction=' + encodeURIComponent(document.getElementById('DirectionB').value);
		   param += '&GpsCode=' + encodeURIComponent(document.getElementById('GpsCodeB').value);
		   param += '&WeatherCode=' + encodeURIComponent(document.getElementById('WeatherCodeB').value);
		   param += '&Main=' + mainValue;
		   



			xmlHttp.open('POST', 'editArticleAssets.php', true);    
			xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");    
			xmlHttp.setRequestHeader("Content-length", param.length);    
			xmlHttp.setRequestHeader("Connection", "close");    
			xmlHttp.send(param);
	 

	 
 }

function addEditingBranch(category, article_id, branch_id)
 {
	 
			 var xmlHttp;
				
			try
			 {    // Firefox, Opera 8.0+, Safari    
				
				xmlHttp=new XMLHttpRequest();  
				
			 }
			 
		   catch (e)
			{    // Internet Explorer    
			try
			  {      
			  
				xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");      
			  
			  }
			  
				catch (e)
				  {   
				  try
					{        
					 
					 xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");        
					 
					}
				  catch (e)
					{        
						alert("Your browser does not support AJAX!");        
						return false;        
						
					}      
				  }    
			  
			  }
					 
			 xmlHttp.onreadystatechange=function()
			  {
				  
				  if(xmlHttp.readyState==4)
					{
						getEditingArticleBranches(category, article_id);	 
					//document.getElementById("BranchList").innerHTML = xmlHttp.responseText;
					}
				  
			 }
		var mainValue="";
		
		if (document.getElementById('mainB').checked == true) { mainValue = "Y"; }
	
		   
		   var param = 'action=save_branch&rand=' + Math.random() + '&category=' + category + '&article_id=' + article_id + '&branch_id=new';
			param += '&BranchName=' + encodeURIComponent(document.getElementById('BranchNameB').value);
		   	param += '&Barangay=' + encodeURIComponent(document.getElementById('BarangayB').value);
		   param += '&Street=' + encodeURIComponent(document.getElementById('StreetB').value);
		   param += '&City=' + encodeURIComponent(document.getElementById('CityB').value);
		   param += '&Province=' + encodeURIComponent(document.getElementById('ProvinceB').value);
		   param += '&Number=' + encodeURIComponent(document.getElementById('NumberB').value);
		   param += '&Direction=' + encodeURIComponent(document.getElementById('DirectionB').value);
		   param += '&GpsCode=' + encodeURIComponent(document.getElementById('GpsCodeB').value);
		   param += '&WeatherCode=' + encodeURIComponent(document.getElementById('WeatherCodeB').value);
		   param += '&Main=' + mainValue;
		   



			xmlHttp.open('POST', 'editArticleAssets.php', true);    
			xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");    
			xmlHttp.setRequestHeader("Content-length", param.length);    
			xmlHttp.setRequestHeader("Connection", "close");    
			xmlHttp.send(param);
	 

	 
 }


function getEditingArticlePhotos(category, article_id, photo_id)
 {
	 
	 if(category != "" && article_id != "" )
	  {
		  
		 var xmlHttp;
				
			try
			 {    // Firefox, Opera 8.0+, Safari    
				
				xmlHttp=new XMLHttpRequest();  
				
			 }
			 
		   catch (e)
			{    // Internet Explorer    
			try
			  {      
			  
				xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");      
			  
			  }
			  
				catch (e)
				  {   
				  try
					{        
					 
					 xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");        
					 
					}
				  catch (e)
					{        
						alert("Your browser does not support AJAX!");        
						return false;        
						
					}      
				  }    
			  
			  }
					 
			 xmlHttp.onreadystatechange=function()
			  {
				  
				  if(xmlHttp.readyState==4)
					{
						document.getElementById("PhotoList").innerHTML = xmlHttp.responseText;
							 
					
					}
				  
			 }
		
		
		
	
		   
		   var param = 'action=display_photos&rand=' + Math.random() + '&category=' + category + '&article_id=' + article_id + '&photo_id=' + photo_id;
		   
			xmlHttp.open('POST', 'editArticleAssets.php', true);    
			xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");    
			xmlHttp.setRequestHeader("Content-length", param.length);    
			xmlHttp.setRequestHeader("Connection", "close");    
			xmlHttp.send(param);
	 
	  }
	 
 }

function deleteEditingPhoto(category, article_id, photo_id)
 {
	 
			 var xmlHttp;
				
			try
			 {    // Firefox, Opera 8.0+, Safari    
				
				xmlHttp=new XMLHttpRequest();  
				
			 }
			 
		   catch (e)
			{    // Internet Explorer    
			try
			  {      
			  
				xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");      
			  
			  }
			  
				catch (e)
				  {   
				  try
					{        
					 
					 xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");        
					 
					}
				  catch (e)
					{        
						alert("Your browser does not support AJAX!");        
						return false;        
						
					}      
				  }    
			  
			  }
					 
			 xmlHttp.onreadystatechange=function()
			  {
				  
				  if(xmlHttp.readyState==4)
					{
						getEditingArticlePhotos(category, article_id);	 
					//document.getElementById("PhotoList").innerHTML = xmlHttp.responseText;
					}
				  
			 }
		
		
		
	
		   
		   var param = 'action=delete_photo&rand=' + Math.random() + '&category=' + category + '&article_id=' + article_id + '&photo_id=' + photo_id;
		   
			xmlHttp.open('POST', 'editArticleAssets.php', true);    
			xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");    
			xmlHttp.setRequestHeader("Content-length", param.length);    
			xmlHttp.setRequestHeader("Connection", "close");    
			xmlHttp.send(param);
	 

	 
 }






//BUCKET LIST

//add to bucket
addtoBucket=function(category, articleid) {
	 
	var error = "";
	
	if(category == "" || articleid == "")
	 {
		
		error += "Category or Article ID not defined. \n";
		
	 }//end if
	 
	if(error == "")
	 {
	 
		//organize the data properly
		var data = 'action=addto_bucket' + '&rand=' + Math.random() + '&category=' + category + '&articleid=' + articleid;
		
		//show the loading sign
		$('#HolderBucket').css({ opacity: 0.5 });
		 
		//start the ajax
		$.ajax({
			//this is the php file that processes the data and send mail
			url: "ajax_return.php",	
			
			//GET method is used
			type: "POST",
	
			//pass the data			
			data: data,		
			
			//Do not cache the page
			cache: false,
			
			//success
			success: function (html) {			
				
				var result =  html.split("|||");
				
				$('#HolderBucket').css({ opacity: 1.0 });
			 
				if(result[0] > 0)
				{
				   //done show increment bucket list
				   $('#BucketCount').html(result[1]);
				   $('#HolderBucket').html('You have added this in your bucket list.');
				}
			   else
			    {
					alert("Error adding article in your bucket list. Please comeback later. \n");
				}
				
				 
 			}//end success
			
		});//end ajax
		
		
	 }//end else
	 
	 
	//cancel the submit button default behaviours
	return false;
		
		
}
//end add to bucket



//add to done
addtoDone=function(category, articleid) {
	 
	var error = "";
	
	if(category == "" || articleid == "")
	 {
		
		error += "Category or Article ID not defined. \n";
		
	 }//end if
	 
	if(error == "")
	 {
	 
		//organize the data properly
		var data = 'action=addto_done' + '&rand=' + Math.random() + '&category=' + category + '&articleid=' + articleid;
		
		//show the loading sign
		$('#HolderBucket').css({ opacity: 0.5 });
		 
		//start the ajax
		$.ajax({
			//this is the php file that processes the data and send mail
			url: "ajax_return.php",	
			
			//GET method is used
			type: "POST",
	
			//pass the data			
			data: data,		
			
			//Do not cache the page
			cache: false,
			
			//success
			success: function (html) {			
				 
				var result =  html.split("|||");
				
				$('#HolderDone').css({ opacity: 1.0 });
			 
				if(result[0] > 0)
				{
				   //done show increment bucket list
				   $('#DoneCount').html(result[1]);
				   $('#HolderDone').html('You have done this.');
				   $('#HolderBucket').html('');
				}
			   else
			    {
					alert("Error adding article in your done list. Please comeback later. \n");
				}
				
				 
 			}//end success
			
		});//end ajax
		
		
	 }//end else
	 
	 
	//cancel the submit button default behaviours
	return false;
		
		
}
//end add to done



//END BUCKET LIST






//LINK DAYS			
linkCal=function(lmonth, lday, lyear) {
   
	 //organize the data properly
	var data = 'action=link_calendar' + '&rand=' + Math.random() + '&month=' + lmonth  + '&year=' + lyear + '&day=' + lday  
	

	 //show the loading sign
	$('.calendar-events-placeholder').css({ opacity: 0.5 });
	
	//start the ajax
	$.ajax({
		//this is the php file that processes the data and send mail
		url: "get_calendar.php",	
		
		//GET method is used
		type: "POST",

		//pass the data			
		data: data,		
		
		//Do not cache the page
		cache: false,
		
		//success
		success: function (html) {			
			 
		   var result = html;
		   
		   $('.calendar-events-placeholder').css({ opacity: 1.0 });	
		   
		   if(result)
			{
	 
				$('.calendar-events-placeholder').html(result);
				
			}
	
		}//end success
		
	});//end ajax

	//cancel the submit button default behaviours
	return false;
		
	 
}


