function checkPasses(one,two)
{
   var pass=document.getElementById(one).value;
   var pass2=document.getElementById(two).value;

   if(pass!=pass2)
   {
    alert ("Passwords dont match!");
   }
}

function checkMail(email,frm)
{
      var mail=document.getElementById(email).value;
      
      if(mail=="")
      {
         alert("Please, fill in valid e-mail address.");
	 return false;
      }
      
      if(mail.indexOf("@")<2||mail.indexOf(".")<5)
      {
         alert("Please, fill in valid e-mail address.");
	 return false;
      }

      document.getElementById(frm).submit();
}

function confirmAction(frm)
{
   if(confirm("Are you sure?"))
   {
      frm.submit();
   }
   return true;
}

function centerWin(filename,width,height,name)
{
   var x=(screen.availWidth-width)/2;
   var y=(screen.availHeight-height)/2-50;

   if(name="") name='win'

   newWin=window.open(filename, name,"width=10,height=10, scrollbars=yes");
   newWin.moveTo(x,y);
   newWin.resizeTo(width,height);
}

function centerElt(eid,w,h)
{  
    elt=document.getElementById(eid);
   	if(!document.all) elt.style.position='fixed';			
    var centerY= Math.floor(Math.round(screen.height/4));
    var centerX= Math.floor(Math.round(screen.width/4));
	
    elt.style.top=(centerY-Math.floor(Math.round(h/4)))+"px";
    elt.style.left=(centerX-Math.floor(Math.round(w/4)))+"px";
	
    elt.style.display='block';
}


function loadComments(topic, offset)
{
	if(typeof(offset)=='undefined') offset=0;

	$('commentsDiv').innerHTML="<br /><br /><br /><br /><p align='center' style='font-family:verdana,sans-serif;font-weight:bold;'>Loading...</p>";

	centerElt('commentsDiv',400,500);

	var url="http://calendarscripts.info/index.php?action=ajax_comments";

	new Ajax.Request(url,
   {
	    method:'post',
	    parameters: { "topic": topic, "offset": offset },
	    onSuccess: function(transport)
	    {
		    var response = transport.responseText || "no response text"; 
			$('commentsDiv').innerHTML=response;
	    }
	});
}

function postComment(frm)
{
	var topic=frm.topic.value;
	var ip=frm.ip.value;	
	var name=frm.name.value;
	var email=frm.email.value;
	var mailStr=new String(email);
	var comment=frm.comment.value;
	
	if(typeof(offset)=='undefined') offset=0;
	
	if(name=='')
	{
		alert("Please enter your name or alias");
		frm.name.focus();
		return false;
	}
	
	 if(mailStr.indexOf("@")<2 || mailStr.indexOf(".")<5 || mailStr=='')
     {
         alert("Please, fill in valid e-mail address.");
		 frm.email.focus();
	 	 return false;
     }
	 
	 if(comment=="")
	 {
	 	alert("Please enter your comment");
		frm.comment.focus();
		return false;
	 }
	 
	 var notify=0;
	 if(frm.notify.checked) notify=1;
	
	var url="http://calendarscripts.info/index.php?action=ajax_comments";
	
	new Ajax.Request(url,
   {
	    method:'post',
	    parameters: { "topic": topic, "offset": offset, "ip": ip, "name": name, 
						"email": email, "comment": comment, "notify": notify },
	    onSuccess: function(transport)
	    {
		    var response = transport.responseText || "no response text"; 
			$('commentsDiv').innerHTML=response;
	    }
	});
}

function loadTour(product,step)
{
	if(step==null || isNaN(step))
	{
		step=1;
	}
	
	$('tourDiv').innerHTML="<table width='100%' height='500'><tr><td align='center' valign='middle'>"
		+"<img src='img/ajax-loader.gif'></td></tr></table>";
	centerElt('tourDiv',700,500);
	
	var url="http://calendarscripts.info/index.php?action=ajax_tours";
	
	new Ajax.Request(url,
   {
	    method:'post',
	    parameters: { "product": product, "step": step },
	    onSuccess: function(transport)
	    {
		    var response = transport.responseText || "no response text"; 
			$('tourDiv').innerHTML=response;
	    }
	});
}