
var lx,ly
function getDim(el){
for (lx=0,ly=0;el!=null;lx+=el.offsetLeft,ly+=el.offsetTop,el=el.offsetParent)
{}
}

function imageClick(image,i,couid,cityid,url)
{
getDim(image);
len=image.width-10;
hei=image.height-10;
if((event.x - lx)>len&&(event.y- ly)>hei)
{
url="../advertise/ImageAdvAction.do?method=showImageAdv&advcode="+i+"&countryid="+couid+"&cityid="+cityid;
 window.showModalDialog(url,null,"dialogWidth:300px;dialogHeight:250px;help:no;resizable:yes;status:no;scroll:no");
}
else{
if(url!="#")
window.open(url,'','');
}
}

function inputchange()
{
title=document.all("title").value;
 en=0;ch=0;
for (Count=0; Count < title.length; Count++)  {
	TempChar= title.substring (Count, Count+1);
	if (isChinese(TempChar)) ch=ch+1; 
	else en=en+1;
}
leftnum=23-ch-en/2;
if(leftnum<0)
{
title=document.all("title").value;
en=0;ch=0;
for (Count=0; Count < title.length; Count++)  {
	TempChar= title.substring (Count, Count+1);
	if (isChinese(TempChar)) ch=ch+1; 
	else en=en+1;
	if((ch*2+en)>46)break;
}
title=document.all("title").value;
document.all("title").value=title.substring(0,Count);
leftnum=0;
}
document.all("TextNum").value=leftnum;
}

function contentchange()
{
title=document.all("content").value;
 en=0;ch=0;
for (Count=0; Count < title.length; Count++)  {
	TempChar= title.substring (Count, Count+1);
	if (isChinese(TempChar)) ch=ch+1; 
	else en=en+1;
}
leftnum=50-ch-en/2;
if(leftnum<0)
{
title=document.all("content").value;
en=0;ch=0;
for (Count=0; Count < title.length; Count++)  {
	TempChar= title.substring (Count, Count+1);
	if (isChinese(TempChar)) ch=ch+1; 
	else en=en+1;
	if((ch*2+en)>100)break;
}
title=document.all("content").value;
document.all("content").value=title.substring(0,Count);
leftnum=0;
}
document.all("TextNum2").value=leftnum;
}


function isChinese(ch){
   if(escape(ch).indexOf("%u")==-1)
   {
    return false
   }
  return true
}


function check(formName)
{

var ob="",obi="",eName="",fieldTp="c",tp="",len="",decimal="",cName="",isNeed="",vlu="";
if (formName)
	ob=document.forms[formName]; 
else 
	ob=document.forms[0]; 


for (var i=0;i<ob.elements.length;i++)
	{
	obi=ob.elements[i];
	eName=obi.name;

	tp=obi.type;
	cName=obi.cName;

	vlu=obi.value;
	len=obi.len;
	isNeed=obi.isNeed;
	decimal=obi.decimal;
	if (len==null || len=="")
		len=10000000;		//设默认值
	if (isNeed==null || isNeed=="")
		isNeed="N";	//设默认值
	if (decimal==null || decimal=="")
		decimal=2;	//设默认值
	if (obi.dataType=="date")	//c:char/i:纯整数/f:带小数/d:date(YYYY.MM.DD)/m:mail
		fieldTp="d";
	else if (obi.dataType=="float")
		fieldTp="f";
	else if (obi.dataType=="mail")
		fieldTp="m";
	else if (obi.dataType=="int")
		fieldTp="i";
	else if (obi.dataType=="zhengInt")
		fieldTp="z";
	else if (obi.dataType=="tel")
		fieldTp="t";
	else
		fieldTp="c";
	//alert ("eName:"+eName+"  fieldTp:"+fieldTp+",tp="+tp+",len="+len+",decimal="+decimal+",cName="+cName+",isNeed="+isNeed+",vlu="+vlu);

	if ( (isNeed=="Y" || isNeed=="y") && 
		(vlu=="" || vlu=="null") &&
		(tp=="text" || tp=="password" || tp=="textarea" || tp=="select-one"))
		{
		alert(cName+"是必填项！"); 
		obi.focus();
		return false;
		}

	if (vlu!="" && vlu!="null") 
		{ 
		if ((vlu.length>len) && (tp=="text" || tp=="password" || tp=="textarea"))
			{alert (cName+"最大总长度是"+len+"位，请勿超过！")
			obi.focus();
			return false;
			} 
		if ( (tp=="text"||tp=="password") && (fieldTp!="c") )
			{
			if (!valid_input(eName,cName,fieldTp,len,decimal))
				{
				obi.focus();
				return false;
				}
			}
		}

	}//End for
return true;
}//End function


function checkdata(formName) {
	if (formName)
	ob=document.forms[formName]; 
else 
	ob=document.forms[0]; 
if( ob.Password.value.length<1 ) {
alert("\请重新输入密码,密码长度为1-16位任何字符 !!")
return false;
}
if( ob.CPassword.value =="" ) {
alert("\请输入密码确认 !!")
return false;
}
if( ob.CPassword.value != ob.Password.value ) {
alert("\两次密码输入不一致 !!")
return false;
}
return true;
}
function isNumberString (InString,RefString)
{
if(InString.length==0) return (false);
for (Count=0; Count < InString.length; Count++)  {
	TempChar= InString.substring (Count, Count+1);
	if (RefString.indexOf (TempChar, 0)==-1)  
	return (false);
}
return (true);
}
function validateEmail(emailStr){
	var re=/^[\w-]+(\.*[\w-]+)*@([0-9a-z]+[0-9a-z-]*[0-9a-z]+\.)+[a-z]{2,3}$/i;
	if(re.test(emailStr))
		return true;
	else
		return false;
}

