function checkLogin()
{
	var username = $('username');
	var password = $('password');
	var usertype = $('usertype');
	if(usertype.value == '')
	{
		alert('请选择用户类型！');
		usertype.focus();
	}
	else if(username.value == '')
	{
		alert('请输入您的用户名！');
		username.focus();
	}
	else if(password.value == '')
	{
		alert('请输入密码！');
		password.focus();
	}
	else
	{
		return true;
	}
	return false;
}


function checkLogin2()
{
	var username = $('username2');
	var password = $('password2');
	var usertype = $('usertype2');
	if(usertype.value == '')
	{
		alert('请选择用户类型！');
		usertype.focus();
	}
	else if(username.value == '')
	{
		alert('请输入您的用户名！');
		username.focus();
	}
	else if(password.value == '')
	{
		alert('请输入密码！');
		password.focus();
	}
	else
	{
		return true;
	}
	return false;
}


function goRegister()
{
	var usertype = $('usertype');
	if(usertype.value == '')
	{
		alert('请选择用户类型！');
		usertype.focus();
	}
	else
	{
		document.location = usertype.value + 'register.php';
	}
}


function goRegister2()
{
	var usertype = $('usertype2');
	if(usertype.value == '')
	{
		alert('请选择用户类型！');
		usertype.focus();
	}
	else
	{
		document.location = usertype.value + 'register.php';
	}
}



function switchSearchMenu(parenid, currentobj)
{
	var parentobj = $(parenid);
	if(parentobj==null || currentobj==null)
		return;
	for(var i=0; i<parentobj.childNodes.length; i++)
	{
		var objchild = parentobj.childNodes[i];
		if(objchild.className == 'current')
		{
			objchild.className = '';
		}
	}
	currentobj.parentNode.parentNode.className = 'current';
	return;
}

//显示二维地图标注对话框
function showDialog(url, width, height)
{
	var w = window.screen.width;
	var h = window.screen.height;
	var l = (w-width)/2;
	var t = (h-height)/2;
	window.open(url, '_zfwdlg', 'width=' + width + ',height=' + height + ',top=' + t + ',left=' + l + ',scroll=no,toolbar=no');
}

function $(elementid)
{
	return document.getElementById(elementid);
}



function setinputvalue(inputid, value)
{
	var objinput = document.getElementById(inputid);
	if(!objinput || objinput.type=="checkbox" || objinput.type=="radio")
	{
		var inputs = document.getElementsByName(inputid);
		for(var i=0; i<inputs.length; i++)
		{
			if((inputs[i].type=="radio" || inputs[i].type=="checkbox") && inputs[i].value==value)
			{
				inputs[i].checked = true;
				return;
			}
		}
		return;
	}
	if(objinput.type=="text" || objinput.type=="hidden")
		objinput.value = value;
	else if(objinput.tagName.toLowerCase() == "select")
	{
		for(var i=0; i<objinput.options.length; i++)
		{
			if(objinput.options[i].value == value)
			{
				objinput.selectedIndex = i;
				break;
			}
		}
	}
	else if(objinput.tagName.toLowerCase() == "textarea")
	{
		objinput.value = value;
	}
	else
		return;
}



function isNumberInput(field, event) 
{
  var key, keyChar;

  if (window.event)
    key = window.event.keyCode;
  else if (event)
    key = event.which;
  else
    return true;
  // Check for special characters like backspace
  if (key == null || key == 0 || key == 8 || key == 13 || key == 27)
    return true;
  // Check to see if it's a number
  keyChar =  String.fromCharCode(key);
  if (/[\d|\.]/.test(keyChar)) 
    {
     window.status = "";
     return true;
    } 
  else 
   {
    window.status = "该输入框仅接受数字输入";
    return false;
   }
}


//trim函数的js实现，去掉字符串的首尾空格
function trim(text)
{
	text = text.replace(/^[ |\n|\r|\t|\x0B|\0|　]+/,""); //去除串首空格
	text = text.replace(/[ |\n|\r|\t|\x0B|\0|　]+$/,""); //去除串尾空格
	return text;
}

