 function saveIdea(){
 
    if (document.getElementById("name").value==""){
    alert("Please enter name");
    return false;
    }
    if (document.getElementById("email").value==""){
    alert("Please enter email");
    return false;
    }
    if (document.getElementById("idea").value==""){
    alert("Please enter your thoughts");
    return false;
    }
    if (document.getElementById("imageVerifyText").value==""){
    alert("Please enter verification code");
    return false;
    }
    
    callAjaxToSaveData();
 }	
 
 
 xmlHttp=createXmlHttpObject();
function callAjaxToSaveData(){
var parameters="name="+encodeURI(document.getElementById("name").value);
parameters=parameters+"&"+"email="+encodeURI(document.getElementById("email").value);
parameters=parameters+"&"+"idea="+encodeURI(document.getElementById("idea").value);
parameters=parameters+"&topicName=valentine";
parameters=parameters+"&"+"imageVerifyText="+encodeURI(document.getElementById("imageVerifyText").value);
xmlHttp.open('POST', '/valentine.do?method=saveIdeas', true);
xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlHttp.setRequestHeader("Content-length", parameters.length);
xmlHttp.setRequestHeader("Connection", "close");
xmlHttp.onreadystatechange =processStateChange;
//alert(parameters);
xmlHttp.send(parameters);
//processStateChange();

}

function processStateChange(){
 //alert("State:"+xmlHttp.readyState+":Status:"+xmlHttp.status);
  if(xmlHttp.readyState  == 4 && xmlHttp.status  == 200) {
  var res=xmlHttp.responseText;
  if (res!='abuse' && res!='notverified'){
    //alert("your Thought is saved.");
 	document.getElementById("email").value='';
	document.getElementById("idea").value='';
	document.getElementById("name").value='';
	document.getElementById("imageVerifyText").value="";
	window.location="/valentine.do";
    }
   else if (res=='notverified') {
        alert("Entered verification code is not correct.");
        var randomnumber1=Math.floor(Math.random()*100);
		document.getElementById("jcaptchadiv").innerHTML='<img border="0" width="140" height="20" align="middle" src="/jcaptcha?id='+randomnumber1+'"/>';
        
        }
    else alert("Due to occurance of some profanity words in your thought, it is not saved.");
 	//document.getElementById("email").value='';
	//document.getElementById("idea").value='';
	//document.getElementById("name").value='';
	//document.getElementById("imageVerifyText").value="";
	//document.getElementById("jcaptchadiv").innerHTML="<img	src='/jcaptcha'	width='70' height='20' align='middle'/>";
	//alert(document.getElementById("jcaptchadiv").innerHTML);
  //insertJs();
  //mark the pop up
    //window.location.reload(true);
   }
}
/////////////////////////////////////
var xmlHttp;
function createXmlHttpObject(){
if (window.XMLHttpRequest){     // Object of the current windows
    xmlHttp = new XMLHttpRequest();     // Firefox, Safari, ...
   } 
   else if (window.ActiveXObject){   // ActiveX version
    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");  // Internet Explorer 
    } 
  return xmlHttp;
 }

 

