// JavaScript Document

function ClassGlobalNormal()
{
	this.checkDel = function (wId)
	{
		var flag = false;
		
		if ( wId == 'delNormalAsk' )
		{
			if (confirm("您真的要删除吗?"))
				flag = true;
		}
		
		return flag;
	}
	
}	// ClassGlobalNormal
var objClassGlobalNormal = new ClassGlobalNormal();


// change an obj's class
function changeCss(aObj, aClassname){
	aObj.removeClass();
	aObj.addClass(aClassname);
}

// valid the email format
function isEmail(str){
	var res = /^[0-9a-zA-Z_\-\.]+@[0-9a-zA-Z_\-]+(\.[0-9a-zA-Z_\-]+)*$/;
	var re = new RegExp(res);
	return !(str.match(re) == null);
} 

// get string length
function len(s) {
	var l = 0;
	var a = s.split("");
	for (var i=0;i<a.length;i++) {
		if (a[i].charCodeAt(0)<299) {
			l++;
		} else {
			l+=2;
		}
	}
	return l;
}

function checkExplorer()
{
	if(window.XMLHttpRequest)//判断浏览器是否属于Mozilla,Sofari
    {
        return "ff";
    }
    else if(window.ActiveXObject)//判断浏览器是否属于IE
    {
        var browser=navigator.appName
        var b_version=navigator.appVersion
        var version=b_version.split(";");
        var trim_Version=version[1].replace(/[ ]/g,"");
        if(browser=="Microsoft Internet Explorer" && trim_Version=="MSIE7.0")
        {
			return "ie7";
        }
        else if(browser=="Microsoft Internet Explorer" && trim_Version=="MSIE6.0")
        {
			return "ie6";
        }
    }
}

function fixOnePngCss(cssName)
{
	// not good nouse
	if ( checkExplorer() == "ie6" )
	{
		DD_belatedPNG.fix("."+cssName);
	}
}

function fixOnePng(eleObj)
{
	// not good nouse
	if ( checkExplorer() == "ie6" )
	{
	//DD_belatedPNG.fixPng($('pngTransparent2'));
	//DD_belatedPNG.fixPng(document.getElementById('pngTransparent2'));
		DD_belatedPNG.fixPng(jQuery("#sss")[0]);
	}
}



function correctPNG(eleObj) // correctly handle PNG transparency in Win IE 5.5 & 6. 
{ 
	// very good 2009-7-24
	
    //var arVersion = navigator.appVersion.split("MSIE") 
    //var version = parseFloat(arVersion[1]) 
    //if ((version >= 5.5) && (document.body.filters)) 
	if ( checkExplorer() == "ie6" )
    { 
       //for(var j=0; j<document.images.length; j++) 
       { 
	   
          var img = eleObj;//document.getElementById('sss');//document.images[j] 
          var imgName = img.src.toUpperCase() 
          if (imgName.substring(imgName.length-3, imgName.length) == "PNG") 
          { 
             var imgID = (img.id) ? "id='" + img.id + "' " : "" ;
             var imgClass = (img.className) ? "class='" + img.className + "' " : "" ;
             var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' " ;
             var imgStyle = "display:inline-block;" + img.style.cssText ;
             if (img.align == "left") imgStyle = "float:left;" + imgStyle ;
             if (img.align == "right") imgStyle = "float:right;" + imgStyle ;
             if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle ;
             var strNewHTML = "<span " + imgID + imgClass + imgTitle 
				 + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";" 
				 + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader" 
				 + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" ;
             img.outerHTML = strNewHTML ;
             //j = j-1 ;
          } 
       } 
    }     
}


function getScrollTop()
{
//var h = (window.innerHeight || (window.document.documentElement.clientHeight || window.document.body.clientHeight));
//var h = (window.innerWidth || (window.document.documentElement.clientWidth || window.document.body.clientWidth));

	return window.document.documentElement.scrollTop;

}
function getScrollLeft()
{
//var h = (window.innerHeight || (window.document.documentElement.clientHeight || window.document.body.clientHeight));
//var h = (window.innerWidth || (window.document.documentElement.clientWidth || window.document.body.clientWidth));

	return window.document.documentElement.scrollLeft;

}

function getClientHeight()
{

	return (window.innerHeight || (window.document.documentElement.clientHeight || window.document.body.clientHeight));

}
function getClientWidth()
{

	return (window.innerWidth || (window.document.documentElement.clientWidth || window.document.body.clientWidth));

}
function getClientCenterX()
{

	return getClientWidth() / 2;

}
function getClientCenterY()
{

	return getClientHeight() / 2;

}


