//------------------------------------------------------------
// Create a URL which is called from a mapquest Map to get Directions
//-----------------------------------------------------------
    function genURL(action,newMap)
    {
		formname=document.forms[0].id;
		var sa = document.getElementById(formname).street_address.value;
		var cy = document.getElementById(formname).city.value;
		var st = document.getElementById(formname).state.value;
		var pc = document.getElementById(formname).postal_code.value;
		var ct = document.getElementById(formname).country.value;
		var lat =document.getElementById(formname).latitude.value;
		var lng =document.getElementById(formname).longitude.value;
		var uid =document.getElementById(formname).userid.value;
		var wid =document.getElementById(formname).website_id.value;
		
		if (newMap=='true'){
		// To be added only if the user is a new user.
			var street=document.getElementById(formname).toStreet.value;
			var city= document.getElementById(formname).toCity.value;
			var state=document.getElementById(formname).toState.value;
			var zip=document.getElementById(formname).toZip.value;
			var country=document.getElementById(formname).toCountry.value;
			if(zip=="")
			{
				if(city=="" || state=="")
				{
					alert("Please select an address by clicking the radio button");
					return false;
				}
			}
		}
		if(pc=="")
		{
			if(cy=="" || st=="")
			{
				alert("Type a City and State, or a Postal/ZIP Code, and then click Continue.");
				return false;
			}
		}
		
		
		
		//pallavi change to send the toAress also to get driving directions
		var url = action+"&street_address="+sa+"&city="+cy+"&state="+st+"&postal_code="+pc+"&country="+ct
					+"&latitude="+lat+"&longitude="+lng +"&userid="+uid+"&website_id="+wid;
		if (newMap=='true'){
		//WE have toaddress only for new user,old users used Lat and lon.			
			url=url +"&toStreet="+street+"&toCity="+city+"&toState="+state+"&toZipCode="+zip+"&toCountry="+country
		}				
		popUp(url);

   } 
//----------------------------------------------------
// Create a new pop up window for a given URL and type
//----------------------------------------------------
function popUp(URL, type) 
{
    switch(type)
    {
	 case "guestbook":
	    width = 675;
	    height = 500;
	    break;	    
	 case "forum":
	    width = 675;
	    height = 500;
	    break;	    
         default:
            width = 550;
            height = 580;
   }

   var token = URL.indexOf('?') > -1 ? '&amp;' : '?';
   uniqueId = genUniqueId();
   URL=URL+genUniqueParam(token);

   var leftPosition  = (screen.width - width - 20) / 2;
   var topPosition = (screen.height - height) / 4;

   //open centered
   eval("win = window.open(URL, '"+type+"', 'toolbar=0,scrollbars=1,location=0,status=1,resizable=1,menubar=0,width="+width+",height="+height+",left="+leftPosition+",top="+topPosition+"');");

   if (parseInt(navigator.appVersion) >= 4) 
   { 
      win.window.focus(); 
   }
} 
// ----------------------
// Generate Unique Id
// ----------------------
function genUniqueId()
{
   day = new Date();
   return day.getTime();
} 
// -------------------------------------------------
// Generate Unique parameter to be appended to the URL
// This will allow us to realod the HTML from the server
// -------------------------------------------------
function genUniqueParam(parameter)
{
   return parameter+'unique_id='+genUniqueId();
} 