
// Function to Use Ajax.
function trim(s) {
   var temp = s;
   return temp.replace(/^\s+/,'').replace(/\s+$/,'');
}
function makeRequest(url,params) {
			var httpRequest;
		//alert('inside make request');

		//alert(url);
			if (window.XMLHttpRequest) { // Mozilla, Safari, ...
				httpRequest = new XMLHttpRequest();
				if (httpRequest.overrideMimeType) {
					httpRequest.overrideMimeType('text/xml');
					// See note below about this line
				}
			} 
			else if (window.ActiveXObject) { // IE
				try {
					httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
					} 
					catch (e) {
					   try {
							httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
						   } 
						 catch (e) {}
					  }
				   }
			if (!httpRequest) {
				alert('Giving up :( Cannot create an XMLHTTP instance');
				return false;
			}
			httpRequest.onreadystatechange = function() { alertContents(httpRequest); };
			httpRequest.open('POST', url, true);
			httpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			httpRequest.send(params);

		}


		function alertContents(httpRequest) {

			if (httpRequest.readyState == 4) {
				if (httpRequest.status == 200) 	{
				var h = httpRequest.responseText;
				var h = trim(h);
			//	alert('respose Text '+h);
				//h.match("true")=='true'
				//if(h == "false"){



//chk captcha
if(h.match("notSame")=='notSame' && h.match("loginValidationsForPostComments")=='loginValidationsForPostComments'){
	alert("Please put valid security code matching the above image.");
	document.frm.captchafield.focus();

}else if(h.match("same")=='same'&& h.match("loginValidationsForPostComments")=='loginValidationsForPostComments'){
    var loginForm=document.getElementById("cms.component.loginForm");
	document.getElementById("CommentsPostForm").style.visibility="hidden";
	document.getElementById("CommentsPostForm").style.display="none";
    document.getElementById("my").style.visibility="hidden";
    loginForm.style.visibility = "visible";
    document.getElementById("userId").value="";
    document.getElementById("password").value="";
    document.getElementById("userId").focus();
}


else if(h.match("notSame")=='notSame' && h.match("commentsPost")=='commentsPost'){

	alert("Please put valid security code matching the above image.");
		document.frm.captchafield.focus();
}else if(h.match("same")=='same'&& h.match("commentsPost")=='commentsPost'){

   startId=h.indexOf('+');
							if(startId!=-1){
							newString= h.substring(startId+1);
							endId=newString.indexOf('+');
							}
						if(startId!=-1 && endId!=-1)
							emailId=newString.substring(0,endId);

//alert("emailId"+emailId);
 commentsPost(true,emailId,true);
   
	}



else if(h.match("notSame")=='notSame' && h.match("makeReportAbuse")=='makeReportAbuse'){
alert("Please put valid security code matching the above image.");
document.cms_comment_reportabuse.captchafield.focus();
}else if(h.match("same")=='same'&& h.match("makeReportAbuse")=='makeReportAbuse'){
    startId=h.indexOf('+');
							if(startId!=-1){
							newString= h.substring(startId+1);
							endId=newString.indexOf('+');
							}
						if(startId!=-1 && endId!=-1)
							emailId=newString.substring(0,endId);

			makeReportAbuse(false,emailId,false);




}


else if(h.match("notSame")=='notSame' && h.match("makeReply")=='makeReply'){
	alert("Please put valid code matching the above image.");
	document.cms_comment_reply.captchafield.focus();
}else if(h.match("same")=='same'&& h.match("makeReply")=='makeReply'&& h.match("reply")!='reply'){
   //  makeReply(bool,userId,false);
	
	                      startId=h.indexOf('+');
							if(startId!=-1){
							newString= h.substring(startId+1);
							endId=newString.indexOf('+');
							}
						if(startId!=-1 && endId!=-1)
							emailId=newString.substring(0,endId);

	 
	 makeReply(true,emailId,false);
	 
	 
	// var loginForm=document.getElementById("cms.component.loginFormreply");
	// document.getElementById("replyForm").style.visibility="hidden";
	// document.getElementById("replyForm").style.display="none";
    // document.getElementById("replytable").style.visibility="hidden";
  //   loginForm.style.visibility = "visible";
  //   document.getElementById("userIdReply").value="";
 //    document.getElementById("passwordReply").value="";
 //    document.getElementById("userIdReply").focus();
	}

				
//

				
				
				
				
				
                if(h.match("false")=='false'){

						alert("Please put valid code.");
					}
				//	else if(h.match("true")!='true')
				//	{
					//	alert(h);
				//	alert("Message could not be posted.Please Post it again.");
				//	}
					else if(h.match("true")=='true') 
					{

			if(h.match("abuse")=='abuse'){
//alert(" Thank you for alerting us,your" +'\n' + "complaint has been successfully reported.");
				    document.getElementById("cms.component.readComments").style.visibility="hidden";
					document.getElementById("cms.component.readComments").style.display="none";
					document.getElementById("readCommentsTable").style.visibility="hidden";
					document.getElementById("readCommentsTable").style.display="none";
					document.getElementById("cms.component.loginFormAbuse").style.visibility="hidden";
					document.getElementById("cms.component.loginFormAbuse").style.display="none";
					document.getElementById("successAbuse").style.visibility="visible";

			
			
			}

			else if(h.match("reply")=='reply'){

				//alert("Your Reply Posted Sucessfully");

//alert(document.getElementById("cms.component.readComments"));
//alert(document.readCommentsTable);
//alert();

				document.readCommentsTable.style.visibility="hidden";
					document.getElementById("cms.component.readComments").style.visibility="hidden";
					document.getElementById("cms.component.readComments").style.display="none";
					document.getElementById("readCommentsTable").style.visibility="hidden";
					document.getElementById("readCommentsTable").style.display="none";
					document.getElementById("cms.component.loginFormreply").style.visibility="hidden";
					document.getElementById("cms.component.loginFormreply").style.display="none";
     				document.getElementById("successReply").style.visibility="visible";


				

			}
			else{
				//alert("Your comment has been" +'\n' +"successfully posted.");
			
					                document.getElementById("CommentsPostForm").style.visibility="hidden";
									document.getElementById("CommentsPostForm").style.display="none";
									document.getElementById("cms.component.loginForm").style.visibility="hidden";
									document.getElementById("cms.component.loginForm").style.display="none";
									document.getElementById("success").style.visibility="visible";
			
			
			
			clearData();

			
			
			
			}
//					document.getElementById("CommentsPostForm").style.visibility="hidden";
//									document.getElementById("CommentsPostForm").style.display="none";
//									document.getElementById("cms.component.loginForm").style.visibility="hidden";
//									document.getElementById("cms.component.loginForm").style.display="none";
//									document.getElementById("success").style.visibility="visible";
					}
				} 
			}
		}
		
		// Adding Dropdown in createDynamicComponent
		
		
		function onComponentChange(url,params,target) {
			//alert("raks help");
			var httpRequest;
			//alert("url="+url);
			if (window.XMLHttpRequest) { // Mozilla, Safari, ...
				httpRequest = new XMLHttpRequest();
				//if (httpRequest.overrideMimeType) {
				//	httpRequest.overrideMimeType('text/html');
					// See note below about this line
				//}
			} 
			else if (window.ActiveXObject) { // IE
				try {
					httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
					} 
					catch (e) {
					   try {
							httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
						   } 
						 catch (e) {}
					  }
				   }
			if (!httpRequest) {
				alert('Giving up :( Cannot create an XMLHTTP instance');
				return false;
			}
			httpRequest.onreadystatechange = function() { processResponse(httpRequest,target); };
			//alert(url);
			httpRequest.open('POST', url, true);
			httpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			httpRequest.send(params);

		}

		function processResponse(httpRequest,target) {

			if (httpRequest.readyState == 4) {
				if (httpRequest.status == 200) 	{
				
				//alert("handleHTTPResponse");     
				processComponentResponse( httpRequest.responseText,target);
            
        } else {
            //alert ( "Images r not equal" );
        }
    }    
}

		
function selectComponent(value,target)
{
		//var pathname = window.location.pathname;
		//alert(pathname);
		//alert("value :"+value);
		//var contextPath = pathname.substring( 0, pathname.indexOf("/faces") );
		
		onComponentChange("/cms/componentlist","value="+value,target);
}	