function resizeImage(objimg, maxwidth)
{
	if(! objimg)
		return;
	if(objimg.width > maxwidth)
		objimg.width = maxwidth;
}


//删除上传文件
function deleteFile(id, frameid, itemtype, itemid, phototype, finsert)
{
	var objframe = document.getElementById(frameid);
	objframe.src = "uploadphoto.php?itemtype="
		+itemtype+"&itemid="+itemid+"&phototype="
		+phototype+"&act=delete&id="+id+"&finsert="+finsert;
}


//右滚动
function MarqueeR(){ 
	if(demo.scrollLeft<=0) 
		demo.scrollLeft += demo2.offsetWidth;
	else{ 
		demo.scrollLeft --;
	} 
}

//左滚动
function Marquee(){
	if(demo2.offsetWidth-demo.scrollLeft<=0)
	{
		demo.scrollLeft -= demo2.offsetWidth;
	}
	else
	{
		demo.scrollLeft ++;
	}
}


function cf(flashsrc,flashwidth,flashheight,flashlink,br){
	document.write("<table width="+flashwidth+" height="+flashheight+" border=0 cellpadding=0 cellspacing=0><tr><td>");
	document.write("<div style=\"position:relative\">");
	document.write("<embed style=\"position:absolute;z-index:0\" src="+flashsrc+" quality=\"high\" width="+flashwidth+" height="+flashheight+" TYPE=\"application/x-shockwave-flash\" PLUGINSPAGE=\"http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\" wmode=\"opaque\"></embed>");
	document.write("<div style=\"position:relative;filter:alpha(opacity=0);-moz-opacity:0;z-index:10;left:0;top:0;background:transparent !important;background:#cdeaf6;width:"+flashwidth+";height:"+flashheight+"px;\">");
	document.write("<a href="+flashlink+" target=\"_blank\" style=\"cursor:pointer;display:block;width:"+flashwidth+";height:"+flashheight+"px;\"></a>");
	document.write("</div>");
	document.write("</div>");
	document.write("</td></tr></table>");
	if (br=="1") {
	document.write("<br>");
	}
}

function cf1(flashsrc,flashwidth,flashheight,br){
	document.write("<embed src=\""+flashsrc+"\" quality=high pluginspage=\"http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\" type=\"application/x-shockwave-flash\" width="+flashwidth+" height="+flashheight+" align=center></embed>");
	if (br=="1") {
	document.write("<br><br>");
	}
}


function switchboard(currentlink, linkname, boardname)
{
	var arrlinks = document.getElementsByName(linkname);
	var currentindex = 0;
	for(var i=0; i<arrlinks.length; i++)
	{
		if(arrlinks[i] == currentlink)
		{
			$(boardname+i).style.display = 'block'
		}
		else
		{
			arrlinks[i].className = 'normal';
			$(boardname+i).style.display = 'none';
		}
	}
	currentlink.className = 'current';
}


function resizePhotos()
{
	var objimg;
	for(var i=0; i<document.images.length; i++)
	{
		objimg = document.images[i];
		if(objimg.className == 'uploadedphoto')
		{
			resizePhoto(objimg);
		}
	}
}
function resizePhoto(objimg)
{
	resizeImage(objimg, 440);
}

function toggleObj(obj, status)
{
	if(obj)
	{
		obj.style.display= (status ? 'block' : 'none');
	}
}
function setObjPos(obj, evt)
{
	if(window.event)
		evt = window.event;
	var x = evt.clientX;
	var y = evt.clientY;
	obj.style.left = x+"px";
	obj.style.top = y+"px";
}

function isChecked(objs)
{
	for(var i=0; i<objs.length; i++)
	{
		if(objs[i].checked)
			return true;
	}
	
	return false;
}

function isTelephone(str)
{
	if(/^[\d]{3,4}-[\d]{7,8}$/.test(str) || /^[\d]{7,8}$/.test(str))
		return true;
	else
		return false;
}

function isMobile(str)
{
	if(/^13[\d]{9}$/.test(str) || /^15[\d]{9}$/.test(str))
		return true;
	else
		return false;
}

function isEmail(str)
{
	return /[^@]+@[^@]+/.test(str);
}