function boxContainer(fatherEleName, eleId, insertPlace, eleWidth, eleHeight, eleBgcolor, elePadding, waitingTime)
{
	// 用于生成一个 div , 在 fatherEleName 里
	var h = "<div id=\""+eleId+"\"></div>";
	if ( insertPlace == 'first' )
	{
		jQuery(fatherEleName).prepend(h);
	}

	if ( eleWidth == '100%' )
	{
		jQuery(fatherEleName+" #"+eleId).css().width('100%');//eleWidth);
	}
	else
	{
		jQuery(fatherEleName+" #"+eleId).css().width(eleWidth);
	}
	jQuery(fatherEleName+" #"+eleId).css().height(eleHeight);
	jQuery(fatherEleName+" #"+eleId).css("background", eleBgcolor);
	jQuery(fatherEleName+" #"+eleId).css("padding", elePadding);
	

}


function boxDiv(fatherEleName, insertPlace, eleWidth, eleHeight, eleCss, eleAlign, inlineHtml, inlineAlign, autoHide, waitingTime)
{
	//boxDiv("body",'first', 300, 30, "boxRed", "clientCenter", 'test', 'left' , 'autoHide', 3000);

	var h = '<div class="'+eleCss+'"><div class="inside">'+inlineHtml+'</div>'+
	  		'<div class="tl"></div><div class="tr"></div><div class="bl"></div><div class="br"></div>'+
			'</div>';
	//alert(eleToInsert);
	if ( insertPlace == 'first' )
	{
		jQuery(fatherEleName).prepend(h);
	}
	if ( eleWidth == '100%' )
	{
		jQuery(fatherEleName+" ."+eleCss).css().width('100%');//eleWidth);
	}
	else
	{
		jQuery(fatherEleName+" ."+eleCss).css().width(eleWidth);
	}
		
	jQuery(fatherEleName+" ."+eleCss).css().height(eleHeight);
	jQuery(fatherEleName+" ."+eleCss+" .bl").css("top", eleHeight-2);
	jQuery(fatherEleName+" ."+eleCss+" .br").css("top", eleHeight-2);
	if ( eleWidth == '100%' )
	{
		jQuery(fatherEleName+" ."+eleCss+" .inside").width('100%');//eleWidth-20);
	}
	else
	{
		jQuery(fatherEleName+" ."+eleCss+" .inside").width(eleWidth-20);
	}
	jQuery(fatherEleName+" ."+eleCss+" .inside").height(eleHeight-5);
	
	if ( eleAlign == "clientCenter" )	// align current screen center
	{
		jQuery(fatherEleName+" ."+eleCss).css("top", getScrollTop() + getClientCenterY() - jQuery(fatherEleName+" ."+eleCss).css().height() / 2);
		jQuery(fatherEleName+" ."+eleCss).css("left", getScrollLeft() + getClientCenterX() - jQuery(fatherEleName+" ."+eleCss).css().width() / 2);
	}
	else if ( eleAlign == "clientTop" )	// align to current screen top
	{
		jQuery(fatherEleName+" ."+eleCss).css("top", getScrollTop() );
		jQuery(fatherEleName+" ."+eleCss).css("left", getScrollLeft() + getClientCenterX() - jQuery(fatherEleName+" ."+eleCss).css().width() / 2);
	}
	else
	{
	}
	if ( inlineAlign == "" )
	{
	}
	else
	{
		jQuery(fatherEleName+" ."+eleCss+" .inside").css("text-align", inlineAlign);
	}
	
	if ( autoHide == "autoHide" )
	{
		if ( waitingTime == '' ){ waitingTime = 3000; }
		window.setTimeout(function(){jQuery(fatherEleName+" ."+eleCss).hide();}, waitingTime);
		//alert(1);
	}
	//return h;
}




function strToPureStr_JSsssssssssssssssssssssssss(str)
{
	str = str.replace('"',"&quot;");
	str = str.replace("'","&#039;");
	str = str.replace(" ","&nbsp;");
	str = str.replace("\'","&#039;");
	str = str.replace("\"","&quot;");
	return str;
}
function strToPureStr_JS(str){
     var RexStr = /\<|\>|\"|\'|\&/g
     str = str.replace(RexStr,
         function(MatchStr){
             switch(MatchStr){
                 case "<":
                     return "&lt;";
                     break;
                 case ">":
                     return "&gt;";
                     break;
                 case "\"":
                     return "&quot;";
                     break;
                 case "'":
                     return "&#39;";
                     break;
                 case "&":
				 	 //return "&";
                     return "&amp;";
                     break;
                 default :
                     break;
             }
         }
     )
     return str;
} 

