// JavaScript Document

var countTripObj;

function getCountTrip()
{	
	//alert('hey dude, i m in getCountTrip()');
	
	if(window.ActiveXObject)//for identify explorer
	{
		countTripObj=new ActiveXObject('Microsoft.XMLHTTP');
	}
	else
	{			
		if (window.XMLHttpRequest) 
		{ 			
			countTripObj = new XMLHttpRequest();						
		} 
	}
	if(countTripObj)
	{
		try
		{
			countTripObj.onreadystatechange=resCount;
		}
		catch(ex)
		{
			alert('Exception in state change')
		}
		//alert('1');
		url = "/servlet/CountPrivateTrip?ranNum="+Math.random();
		//alert(url);
		countTripObj.open('GET',url);
		//alert('1');	
		try
		{
			//alert('2');							
			if(window.ActiveXObject)
			{		
				countTripObj.send();
			}
			else
			{							
				//alert('3');	
				countTripObj.send("");
				//alert('4');
			}				
		}
		catch(ajaxEx)
		{
			alert(ajaxEx);
		}
	}
}

function resCount()
{
	if(countTripObj.readyState==4)
	{
		//alert(countTripObj.status);
		if(countTripObj.status==200)
		{				
			//alert(countTripObj.responseText);
			if(countTripObj.responseText=='true')
			{
				//alert('from server:-> '+countTripObj.responseText);
				tripCountCheck = countTripObj.responseText;
				if(tripCountCheck=='false')
				{
					alert('You are allowed to create only Five Trips.\' To create new, delete any unwanted Trip, then create another! ');
					return 0;
				}
				else
				{
					setEmptyCT();
					//document.createTrip.reset;
					document.getElementById('pathFreeze').style.display='none';
					document.getElementById('tripDetail').style.display='none';
					document.getElementById('goldenList').style.display='none';
					document.getElementById('helpDiv').style.display='none';
					divTripInBox = document.getElementById('tripInBox');
					divTripInBox.style.display = 'none';
					divCreateTrip = document.getElementById('createTrip');
					divCreateTrip.style.display = 'block';									
				}
				//alert('tripCountCheck:-> '+tripCountCheck);
			}
			else
			{
				alert('You are allowed to create only Five Trips.\' To create new, delete any unwanted Trip, then create another! ');
			}
		}
	}			
}