function openWin(content,pageheading){
	myWin= open("", "", "height=550, width=750, top=400, left=400,scrollbars=yes, toolbars=yes, resizeable=yes"); // open document for further output
	myWin.document.open();
	
	// create document
	myWin.document.write("<html><head>");
	myWin.document.write("<META HTTP-EQUIV='Content-Type' CONTENT='text/html; charset=ISO-8859-1'>");
	myWin.document.write("<title>Printable Recipe - Kulinary Kidz</title><style type=\"text/css\">img{display:none;}</style>");
	myWin.document.write('</head><body>');
	myWin.document.write('<h4>'+pageheading+'</h4>');
	myWin.document.write('</p><div align="left">');
	myWin.document.write(content);
	myWin.document.write('<p><a href=\"javascript:print()\">Print This Recipe</a></p></div>');
	myWin.document.write('</body></html>');
	
	// close the document - (not the window!)
	myWin.document.close(); 
}

function CommentFormCheck(ajax,action,next,formid){
	var querystr='';
	var theForm = document.getElementById(formid);
	var EmailFilter=/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if(!(document.getElementById('Commentr1')) || !(document.getElementById('Commentr2'))){
		return false;															 																 
	}
	if (document.getElementById('CommentName') && document.getElementById('CommentName').value==''){
			alert('Please enter your name');
			document.getElementById('CommentName').focus();
			document.getElementById("reqCommentName").style.fontWeight="bold";
			return false;
	}
	if (document.getElementById('CommentEmail') && !(EmailFilter.test(document.getElementById('CommentEmail').value))){
			alert('Please enter your email address correctly');
			document.getElementById('CommentEmail').focus();
			document.getElementById("reqCommentEmail").style.fontWeight="bold";
			return false;
	}
	if (document.getElementById('CommentProvider') && document.getElementById('CommentProvider').value==''){
			alert('Please enter the name of the new provider or brand!');
			document.getElementById('Commentrovider').focus();
			document.getElementById("reqCommentProvider").style.fontWeight="bold";
			return false;
	}	if (document.getElementById('CommentComments') && document.getElementById('CommentComments').value==''){
			alert('Please enter your comments');
			document.getElementById('CommentComments').focus();
			document.getElementById("reqCommentComments").style.fontWeight="bold";
			return false;
	}
	
	if (document.getElementById('Commentr1').value=='' || document.getElementById('Commentr2').value=='' || isNaN(document.getElementById('Commentr1').value) || isNaN(document.getElementById('Commentr2').value)){
		return false;
	}
	else{
		num1=parseInt(document.getElementById('Commentr1').value);
		num2=parseInt(document.getElementById('Commentr2').value);
		var sum= num1+ num2 ;
		if (document.getElementById('Comment').value!=sum){
			alert('Please enter the correct value of the equation, this is to stop spammers.');
			document.getElementById('Comment').focus();
			document.getElementById("reqComment").style.fontWeight="bold";
			return false;
		}
			
	}
	if(ajax){
		for (i=0;i<theForm.elements.length;i++){
			querystr=querystr+theForm.elements[i].name+'='+ theForm.elements[i].value+'&';
		}
		querystr=querystr+'submit=1';
		origSubmit='<input type=\"image\" src=\"/images/send.jpg\" name=\"Submit\" style=\"border:none; width:auto;height:auto;margin-left:160px;\" />';
		document.getElementById('commentProcessing').innerHTML="<img src='../images/ajax-loader.gif' style='float:right;padding-left:175px;border:0;'>";
		ajaxForm(action,querystr,next);
		return false;
	}
	return true;
}
function getHTTPObject(){
	var xhr=false;
	if(window.XMLHttpRequest){
		xhr=new XMLHttpRequest();
	}
	else if(window.ActiveXObject){
		try{
			xhr=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e){
			try{
				xhr=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(e){}
		}
	}
	return xhr;
}

function ajaxForm(action,request_vars,next){
	//window.onload=init;
	//alert(request_vars);
	http='';
	http=getHTTPObject();
	next_function = next;
	http.open('get',  '/' + action + '.php?' + request_vars);
	http.onreadystatechange = ajres;
	http.send(null);
}
function ajres() 
{
    if(http.readyState==4)
    {    	
		eval(next_function + "(http.responseText)"); 
	}
}
function commentformResult(result,param){
	if(result==0){
		document.getElementById('commentProcessing').innerHTML=origSubmit+'<h3>Sorry, there was an error. Try again.</h3>';
	}
	else if(result==2){
		document.getElementById('commentProcessing').innerHTML=origSubmit+'<br><h3>Sorry, you can\'t add. Try again.</h3>';	
	}
	else{
		alert(result);
		document.getElementById('commentProcessing').innerHTML='<h3>'+result+'</h3>';
	}
}