function inLineEditor(editorType, editorWidth, editorHeight, maxLength,  oriEleName, iniValue, buttons)
{
	// inLineEditor("input", 100, 25, "className", "show_user_nick_name", "")
	
	g_inLineEditor_ori_html = jQuery("#" + oriEleName).html();
	//alert (g_inLineEditor_ori_html);
	if ( iniValue == "" ){ 
		iniValue = strToPureStr_JS(g_inLineEditor_ori_html);
		//iniValue = g_inLineEditor_ori_html;
	
	}
	//alert(iniValue);
	g_inLineEditor_editing = true;
	if ( editorType == "input" )
	{
		var buttons_str = "";
		if ( buttons == "UpdateCancel" )
		{
			buttons_str = "&nbsp;<input type=\"button\" id=\"p_inLineEditor_update\" value=\"更新\" />"+
						  "&nbsp;<input type=\"button\" id=\"p_inLineEditor_cancel\" value=\"取消\" />&nbsp;";
		}
		alert(iniValue);
		jQuery("#" + oriEleName).html("<input name=\"p_inLineEditorInput\"  maxlength=\""+maxLength+"\" type=\"text\" id=\"p_inLineEditorInput\" value=\""+iniValue+"\" />" + buttons_str);
		jQuery("#" + oriEleName + " #p_inLineEditorInput").css().height(editorHeight);
		jQuery("#" + oriEleName + " #p_inLineEditorInput").css().width(editorWidth);
		
		if ( buttons == "UpdateCancel" )
		{
			jQuery("#p_inLineEditor_update").click(function(){
				inLineEditor_doUpadte(jQuery("#p_inLineEditorInput")[0].value);
				g_inLineEditor_editing = false;

				
				window.setTimeout(function(){jQuery("body .boxRed").hide();}, 1000);
				return false;
			});
			jQuery("#p_inLineEditor_cancel").click(function(){
				inLineEditor_doCancel();
				g_inLineEditor_editing = false;
				return false;
			});
		}
	}
	
}		 // end inLineEditor


function splitPages(currentPage, all_pages, click_fun_name, click_fun_param)
{
	// currentPage = objMe.page
	// all_pages = objMe.all_pages
	// click_fun_name = onclick function name 	->	listVoa
	// click_fun_param = onclick function param	->	1,'tag_name'		-> using ' instead of "   !!!!!!!!!!!!!!!!!
	// click_fun_param	=> objMe.tag_id+",'"+objMe.tag_name+"', "
	//nav_a
	a_str = '';
	i1 = 0;
	
	if ( currentPage < 10 )						// current page is < 10
	{
		if ( all_pages <= 10 )		// all_pages <= 10
		{
			for (i = 0; i<all_pages; i++)
			{
				i1 = i + 1;
				a_str = a_str + "<a id=\"nav_a_"+i1+"\" href=\"javascript:;\" onclick=\""+click_fun_name+"("+click_fun_param+i1+");\" class=\"slink\">"+i1+"</a>";
			}
		}
		else
		{
			// 1 get first 10
			for (i = 0; i<10; i++)
			{
				i1 = i + 1;
				a_str = a_str + "<a id=\"nav_a_"+i1+"\" href=\"javascript:;\" onclick=\""+click_fun_name+"("+click_fun_param+i1+");\" class=\"slink\">"+i1+"</a>";
			}
			// 2 
			if ( all_pages >= 13 )
			{
				a_str = a_str + "...";
			}
			// 3
			i1 = all_pages - 1;
			a_str = a_str + "<a id=\"nav_a_"+i1+"\" href=\"javascript:;\" onclick=\""+click_fun_name+"("+click_fun_param+i1+");\" class=\"slink\">"+i1+"</a>";
			a_str = a_str + "<a id=\"nav_a_"+i1+"\" href=\"javascript:;\" onclick=\""+click_fun_name+"("+click_fun_param+all_pages+");\" class=\"slink\">"+all_pages+"</a>";
		}
		
	}
	else if ( currentPage > all_pages-9 )				// current page is > all_pages -10
	{
		
		// 1
		i1 = 1;
		a_str = a_str + "<a id=\"nav_a_"+i1+"\" href=\"javascript:;\" onclick=\""+click_fun_name+"("+click_fun_param+i1+");\" class=\"slink\">"+i1+"</a>";
		i1 = i1 + 1;
		a_str = a_str + "<a id=\"nav_a_"+i1+"\" href=\"javascript:;\" onclick=\""+click_fun_name+"("+click_fun_param+i1+");\" class=\"slink\">"+i1+"</a>";
		
		// 2
		if ( all_pages >= 13 )
		{
			a_str = a_str + "...";
		}
		
		// 3
		for (i = 9; i>=0; i--)
		{
			i1 = all_pages - i;
			a_str = a_str + "<a id=\"nav_a_"+i1+"\" href=\"javascript:;\" onclick=\""+click_fun_name+"("+click_fun_param+i1+");\" class=\"slink\">"+i1+"</a>";
		}
	}
	else												// current page is in the middle
	{
		
		// 1
		i1 = 1;
		a_str = a_str + "<a id=\"nav_a_"+i1+"\" href=\"javascript:;\" onclick=\""+click_fun_name+"("+click_fun_param+i1+");\" class=\"slink\">"+i1+"</a>";
		i1 = i1 + 1;
		a_str = a_str + "<a id=\"nav_a_"+i1+"\" href=\"javascript:;\" onclick=\""+click_fun_name+"("+click_fun_param+i1+");\" class=\"slink\">"+i1+"</a>";
		
		// 2
		a_str = a_str + "...";
		
		// 3
		for (i = 0; i<7; i++)
		{
			i1 = currentPage - 3 + i;
			a_str = a_str + "<a id=\"nav_a_"+i1+"\" href=\"javascript:;\" onclick=\""+click_fun_name+"("+click_fun_param+i1+");\" class=\"slink\">"+i1+"</a>";
		}
		
		// 4
		a_str = a_str + "...";
		
		// 5
		i1 = all_pages - 1;
		a_str = a_str + "<a id=\"nav_a_"+i1+"\" href=\"javascript:;\" onclick=\""+click_fun_name+"("+click_fun_param+i1+");\" class=\"slink\">"+i1+"</a>";
		i1 = all_pages - 0;
		a_str = a_str + "<a id=\"nav_a_"+i1+"\" href=\"javascript:;\" onclick=\""+click_fun_name+"("+click_fun_param+i1+");\" class=\"slink\" >"+i1+"</a>";
		
		
		
		
	}	
	return a_str;
}	// end splitPages