function selectSubCategory(value,target)
{
		//var pathname = window.location.pathname;
		//alert(pathname);
		
		//var contextPath = pathname.substring( 0, pathname.indexOf("/faces") );
		
		onComponentChange("/cms/subcategorylist","value="+value,target);
}	


	function processComponentResponse(response,target)
	{
		var responseDom = parseStringResponse(response);
		
		//alert("responsedom "+responseDom);
		
		var ctElem = responseDom.getElementsByTagName("response");
		
	    if (!ctElem || ctElem.length == 0) {
        										var options = new Array(0);
        										return options;
    										}
    		
									
    	var xmlElem = ctElem[0].getElementsByTagName("option");
    	var options = new Array(xmlElem.length);
    	
	   	//var target = document.getElementById("frm:complist");
    	//alert("target: "+target);
    	
    	target.length = options.length + 1;
    	
    	for (var i = 0; i < xmlElem.length; i++) 
    		{
				target.options[i + 1].selected=true;
        		target.options[i + 1].text = xmlElem[i].getAttribute("name");
        		target.options[i + 1].value = xmlElem[i].getAttribute("value");
        		//alert(target.options[i + 1].text);
        		//alert(target.options[i + 1].value);
        	}
		
	}
		
	
		
function parseStringResponse(result){
		 var xmlDoc;
		//load xml document
		if(document.implementation && document.implementation.createDocument) {
		// MOZILLA
			 xmlDoc = document.implementation.createDocument("", "", null);
			 xmlDoc.async="false";
			 xmlDoc.loadXML(result);
		} else if (window.ActiveXObject){
			//IE
			xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
			xmlDoc.async="false";
			xmlDoc.loadXML(result);
			
		}
		return xmlDoc;
     
}

function getHTTPObject() {
    var xmlhttp;
    if (window.XMLHttpRequest) {
        xmlhttp = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    } 
    return xmlhttp;
}






