function openAddActivityPopup(url) {
	var vWinAct = window.open(url, 'email' ,'scrollbars=0,resizable=0,status=1,width=431px,height=422px,left=50,top=50');
	vWinAct.focus();
}

function openEditActivityPopup(url) {
	var vWinAct = window.open(url, 'email' ,'scrollbars=0,resizable=0,status=1,width=431px,height=332px,left=50,top=50');
	vWinAct.focus();
}

function addEditTripValidation()
{
	var tripName = document.getElementById("TripName");
	var tripNameValue = tripName.value;
	
	if (tripNameValue == '' || tripNameValue == null || tripNameValue == undefined){
		alert("Please enter a valid trip name.");
		return false;
	}
	
	return true;
}

function redirectFromPopup(url) {
	opener.location.href = url;
	window.close();
}

function addToFavorite() {
	if(browser == 'Safari')
		alert ('Please press clt+D for BookMarking this page');
	else if(document.all)
		window.external.AddFavorite(window.location.href, window.document.title);
	else if(window.sidebar)
		window.sidebar.addPanel(window.document.title,window.location.href,'');
}

function addLinkToFavorite() {
	var mailLink   =  document.getElementById("linkemail").value;
	var mailTitle  =  document.getElementById("emailtitle").value;
	if(browser == 'Safari'){
		alert ('Please press clt+D for BookMarking this page');
	}else if(document.all){
	 	window.external.AddFavorite(mailLink, mailTitle);
	}else if(window.sidebar){	
	 	window.sidebar.addPanel(mailTitle,mailLink,'');
	}
}

function bookmarkDel() {
	window.open('http://del.icio.us/post?v=2&url='+encodeURIComponent(location.href)+'&notes=&tags=&title='+encodeURIComponent(document.title));
}

function bookmarkDigg() {
	// Format - http://digg.com/submit?url=example.com&title=TITLE&bodytext=DESCRIPTION&media=MEDIA&topic=TOPIC
	// For more details, see - http://digg.com/tools/integrate#1
	//window.open('http://digg.com/submit?url='+encodeURIComponent(location.href)+'&title='+encodeURIComponent(document.title) + '&bodytext=&media=&topic=');
	window.open('http://digg.com/submit?url='+encodeURIComponent(location.href)+'&title='+encodeURIComponent(document.title) + '&bodytext=&media=&topic=');
}

function openEmailWin(url) {
	var vWinEml = window.open(url, 'email' ,'scrollbars=yes,resizable=no,width=431px,height=322px,left=50,top=50');
	vWinEml.focus();
}

function emailValidation()
{
	// Validate Mail From
	var mailfrom = document.getElementById("SiteSearch0");
	var mailfromValue = mailfrom.value;
	
	if (mailfromValue == '' || mailfromValue == null || mailfromValue == undefined){
		alert("Please enter a valid email address in the From field.");
		mailfrom.focus();
		return false;
	}
	else if (!isValidEmail(mailfromValue)) {
		alert("The value entered in the From field is not a valid email address");
		mailfrom.focus();
		return false;
	}
	
	// Validate Mail To
	var mailto = document.getElementById("SiteSearch1");
	var mailtoValue = mailto.value;
	
	if (mailtoValue == '' || mailtoValue == null || mailtoValue == undefined){
		alert("Please enter a valid email address in the To field.");
		mailto.focus();
		return false;
	}
	else if (!isValidEmail(mailtoValue)) {
		alert("The value entered in the To field is not a valid email address");
		mailto.focus();
		return false;
	}
	
	// Validate CC
	var mailcc = document.getElementById("SiteSearch2");
	var mailccValue = mailcc.value;
	
	if (mailccValue == '' || mailccValue == null || mailccValue == undefined){
		// Optional Field - Continue
	}
	else if (!isValidEmail(mailccValue)) {
		alert("The value entered in the CC field is not a valid email address");
		mailcc.focus();
		return false;
	}
	
	// Send Email
	document.getElementById("BtnHolder").style.display ="none" ;
	document.getElementById("submitBtnHolder").innerHTML = "Sending...";
	document.getElementById("emailForm").submit();
}

function emailHideValidation()
{
	// Validate Mail From
	var mailfrom = document.getElementById("SiteSearch0");
	var mailfromValue = mailfrom.value;
	
	if (mailfromValue == '' || mailfromValue == null || mailfromValue == undefined){
		alert("Please enter a valid email address in the From field.");
		mailfrom.focus();
		return false;
	}
	else if (!isValidEmail(mailfromValue)) {
		alert("The value entered in the From field is not a valid email address");
		mailfrom.focus();
		return false;
	}
	
	// Validate CC
	var mailcc = document.getElementById("SiteSearch2");
	var mailccValue = mailcc.value;
	
	if (mailccValue == '' || mailccValue == null || mailccValue == undefined){
		// Optional Field - Continue
	}
	else if (!isValidEmail(mailccValue)) {
		alert("The value entered in the CC field is not a valid email address");
		mailcc.focus();
		return false;
	}
	
	// Send Email
	document.getElementById("BtnHolder").style.display ="none" ;
	document.getElementById("submitBtnHolder").innerHTML = "Sending...";
	document.getElementById("emailForm").submit();
}

