// JavaScript Document
/*
Author: KKS
Email: kaushalkumarshah@gmail.com
*/

//load the page
function loadThis(pagename){
	if(pagename != null){
		$("#countrydivcontainer").html("<img src='images/tab/loading.gif' /> Loading...")
		$("#countrydivcontainer").load(pagename);
	}
}

function showHideConceptDetail(divid){
	if(document.getElementById(divid)){
		if(document.getElementById(divid).style.display == "block")
			document.getElementById(divid).style.display = "none";
		else
			document.getElementById(divid).style.display = "block";
	}
//<<<<<<< .mine
}
 

/*
submit the comments in concept detail using jquery ajax
Author:KKS kaushalkumarshah@gmail.com
*/
$(document).ready(function(){									
			$("#submit").click(function() {
			//$("#msgbox").hide();
			
				var options = 
					 { 
						 url				: 'loader.php?mod=cboulevard&act=mail',	
						 //target: '#msgbox',
						 resetForm		: true,
						 beforeSubmit	: checkEmpty,
						 success		: showResponse
					 };
					
						
				      $("#commentFrm").ajaxSubmit(options);
					  //$("#commentFrm").ajaxSForm(options);
				      return false; // cancel conventional submit
 			 });

			
			
		});

function showResponse(responseText, statusText)  {			
			var outputMessage = "";
			//alert(responseText);
			if(responseText == 1){
				$("#msgbox").removeClass("red");
				outputMessage = "Uw reactie is succesvol verstuurd.";
			}
			else if(responseText == 2){
				$("#msgbox").addClass("red");
				outputMessage = "Session has expired. Please refresh the page.";
			}
			else{
				$("#msgbox").addClass("red");
				outputMessage = "Uw reactie is not verstuurd.";
			}
			$("#msgbox").slideDown("slow");
			$("#msgbox").text(outputMessage).fadeIn("slow");	
		}

function checkEmpty(){
	$("#msgbox").text("");
	$("#msgbox").addClass("red");
	if($("#txtConceptEmail").val() == "" || $("#txtConceptName").val() == ""){
		$("#msgbox").append("Posting comment is blocked for invalid concept.<br/>");
		$("#msgbox").slideDown("slow");			
		return false;
	}
	else if($("#txtUser").val()== "" || $("#txtEmail").val()== "" || !checkEmail($("#txtEmail").val())){					
		if($("#txtUser").val()== ""){
			
			$("#msgbox").append("Uw naam  is empty.<br/>");
			
		}
		if($("#txtEmail").val()== ""){
			
			$("#msgbox").append("Email is empty.<br/>");
		}
		else if(!checkEmail($("#txtEmail").val())){
			$("#msgbox").append("Please enter valid email address.<br/>");
		}
		$("#msgbox").slideDown("slow");			
		return false;
	}
	$("#msgbox").removeClass("red");
	$("#msgbox").append("<img src='images/tab/loading.gif' /> Posting your comments...");
	$("#msgbox").slideDown("slow");	
	return true;
}

/* Email Validation */
function checkEmail(thisEmail){  
//return true;
  var b=thisEmail.search(/^[a-z0-9\.\-_]{1,}@[a-z0-9\.\-_]{1,}\.[a-z]{2,4}$/);  
  if(b==-1){
  	return false;
  }
  else{
  	return true;
  }
}

//>>>>>>> .r21
