var catName = '';
var startX, socialSliderVal, distanceSliderVal;
var currentCity = "";
var currentLL = "";
var first=true;
//var ckSocial = getCookie("BB_SS");
//var ckDist = getCookie("BB_DS");
//var defaultDistanceSetting = 1;
//var hiddenIFrameHeight = 0;

function getWeekDayNameFromLanguage(lan)//根据不同语言这里需要添加一周每一天的表示。<国际化>
{
	var returnArray;
	if(lan=="English")	
	{
		returnArray = new Array("Sun","Mon","Tue","Wed","Thur","Fri","Sat");
	}
	else if (lan=="Chinese_CN")
	{
		returnArray = new Array("日","一","二","三","四","五","六");
	}
	else if(lan=="Chinese_TW")
	{
		returnArray = new Array("日","一","二","三","四","五","六");
	}
	else if(lan=="German")
	{
		returnArray = new Array("So","Mo","Di","Mi","Do","Fr","Sa");
	}
	else if(lan=="French")
	{
		returnArray = new Array("Dim","Lun","Mar","Mer","Jeu","Ven","Sam");
	}
	else if(lan=="Spanish")
	{
		returnArray = new Array("Dom","Lun","Mar","Mie","Jue","Vie","Sáb");
	}
	else
	{
		returnArray = new Array("Sun","Mon","Tue","Wed","Thur","Fri","Sat");
	}
	return returnArray;
}

