/* print */
function printPopup(url) {
	var newwindow=window.open(url,'','status=1,scrollbars=1,height=800,width=780');
	if (window.focus) {newwindow.focus()}	
	return false;
}


/* comments */
function validate(opt,scriptUrl)
{
	var name			=	document.getElementById("name").value;
	var comment			=	document.getElementById("comment").value;
	
	if(name.length==0 || comment.length==0)
	{
		alert("Please enter valid Name and Comment");
		return false;
	}

	if(name.length>30)
	{
		alert("Maximum charector exceeded in Name");
		return false;
	}
	if(comment.length>2000)
	{
		alert("Maximum charectors exceeded in Comment");
		return false;
	}
	document.getElementById("commentError").innerHTML="";
	if(opt=="preview")
	{
		document.getElementById("btnPreview").style.display="none";
		document.getElementById("btnEdit").style.display="block";
		getPreview(name,comment,scriptUrl);
	}
	else
	{
		var captcha_code = document.getElementById("captcha_code").value;
		if(captcha_code.length==0){ alert("Please enter the Access Code"); return false;}
		
		document.getElementById("postName").value=name;
		document.getElementById("postComment").value=comment;
		document.getElementById("frmComment").submit();
	}
	return true;
}
function edit()
{
	var commentEntryBox = 	document.getElementById("commentEntryBox");
	var commentPreviewBox = document.getElementById("commentPreviewBox");
	commentEntryBox.style.display="block";
	commentPreviewBox.style.display="none";
	document.getElementById("btnPreview").style.display="block";
	document.getElementById("btnEdit").style.display="none";
}
function getPreview(argName,argComment,scriptUrl)
{
	var post = "name="+argName+"&comment="+argComment;
	AJAX("preview",scriptUrl,post)
}
	
function AJAX(strType,strURL,post)
{
    var xmlHttpReq = false;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }   
    xmlHttpReq.open('POST', strURL, true);
	//    xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlHttpReq.onreadystatechange = function() 
	{
        if (xmlHttpReq.readyState == 4) 
		{
			if(strType=="preview") {  showPreview(xmlHttpReq.responseText); }
			
        }
    }
	xmlHttpReq.setRequestHeader( 'Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8' ); 
    xmlHttpReq.send(post);
}

function showPreview(preview)
{

	var commentEntryBox = 	document.getElementById("commentEntryBox");
	var commentPreviewBox = document.getElementById("commentPreviewBox");
	commentPreviewBox.style.display="block";
	var commentPreview 	= 	document.getElementById("commentPreview");

	var postName		=	document.getElementById("postName");
	var date			=	"";
	var postComment		=	document.getElementById("postComment");

//		alert(preview);
	preview				=	preview.split("\n");
	postName.value		=	preview[0];
	date				=	preview[1];
	postComment.value	=	preview[2];
	
	commentPreview.innerHTML = "<div class='commentTitle'><u>"+postName.value+"</u> | <u>"+date+"</u></div><p class='commentText'>"+postComment.value+"</p>";
	commentEntryBox.style.display="none";
	return true;
}


var popupStatus = 0; 
function loadPopup(){
	if(popupStatus==0){
		$("#popupCities").fadeIn("slow");
		popupStatus = 1;
	}
}
function disablePopup(){
	if(popupStatus==1){
		$("#popupCities").fadeOut("slow");
		popupStatus = 0;
	}
}

