//javascript
function getHttpObject()
{
	var httpobject=null;
 	if(window.XMLHttpRequest)
 	{
 		 httpobject=new XMLHttpRequest();
 	}
 	else if(window.ActiveXObject)
 	{
  		try{
   			httpobject=new ActiveXObject("Msxml2.XMLHTTP");
  			}
  		catch(e){
   				try{
   					httpobject=new ActiveXObject("Microsoft.XMLHTTP");
		  			}
		  		catch(e){
  					 	alert("could not find the http requst object");
   						return false;
  						}
  				}
  	}
  return httpobject;
}

function SubmitCommentForm()
{
	httpobject=getHttpObject();
	var author = document.getElementById('author').value;	
	var email = document.getElementById('email').value;
	var url = document.getElementById('url').value;
	var comment = document.getElementById('comment').value;
	var comment_post_ID = document.getElementById('comment_post_ID').value;
	var rating = document.getElementById('rating').value;
	var redirect_to = document.getElementById('redirect_to').value;
	if(document.getElementById('user_id'))
	{
		var user_id = document.getElementById('user_id').value;
	}
	else
	{
		var user_id = 0;
	}
	//alert ("author="+author+" email="+email+" url="+url+"<br>comment="+comment+"<br>comment_post_id="+comment_post_ID+" rating="+rating+" redirect to ="+redirect_to);
	
	var url2="../misc_test.php";
	var parameters = "author="+encodeURI(author)+"&email="+encodeURI(email)+"&url="+encodeURI(url)+"&comment="+encodeURI(comment)+"&comment_post_ID="+encodeURI(comment_post_ID)+"&rating="+encodeURI(rating)+"&redirect_to="+encodeURI(redirect_to)+"&user_id="+encodeURI(user_id);	
	
	//alert(parameters);
	
	httpobject.onreadystatechange=getReponse
	httpobject.open('POST',url2,true);
	httpobject.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    httpobject.setRequestHeader("Content-length", parameters.length);
    httpobject.setRequestHeader("Connection", "close");
	httpobject.send(parameters);
	
}

/*function getReponse()
{
	if(httpobject.readyState==4)
	{
		response = httpobject.responseText;
		//alert(response);
		//document.getElementById('newComment').innerHTML=response
		window.location.reload();
	}
}*/

function getReponse()
{
	
	if(httpobject.readyState==4)
	{
		response = httpobject.responseText;
		
		var currentUrl = window.location.href;
		//alert(currentUrl);
		var redirect_param = gup( 'qs' ); 
		//alert(redirect_param);
		
		if(redirect_param != "")
		{
			var url = window.location.href;
			urlClean = url.split("&");
			redirect_to=urlClean[0];
		}
		else
		{
			redirect_to		=	window.location.href;
		}
		
		redirect_to		=	redirect_to+"&qs="+ Math.random();
		
	//	alert(redirect_to);
		//redirect_url 		=	redirect_to.split("?") ;
		//alert(redirect_url[0]);
		//redirect_to="?qs="+ Math.random();	
		
		//alert(redirect_to);
		//window.location.reload();
		window.open(redirect_to,"_parent");
		
	}
}



function gup( name )
{
  var regexS = "[\\&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var tmpURL = window.location.href;
  var results = regex.exec( tmpURL );
  if( results == null )
    return "";
  else
    return results[1];
}