function getMonthNameFromLanguage(lan)//根据不同语言这里需要添加一年中每一月的表示。次函数返回一个数组.<国际化>
{
	var returnArray;
	if(lan=="English")	
	{
		returnArray = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
	}
	else if (lan=="Chinese_CN")
	{
		returnArray = new Array("1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月");
	}
	else if(lan=="Chinese_TW")
	{
		returnArray = new Array("一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月");
	}
	else if(lan=="German")
	{
		returnArray = new Array("Jan", "Feb", "März", "April", "Mai", "Juni", "Juli", "Aug", "Sept", "Okt", "Nov", "Dez");
	}
	else if(lan=="French")
	{
		returnArray = new Array("Janvier", "Février", "Mars", "Avril", "Mai", "Juin", "Juillet", "Août", "Septembre", "Octobre", "Novembre", "Décembre");
	}
	else if(lan=="Spanish")
	{
		returnArray = new Array("Ene", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Ago", "Sep", "Oct", "Nov", "Dic");
	}
	else
	{
		returnArray = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
	}
	return returnArray;
}

//<国际化>
//用途：得到年月的表示,例如（2007年5月）
//此函数需要自己根据语言写出年和月表示的算法。
//参数      monthName：根据语言得到的月份字符串。  字符串的具体内容请看函数getMonthNameFromLanguage()中的定义。
//         year：年份，例如(2007)等.
//         lan:语言类新.
function formatYearAndMonthByLanguage(monthName,year,lan)
{
	var returnString;
	if(lan=="English")	
	{
		returnString = monthName+" "+year;
	}
	else if (lan=="Chinese_CN")
	{
		returnString = year+"年 "+monthName;
	}
	else if(lan=="Chinese_TW")
	{
		returnString = year+"年 "+monthName;
	}
	else
	{
		returnString = monthName+" "+year;
	}
	return returnString;
}

//<国际化>
//用途：得到年月日的表示,例如（2007年5月6日,或:sunday, July 8 2007）
//此函数需要自己根据语言写出年,月和日表示的算法。
//参数      monthId：根据语言得到的月份的id为int类型,需要从getMonthNameFromLanguage(id)得到字符串。
//         year：年份，例如(2007)等.
//			day:天数.
//          weekday:表示星期几的字符串.
//         lan:语言类新.
function formatDayStringByLanguage(monthId,year,day,weekday,lan)
{
	//calendar_MonthNames[dMonth]

	var dtObj=new Date(year,monthId,day);


	var returnString;
	if(lan=="English")	
	{
		returnString = weekday+', '+calendar_MonthNames[monthId] + ' ' + day+', '+year
	}
	else if (lan=="Chinese_CN")
	{
		returnString = dtObj.toLocaleDateString()
	}
	else if(lan=="Chinese_TW")
	{
		returnString = dtObj.toLocaleDateString()
	}
	else
	{
		returnString = weekday+', '+calendar_MonthNames[monthId] + ' ' + day+', '+year
	}
	return returnString;
}

////--- This part needs to be snipped out into a resource folder
function usaDateFormat(strDate)
{
		var stime=strDate.match(/[012]{0,1}[\d]{1}\:[\d]{1,2}\:[\d]{1,2}/);
		
		var sdate=strDate.match(/[\d]{1,4}\-[\d]{1,2}\-[\d]{1,2}/);
		var tdate=sdate[0];
		var ttime=stime[0];
		var dArr=new Array();
		var tArr=new Array();
		var returnvalue;
		if (tdate=="")
		{
			return "Unknow date!"	
		}
		else
		{
			dArr=tdate.split("-");
			var strDay;
			var strDate;
			var strMonth;
			var strYear;
			var dateObj = new Date(dArr[0],dArr[1]*1-1,dArr[2]);
		}
		return dateObj;
}
function getlastb()
{
	
	try
	{
		var tmpstr=pointArray[0].Date;
	}
	catch(e)
	{
		return "";	
	}
	var newmydate=pointArray[pointArray.length-1].Date;
    var testdate = usaDateFormat(newmydate);
	
		  if(testdate.getDate()!=null)
		  {
			  return testdate.getDate();
		  }
		  else
		  {
			  return 1;
		  }
	  
}
function getnextdate(_year,_month,_date)
{
	
	try
	{
		var tmpstr=pointArray[0].Date;
	}
	catch(e)
	{
		return "";	
	}
	 var i=0;
	 //var j=0;
	 //var alldate= new Array();
  while(i<pointArray.length)
  {
    var newmydate=pointArray[i].Date;
    var testdate = usaDateFormat(newmydate);
   //alert(testdate.getFullYear()+"\n"+testdate.getMonth()+"\n"+testdate.getDate());
   //alert(_year+"\n"+_month+"\n"+_date);
   if(testdate.getFullYear()==_year)
   {
	   if(testdate.getMonth()==_month)
	   {
		 // alldate[j]=testdate.getDate();
		 if(testdate.getDate()>_date)
		 {
			 return testdate.getDate();
		 }
		  //alert(alldate[j]);
		 // j++;
		  
	   }
   }
  
   i++;
 }
 return false;
}

function getperydate(_year,_month,_date)
{
	
	try
	{
		var tmpstr=pointArray[0].Date;
	}
	catch(e)
	{
		return "";	
	}
	 var i=pointArray.length-1;
	 var tmpPointDay;
	 //var j=0;
	 //var alldate= new Array();
  while(i>-1)
  {
    var newmydate=pointArray[i].Date;
    var testdate = usaDateFormat(newmydate);
   //alert(testdate.getFullYear()+"\n"+testdate.getMonth()+"\n"+testdate.getDate());
   //alert(_year+"\n"+_month+"\n"+_date);
   if(testdate.getFullYear()==_year)
   {
	   if(testdate.getMonth()==_month)
	   {
		 // alldate[j]=testdate.getDate();
		 
		 if(testdate.getDate()<_date)
		 {
			 return testdate.getDate();
		 }
		  //alert(alldate[j]);
		 // j++;
		  
	   }
   }
   
   i--;
 }
 return false;
}
//获取最后一次备份的时间
function getlastback(_year,_month,_date)
{
	try
	{
		var tmpstr=pointArray[0].Date;
	}
	catch(e)
	{
		return "";	
	}
	var newmydate=pointArray[pointArray.length-1].Date;
    var testdate = usaDateFormat(newmydate);
	if(testdate.getFullYear()==_year)
   {
	   if(testdate.getMonth()+1==_month)
	   {
		   if(testdate.getDate()==_date)
		   {
			  return _date;
		   }
	   }
   }
   else
   {
	   return false;
   }
  
}


//var sliderDialogTitle = "Set Your Search View";
//检查有没有备份点
function getdate(_year,_month,_date)
{
	 
	try
	{
		var tmpstr=pointArray[0].Date;
	}
	catch(e)
	{
		return "";	
	}
  var i=pointArray.length-1;
  while(i>-1)
  {
    	var newmydate=pointArray[i].Date;
   		var testdate = usaDateFormat(newmydate);
   		if(testdate.getFullYear()==_year)
   		{
	   		if(testdate.getMonth()+1==_month)
	   		{
		   		//alert(testdate.getDate()+"^^^"+_date);
		   		if(testdate.getDate()==_date)
		   		{
			   		return _date;
		   		}
	   		}
   		}
   		else
   		{
	   		//return false;
   		}
   		i--;

 	}
return false;
  
}
function getmldate(_year,_month)
{
	 
	try
	{
		var tmpstr=pointArray[0].Date;
	}
	catch(e)
	{
		return "";	
	}
  var i=pointArray.length-1;
  while(i>-1)
  {
    	var newmydate=pointArray[i].Date;
   		var testdate = usaDateFormat(newmydate);
   		if(testdate.getFullYear()==_year)
   		{
	   		if(testdate.getMonth()+1==_month)
	   		{
		   		//alert(testdate.getDate()+"^^^"+_date);
		   		
			   		return testdate.getDate();
		   		
	   		}
   		}
   		else
   		{
	   		//return false;
   		}
   		i--;

 	}
return false;
  
}
//alert(getmldate(2006,5));
var lastobj=null;
//改变选中的颜色
function test(obj)
{

  if(lastobj==null)
  {
    obj.style.color="#ffffff";
	obj.style.backgroundImage="url(pic/calendar_r5_c6.jpg)";
  }
  else
  {
	  
  //alert(lastobj.innerHTML);
    lastobj.style.background="#D9EAF6";
    lastobj.style.color="#3E75BC";
	obj.style.color="#ffffff";
	obj.style.backgroundImage="url(pic/calendar_r5_c6.jpg)";
  }
  lastobj=obj;
	
  
  	
}
//当鼠标经过的颜色
function mousemove(lastobj,obj)
{
  obj.style.background="#123456";
}
//当鼠标移开恢复颜色
function mouseout(lastobj,obj)
{
  if(lastobj==null)
  {
  obj.style.background="#466AB3";
  
  }
  else
  {
 
    lastobj.style.background="#654321";
    obj.style.background="#466AB3";
  }
  lastobj=obj;
}
var calendar_DayNames = new Array("Sun","Mon","Tue","Wed","Thur","Fri","Sat");
var calendar_MonthNames = getMonthNameFromLanguage(langType)
//var socArray = new Array("Messenger Buddies Only", "E-mail Groups Only", "Buddies and E-mail Groups", "Everyone");
//var dstArray = new Array(25,50,75,100,150,250,500,-1);
//var dstTextArray = new Array(" +25 miles"," +50 miles"," +75 miles"," +100 miles"," +150 miles"," +250 miles"," +500 miles","United States"); 

function showCalendar(targetID, targetURL, dMonth, dYear, dDay,action)
{

	var cd=null;
	document.getElementById("pid").value=="";//Clear the select
    if(dMonth < 0)
    {       
        dMonth = 11;
        dYear--;
    }
    if(dMonth > 11)
    {
        dMonth = 0;
        dYear++;
    }

    var dNow = new Date();
    if(dDay == 90 && dMonth == dNow.getMonth() && dYear == dNow.getYear()) dDay = dNow.getDate();
    var dCurFD = new Date(dYear, dMonth, 1);
    var dGivenDate = new Date(dYear, dMonth, dDay);  
    var dCurrentMonthFirstSunday = dCurFD.getDay();
    var dCurrentViewDate = new Date(dCurFD);
    var iDays = 0;
    var weekMilliseconds = 1000*60*60*24*7;
    if(dCurrentMonthFirstSunday > 0) iDays = -dCurrentMonthFirstSunday;
    
    var fTrgt = targetURL;
    while (fTrgt.indexOf("'") >= 0) fTrgt = fTrgt.replace("'", "`");
    while (fTrgt.indexOf("`") >= 0) fTrgt = fTrgt.replace("`", "\\'");
    
    var oBuf = '<TABLE BORDER="0" WIDTH="100%" CELLSPACING="0" CELLPADDING="0" style="border:none;background:#ECF2F7;" id="maint">';       
    oBuf += '<TR><td>&nbsp;</td><TD CLASS="calendarhd" ><A onkeydown="bigkey();" id="bleft" HREF="#" onclick="javascript:showCalendar(\'' + targetID + "','" + fTrgt + "'," + (dMonth - 1) + ',' + dYear + ',90);SetBfocus(0);"><img src="pic/leftArrow.jpg" /></A></TD>';
    oBuf += '<TD COLSPAN="3" CLASS="calendarhd">' + formatYearAndMonthByLanguage(calendar_MonthNames[dMonth],dYear,langType)+ '</TD>';
    oBuf += '<TD CLASS="calendarhd" ><A  id="bright" onkeydown="bigkey();" HREF="#" onclick="javascript:showCalendar(\'' + targetID + "','" + fTrgt + "'," + (dMonth + 1) + ',' + dYear + ',90);SetBfocus(1);"><img src="pic/rightArrow.jpg" /></A></TD><td></td></TR>';
   
   oBuf += '<TR >';
    
    for(var e=0; e < 7; e++) 
	{
		if (e==0)
		{
			oBuf += '<TD CLASS="calendarDays" style="border-left:1px solid #D7DBE4;">' + calendar_DayNames[e] + '</TD>';  
		}
		else
		{
			oBuf += '<TD CLASS="calendarDays">' + calendar_DayNames[e] + '</TD>';  
		}
	}
    oBuf += '</TR>';
    var nextMonthFirstDay = new Date(dYear, dMonth+1, 1);
    var IsNextMonthFirstDaySunday = nextMonthFirstDay.getDay()==0;
        
    for(var iRows=0; iRows < 6; iRows++)
    {
        dCurrentMonthDate = new Date(dCurFD.getFullYear(), dCurFD.getMonth(), dCurFD.getDate() + iDays);
        //if(dCurrentMonthDate.getMonth() <= dCurFD.getMonth()) // old style
        if(1==1)         
        {
        // skipping extra row at the end of the table if needed (new month) 
        if(iRows==5 && dCurrentMonthDate.getMonth() > dCurFD.getMonth()) continue;        
        if(iRows==5 && IsNextMonthFirstDaySunday) continue;
                
        oBuf += '<TR style="border-left:1px solid #000000;">';
        for(var iCols=0; iCols < 7; iCols++)
        {
			
            dCurrentViewDate = new Date(dCurFD.getFullYear(), dCurFD.getMonth(), dCurFD.getDate() + iDays);
			myyear=dCurrentViewDate.getFullYear();
			mymonth=dCurrentViewDate.getMonth()+1;
			mydate=dCurrentViewDate.getDate();
			//alert(getmldate(dYear,dMonth));
			//alert(dCurrentViewDate.getDate());
			var newtemp;
			if(action=="" || action==null)
			{
				var cud = new Date();
			    newtemp=cud.getDate();//getmldate(dYear,dMonth+1);
			    //newtemp=getmldate(dYear,dMonth+1);
			   //alert(dMonth);
			   //alert(newtemp);
			}
			else
			{
				newtemp=dDay;
			}
			var tdid=mydate;
			if (iCols==0)
			{
				oBuf +="<TD  style='border-left:1px solid #D7DBE4; font-size:13px;'";
			}
			else
			{
				oBuf +="<TD  style='font-size:13px;'";
			}
			
            if((dCurrentViewDate.getDate()==newtemp) && (dDay != 90) && (dCurrentViewDate.getMonth() == dMonth) &&(dCurrentViewDate.getFullYear() == dYear))
            {
				
                //oBuf += '<TD CLASS="selectedDate">'+dCurrentViewDate.getDate();
				 oBuf += ' align="left" id=\"'+tdid+'\" valign="top"  CLASS="selectedDate" onclick="test(this);showCalendar1(\'' + targetID + "1','" + fTrgt + "'," + (mymonth-1) + ',' + myyear + ','+mydate+');"><span style="font-weight:bold;font-size=14px;">' + dCurrentViewDate.getDate() + '</span>';
				 cd=tdid;
				 //alert(cd);
				
			}
		    else
            {
                if(dCurrentViewDate.getMonth() != dMonth || iDays < 0) 
                {
                    oBuf += ' align="left" valign="top" CLASS="negDate">&nbsp;';//+dCurrentViewDate.getDate();
					//alert("a");
					//alert(mymonth);
                }
                else if(dCurrentViewDate.getDate()==getdate(myyear,mymonth,mydate))
				//else if(dCurrentViewDate.getDate()==getmldate(dYear,dMonth))
                {
					
					//alert(getmldate(dYear,dMonth));
                    //alert(getdate("1"));
                     //myargs = dCurrentViewDate.getFullYear()+'年'+(dCurrentViewDate.getMonth()+1)+'月' +dCurrentViewDate.getDate();
                    oBuf += ' align="left" id=\"'+tdid+'\" valign="top" CLASS="disableDate" onclick="test(this);showCalendar1(\'' + targetID + "1','" + fTrgt + "'," + (mymonth-1) + ',' + myyear + ','+mydate+');"><span style="font-weight:bold;font-size=14px;">' + dCurrentViewDate.getDate() + '</span>';
					 //cd=tdid;
                }
                else
                {
					//alert("c");
                    oBuf += ' align="left" valign="top" CLASS="posDate">'+dCurrentViewDate.getDate();
                }
            }
            
            var args;
            
            if (targetURL.substr(0,11) == 'javascript:')
            {
              args = dCurrentViewDate.valueOf() + ")";
            }
            else
            {
              var sep = targetURL.indexOf('?') < 0 ? '?' : '&';
              args = sep + 'startDate=' + (dCurrentViewDate.getMonth()+1)+ '%2F' + dCurrentViewDate.getDate() + '%2F' + dCurrentViewDate.getFullYear();
              myargs = dCurrentViewDate.getFullYear()+'Year'+(dCurrentViewDate.getMonth()+1)+'Month' +dCurrentViewDate.getDate();
            }
            oBuf +=   '</TD>';
           // oBuf="</TD>";
            iDays++;
        }
        oBuf += '</TR>';
        }
    }
    oBuf += '</TABLE>';
	//alert(oBuf);
    document.getElementById(targetID).innerHTML = oBuf;
	if(action=="" || action==null)
	{
		
	showCalendar1(targetID+"1", targetURL, dMonth, dYear,dDay);
		
	}
	
	lastobj=document.getElementById(cd);
	
   // alert(action);
	//alert(oBuf);
	//alert(cd);
	//alert(getperydate(dYear,dMonth,4));
	//alert(getnextdate(dYear,dMonth,11));
	//alert(tdid);
	
}
function bigkey()
{
	var key = event.keyCode;
	if(key==37)
	{
		document.getElementById("bleft").click();
		document.getElementById("bleft").focus();
	}
	if(key==39)
	{
		document.getElementById("bright").click();
		document.getElementById("bright").focus();
	}
}
function SetBfocus(id)
{
	if(id==0)
	{
		document.getElementById("bleft").focus();
	}
	if(id==1)
	{
		document.getElementById("bright").focus();

	}
}