function emailTripValidation()
{
	// Validate Mail To
	var mailto = document.getElementById("SiteSearch1");
	var mailtoValue = mailto.value;
	
	if (mailtoValue == '' || mailtoValue == null || mailtoValue == undefined){
		alert("Please enter a valid email address in the To field.");
		mailto.focus();
		return false;
	}
	else if (!isValidEmail(mailtoValue)) {
		alert("The value entered in the To field is not a valid email address");
		mailto.focus();
		return false;
	}
	
	// Validate CC
	var mailcc = document.getElementById("SiteSearch2");
	var mailccValue = mailcc.value;
	
	if (mailccValue == '' || mailccValue == null || mailccValue == undefined){
		// Optional Field - Continue
	}
	else if (!isValidEmail(mailccValue)) {
		alert("The value entered in the CC field is not a valid email address");
		mailcc.focus();
		return false;
	}
	
	// Send Email
	document.getElementById("BtnHolder").style.display ="none" ;
	document.getElementById("submitBtnHolder").innerHTML = "Sending...";
	document.getElementById("emailForm").submit();
}

function isValidEmail(str) {
   return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
}

function getWindowCenter() {
} 

function removetext(varid)
{
	if (document.getElementById(varid).value == document.getElementById(varid).defaultValue)
    	document.getElementById(varid).select();
}

function restoretext(boxid)
{ 
    if(document.getElementById(boxid).value=="")
       document.getElementById(boxid).value="Search Chicago";        

}

function isEnterPressed(e) {
		var code;
		if (e.keyCode) code = e.keyCode;
		else if (e.which) code = e.which;
		if (code == 13){
			validateKeyWord();
		}
} 

function doDestinations()
{
		var e;
		var strOriginCityCode = document.getElementById('ctlAvailCriteria_cboOrigin').value;
		if ( strOriginCityCode == '' )
		{
			return;
		}
		ClearDestinationList();
		if (strOriginCityCode == "all") 
		{
			for (j=0; j < area_array.length; j++) 
			{
			  		CreateOptionInDestinationList(neighborhood_handle_array[j],neighborhood_array[j],false);
				  
			} 
		} else 
		{
			for (j=0; j < area_array.length; j++) 
			{
			  	if (strOriginCityCode == area_array[j])
				{
						CreateOptionInDestinationList(neighborhood_handle_array[j],neighborhood_array[j],false);
				}  
			} 
		}
}


function ClearDestinationList()
{
	//alert("ClearDestinationList Begin ");
	var e;
	try
	{
		var nlength = document.getElementById('ctlAvailCriteria_cboDest').options.length;
		//alert("ClearDestinationList nlength = " + nlength);

		while (document.getElementById('ctlAvailCriteria_cboDest').options.length > 0)
		{
			var deleteIndex=document.getElementById('ctlAvailCriteria_cboDest').options.length-1;
			document.getElementById('ctlAvailCriteria_cboDest').options[deleteIndex]=null;
		}
		return true;
	}
	catch(e)
	{
		alert("Error in function ClearDestinationList. Error = " + e.description );
		return false;
	}
}

function CreateOptionInDestinationList(strVal,strName,blnIsSelected)
{
	//alert("CreateOptionInDestinationList return value = " + sResult);

			
		var myOption=new Option();
		var insertIndex;
		myOption.text=strName;
		myOption.value=strVal;
	//	alert("CreateOptionInDestinationList before IF.");
		if (document.getElementById('ctlAvailCriteria_cboDest').selectedIndex > 0)
			insertIndex=document.getElementById('ctlAvailCriteria_cboDest').selectedIndex;
		else
			insertIndex=document.getElementById('ctlAvailCriteria_cboDest').options.length;

	//	alert("CreateOptionInDestinationList after IF.");
		document.getElementById('ctlAvailCriteria_cboDest').options[insertIndex]=myOption;	


}

function populateAreaDropDown()
{
	//alert("CreateOptionInDestinationList return value = " + sResult);

			
		var myOption=new Option();
		var insertIndex;
		myOption.text=strName;
		myOption.value=strVal;
	//	alert("CreateOptionInDestinationList before IF.");
		if (document.getElementById('ctlAvailCriteria_cboDest').selectedIndex > 0)
			insertIndex=document.getElementById('ctlAvailCriteria_cboDest').selectedIndex;
		else
			insertIndex=document.getElementById('ctlAvailCriteria_cboDest').options.length;

	//	alert("CreateOptionInDestinationList after IF.");
		document.getElementById('ctlAvailCriteria_cboDest').options[insertIndex]=myOption;	


}

function check_selected_neighborhood() {
	var neighborhoodhandle = document.getElementById("ctlAvailCriteria_cboDest").value;
	if (neighborhoodhandle == "all") {
		alert ("Please select a neighborhood from the list.");
		return false;
	} else if( neighborhoodhandle==null || neighborhoodhandle=="")  {
		alert ("Please select a neighborhood from the list.");
		return false;
	} else {
		submitneighborhood(neighborhoodhandle);
	}
}

function submitneighborhood(neighborhoodhandle) {
	var formAction = document.getElementById("neighborhoodsearch");
	formAction.action=neighborhoodhandle+".html";
	formAction.submit();
}
 
function filterInputMaxlength(maxlength)
{
	if(eval(event))
	{
		if (event.srcElement.value.length == maxlength) 
		{
			event.returnValue=false;
			return false;
		}
		else if(event.srcElement.value.length > maxlength)
		{
			event.srcElement.value = event.srcElement.value.substring(0, maxlength);
		}
		// need to take custom action if the event was onPaste because data
		// coming from the clipboard must be modified.
		else if(event.type=='paste')
		{
			// no return value - manually set the srcElement value
			event.returnValue = false;
			// check for how many remaining characters and substring the text in the clipboard
			// to fill available space.  Then set it on the source element.vv
			var remainingLength = maxlength - event.srcElement.value.length;
			event.srcElement.value =  event.srcElement.value + window.clipboardData.getData('text').substring(0,remainingLength);
		}
		return true;
	}
	return false;
}