function createMarker(latlng, number) {
	var marker = new GMarker(latlng);
		marker.value = number;
		GEvent.addListener(marker,"click", function() {
		var myHtml = ""+latlng.lng()+" "+latlng.lat();
		map.openInfoWindowHtml(latlng, myHtml);

	});
	return marker;
}

function showTopicType(topicId, i, topicType, rtMapZoom){
	

	var query = "";
	
	if (topicType == "2")
	{
		query = "dt=getAtnoteRt&id="+topicId+"&rtMapZoom="+rtMapZoom;
	}

	if ( doing == true )
	{
		return;
	}
	boxDiv("body",'first', 300, 30, "boxRed", "clientTop", '载入中...', 'left', 'no_autoHide', 0);
	doing = true;
	
		jQuery.ajax({
			url: "microAtnoteList_ajax.php",
			type: "post",
			data: query,
			dataType: "html",
			timeout: 0,
			success: function(msg){
				//alert(msg);
				doing = false;
				jQuery("body .boxRed").hide();
				try
				{
					var objMe = msg.evalJSON(true);
				}catch(e){
					boxDiv("body",'first', 300, 150, "boxRed", "clientCenter", msg, 'left', 'autoHide', 3000);
					return;
					}
				//alert( objMe.msgStatus);
				if ( objMe.msgStatus == "error" )	// error
				{
					if ( objMe.msgCode == "101" )	//数据库错
					{
					}
						boxDiv("body",'first', 300, 30, "boxRed", "clientCenter", objMe.msgStr, 'center', 'autoHide', 3000);
						//window.setTimeout(function(){window.location="atnoteClientList.php"}, 1000);
						return;
			
					return;
					
				}
				else
				{
					rt_ = objMe.rt;
					//alert(rt_);
					rt_ = rt_.split("|");
					//alert(rt_);
					//alert(rt_.length);
					
					for (i99 = 0; i99<rt_.length; i99++)
					{
						try{   
							lnglat = rt_[i99];
							lnglat = lnglat.split(" ");
							if ( (lnglat[0] == "") || (lnglat[1] == "") ){
									continue;
								}
							var a_rt = "";
							var latlng = new GLatLng(lnglat[1],lnglat[0]);	// lat, lng
							//alert(latlng);
							//var marker = new GMarker(latlng);
							//alert(marker);
							//marker.value=i99;
							//alert(map);
							map.addOverlay(createMarker(latlng, i99 + 1));

						}   
						catch(exception){   
						}   
						finally{   
						}  
					}
		 
		 
					
				}
			},
			error: function(msg){
				doing = false;
				jQuery("body .boxRed").hide();
				boxDiv("body",'first', 300, 150, "boxRed", "clientCenter", "请再试一次...", 'left', 'autoHide', 3000);
			//alert(msg.responseText); 
			}
		});

}
