var _RESPONSE_WINDOW = "responseWindow";
//验证是否为字符
function checkFormString(name,ctrl,allowNull,minLen,maxLen)
{
	try
	{
		
		var datastr = ctrl.value;
		var lefttrim = datastr.search(/\S/gi);
		if (lefttrim == -1) 
		{
			if (allowNull) 
			{
				return true;
			} 
			else 
			{
			  alert(name + JS_ERROR_NULL);
			  if (ctrl.type.toLowerCase() != "hidden")
				  ctrl.focus();
			  return false;
			}
		}
		if (datastr.search(/[<>]/gi) != -1) 
		{
			alert(name + JS_ERROR_INVALID_STRING);
			  if (ctrl.type.toLowerCase() != "hidden")
				  ctrl.focus();
			return false;
		}
		if ((minLen > 0) && (datastr.length < minLen))
		{
			alert(name + JS_ERROR_STRING_TOO_SHORT + minLen);
			  if (ctrl.type.toLowerCase() != "hidden")
				  ctrl.focus();
			return false;
		}
		if ((maxLen > 0) && (datastr.length > maxLen))
		{
			alert(name + JS_ERROR_STRING_TOO_LONG + maxLen);
			  if (ctrl.type.toLowerCase() != "hidden")
				  ctrl.focus();
			return false;
		}
		return true;
	}
	catch (e)
	{
		alert(e);
		return false;
	}
}

//验证EMAIL
function checkFormEmail(name, ctrl, allowNull)
{
	var datastr = ctrl.value;
	var lefttrim = datastr.search(/\S/gi);
    if (lefttrim == -1) 
    {
    	if (allowNull) 
		{
      		return true;
    	} 
		else 
		{
      		alert(name + JS_ERROR_NULL);
			  if (ctrl.type.toLowerCase() != "hidden")
				  ctrl.focus();
      		return false;
    	}
  	}

  	var myRegExp = /[a-z0-9](([a-z0-9]|[_\-\.][a-z0-9])*)@([a-z0-9]([a-z0-9]|[_\-][a-z0-9])*)((\.[a-z0-9]([a-z0-9]|[_\-][a-z0-9])*)*)/gi;
  	var answerind = datastr.search(myRegExp);
  	var answerarr = datastr.match(myRegExp);

  	if (answerind == 0 && answerarr[0].length == datastr.length)
  	{
    	return true;
  	}
  if (ctrl.type.toLowerCase() != "hidden")
	  ctrl.focus();
  	alert(name + JS_ERROR_INVALID_EMAIL);
  	return false;
}

//验证是否为一个整数（正整数和负数 0）
function checkFormInt(name,ctrl,allowNull)
{
	var num=ctrl.value;
	if(num.search(/^-?[0-9][0-9]*$/gi)!= -1)
		return true;
	else
	{
		if (num=='')
		{
			if (allowNull)
				return true;
			else
				alert(name + JS_ERROR_NULL);
		}
		else
		{
			alert(name + JS_ERROR_INVALID_NUMERIC);
		}
		ctrl.focus();
		return false;
	}
}

//验证密码（数字和字母）
function checkFormPassword(name,ctrl,allowNull)
{
	var num=ctrl.value;

	if(num.search(/^[a-zA-Z0-9_]*$/gi)!= -1)
		return true;
	else
	{
		if (num=='')
		{
			if (allowNull)
				return true;
			else
				alert(name + JS_ERROR_NULL);
		}
		else
		{
			alert(name + JS_ERROR_INVALID_PASSWORD);
		}
		ctrl.focus();
		return false;
	}
}

//验证是否为一个正数
function checkFormNum(name,ctrl,allowNull)
{
	var num=ctrl.value;
	if(num.search(/^[0-9]+(\.[0-9]*)?$/gi)!= -1)
		return true;
	else
	{
		if (num=='')
		{
			if (allowNull)
				return true;
			else
				alert(name + JS_ERROR_NULL);
		}
		else
		{
			alert(name + JS_ERROR_INVALID_NUMERIC);
		}
		ctrl.focus();
		return false;
	}
}

//验证字符是否为小于一的实数
function checkFormLessThanOne(name,ctrl,allowNull)
{
	var num=ctrl.value;
	if(num.search(/^[0]+(\.[0-9]*)?$/gi)!= -1)
		return true;
	else
	{
		if (num=='')
		{
			if (allowNull)
				return true;
			else
				alert(name + JS_ERROR_NULL);
		}
		else
		{
			alert(name + JS_ERROR_INVALID_LESS_THAN_ONE);
		}
		ctrl.focus();
		return false;
	}
}


function checkFormNumWithoutZero(name,ctrl,allowNull)
{
	var num=ctrl.value;
	if(num.search(/^[0-9]*[1-9][0-9]*$/gi)!= -1)
		return true;
	else
	{
		if (num=='')
		{
			if (allowNull)
				return true;
			else
				alert(name + JS_ERROR_NULL);
		}
		else
		{
			alert(name + JS_ERROR_INVALID_NUMERIC);
		}
		ctrl.focus();
		return false;
	}
}

//验证是否为正数且只有两位以内小数
function checkFormMoneyType(name,ctrl,allowNull)
{
	var num = ctrl.value;
	if(num.search(/^[0-9]+(.[0-9]{1,2})?$/)!= -1)
		return true;
	else
	{
		if (num=='')
		{
			if (allowNull)
				return true;
			else
				alert(name + JS_ERROR_NULL);
		}
		else
		{
			alert(name + JS_ERROR_INVALID_NUMERIC);
		}
		ctrl.focus();
		return false;
	}
}

function checkFormIntNum(name,ctrl,allowNull)
{
	var num=ctrl.value;
	if(num.search(/^([0-9])+([0-9]*)?$/gi)!= -1)
		return true;
	else
	{
		if (num=='')
		{
			if (allowNull)
				return true;
			else
				alert(name + JS_ERROR_NULL);
		}
		else
			alert(name + JS_ERROR_INVALID_INT);
		  if (ctrl.type.toLowerCase() != "hidden")
			  ctrl.focus();
		return false;
	}
}

//大于0的正整数
function checkFormMoreThanZeroIntNum(name,ctrl,allowNull)
{
	var num=ctrl.value;
	if(num.search(/^([1-9])+([0-9]*)?$/gi)!= -1)
		return true;
	else
	{
		if (num=='')
		{
			if (allowNull)
				return true;
			else
				alert(name + JS_ERROR_NULL);
		}
		else
			alert(name + JS_ERROR_INVALID_MORE_THAN_ZERO_INT);
		  if (ctrl.type.toLowerCase() != "hidden")
			  ctrl.focus();
		return false;
	}
}

function parseNum(theNum){
  if (theNum.substring(0,1)==0)
    theNum=theNum.substring(1)
  return theNum
}

function parseYMD(theYear,theMonth,theDay) {
  theYear=parseNum(theYear)
  theMonth=parseNum(theMonth)
  theDay=parseNum(theDay)
  if ((theYear < 1900) || (theYear > 3000)){
    return 1
  }

  if (theMonth < 1 || theMonth > 12){
    return 2
  }

  if ((theMonth==1 || theMonth==3 || theMonth==5 || theMonth==7 || theMonth==8 || theMonth==10 || theMonth==12) &&
      (theDay <1 || theDay > 31)
     ){
    return 3
  }

  if ((theMonth==4 || theMonth==6 || theMonth==9 || theMonth==11) &&
      (theDay <1 || theDay > 30)
     ){
    return 3
  }

  if (theYear%400==0 || (theYear%4==0 && theYear%100!=0)){  //  
    if (theMonth==2 && (theDay <1 || theDay > 29) )
      return 3
  }
  else  //  
    if (theMonth==2 && (theDay <1 || theDay > 28) )
      return 3
  return 0
}

function isInvalidDate(theDate,separator){
  default_style=1
  if (theDate.length>10 || theDate.length<8)
    return true
  idx1=theDate.indexOf(separator)
  if (idx1==-1)
    return true
  idx2=theDate.indexOf(separator,idx1+1)
  if (idx2==-1)
    return true
  if (isInvalidDate.arguments.length>2)
  	default_style=isInvalidDate.arguments[2]
  if (default_style<1 || default_style>9){
  	alert("Parameter Error,please check!")
	return true
  }

  if (default_style==1){
  theYear=theDate.substring(0,idx1)
  theMonth=theDate.substring(idx1+1,idx2)
  theDay=theDate.substring(idx2+1)
  }
  if (default_style==2){
  theMonth=theDate.substring(0,idx1)
  theDay=theDate.substring(idx1+1,idx2)
  theYear=theDate.substring(idx2+1)
  }
  if (theDay.length>2)
    return true
  if (parseYMD(theYear,theMonth,theDay)>0)
    return true
  else
    return false
}

function openWindow(n,u,w,h)
{
	var windowLeft = (window.screen.availWidth - w)/2;
	var windowTop = (window.screen.availHeight - h)/2;
	args = "left="+windowLeft+",top="+windowTop+",width="+w+",height="+h+",resizable=yes,scrollbars=yes,status=1";
	window.open(u,n,args);
}

function openStaticWindow(n,u,w,h)
{
	var windowLeft = (window.screen.availWidth - w)/2;
	var windowTop = (window.screen.availHeight - h)/2;
	args = "left="+windowLeft+",top="+windowTop+",width="+w+",height="+h+",resizable=no,scrollbars=no,status=0";
	window.open(u,n,args);
}

function openModalDialog(u,w,h)
{
	var windowLeft = (window.screen.availWidth - w)/2;
	var windowTop = (window.screen.availHeight - h)/2;
	args = "dialogLeft="+windowLeft+"px;dialogTop="+windowTop+"px;dialogWidth="+w+"px;dialogHeight="+h+"px;";
	return window.showModalDialog(u,"",args);
}

function setSelectionOption(the_selection, option_list)
{
  var arr_dir, str_dir;
  the_selection.length=0;
  for(var i=0; i<option_list.length; i++)
  {
    	str_dir=new String(option_list[i]);
        arr_dir=str_dir.split("===");
        the_selection.options[i] = new Option();
		the_selection.options[i].value = arr_dir[0];
		the_selection.options[i].text = arr_dir[1];
  }
}

function selectOptionInSelect(the_selection, value)
{
    for (var i=0; i<the_selection.length; i++)
    {
    if (the_selection.options[i].value == value) 	the_selection.options[i].selected = true;
    }
}

function getSelectionValues(selectCtrl)
{
	var values = '';
	var s;
	if (selectCtrl == null) 
		return values;
	s = selectCtrl;
	if (s.type)
		if (s.checked)
			return s.value;
		else
			return values;
	for (i=0; i<s.length; i++)
	{
		if (s[i].checked)
		{
			if (values == '')
				values += s[i].value;
			else
				values += ',' + s[i].value;
		}
	}
	return values;
}

function selectAllSelections(selectCtrl, selected)
{
	if (selectCtrl == null) 
		return;
	s = selectCtrl;
	if (s.type)
	{
		if (s.disabled != true && s.readonly != true)
			s.checked = selected;
	}
	for (i=0; i<s.length; i++)
	{
		if (s[i].disabled != true && s[i].readonly != true)
			s[i].checked = selected;
	}
}

//反选
function reverseChoiceSelections(selectCtrl, selected)
{
	if (selectCtrl == null) 
		return;
	s = selectCtrl;
	if (s.type)
	{
		if (s.disabled != true && s.readonly != true)
		{			
			
			s.checked = (s.checked == true) ? false : true;
		}
	}
	for (i=0; i<s.length; i++)
	{
		if (s[i].disabled != true && s[i].readonly != true)
			s[i].checked = (s[i].checked == true) ? false : true;
	}
}


function validateFormData(theForm)
{
	submitFormInResponseWindow(theForm);
}

function resetFormData(theForm)
{
	theForm.reset();
	return true;
}
//resize image size
function resizeImg(resLimit,limit){
	if (window.document.all.item('res')!=null)
		{resize (window.document.all.item('res'),resLimit);}
	if (window.document.all.item('map')!=null)
		{resize (window.document.all.item('map'),resLimit);}
	var i;
	for (i=0;window.document.all.item('img'+i)!=null;i++){
	resize (window.document.all.item('img'+i),limit);}
}
function resize(obj,limit){
	//var limit = 250;
	if (obj.width >limit || obj.height >limit){
		if (obj.height > obj.width)
			obj.height = limit;
		else
			obj.width = limit;
	}
}

function getPos(el,sProp) {
	var iPos = 0;
	while (el!=null) {
		iPos+=el["offset" + sProp];
		el = el.offsetParent;
	}
	return iPos;
}

function getDays(month, year)
{
	/*
	Check for leap year ..
	1.Years evenly divisible by four are normally leap years, except for...
	2.Years also evenly divisible by 100 are not leap years, except for...
	3.Years also evenly divisible by 400 are leap years.
	*/
	var monthArray1 = new Array();
	var monthArray2 = new Array();
	var monthNo = month - 1;
	// Non-Leap year Month days..
	monthArray1 = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
	// Leap year Month days..
	monthArray2 = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
	if ((year % 4) == 0) {
		if ((year % 100) == 0 && (year % 400) != 0)
			return monthArray1[monthNo];

		return monthArray2[monthNo];
	} else
		return monthArray1[monthNo];
}

function selectDate(yearSelectId,monthSelectId,daySelectId,defaultDay)
{
	
	var frmYear = document.getElementById(yearSelectId);
	var frmMonth = document.getElementById(monthSelectId);
	var frmDay = document.getElementById(daySelectId);
	var newDate = new Date();
	var year = frmYear.value;
	var month = frmMonth.value;
	if (year > 0 && month > 0)
	{
		var days = getDays(month,year);
		var i;
		frmDay.options.length = 0;
		for (i = 1;i <= days;i ++)
		{
			frmDay.options[i-1]= new Option(i ,i);
			if (i == defaultDay)
				frmDay.options[i-1].selected = true;
		}
	}
}

function dictionary(name,value,connective)
{
	this.name = name;
	this.value = value;
	this.connective = connective;
}

function showSubList(optionId,subOptionId,arrayName,SubArrayName,selectedValue,defaultStr)
{
	var frmOptionId = document.getElementById(optionId);
	var frmSubOptionId = document.getElementById(subOptionId);
	var parentArray = new Array();
	var subArray = new Array;
	var parentCode,fieldValue,connective,i,j,k=0,parentLength,subLength;
	parentArray = eval(arrayName);
	parentLength = parentArray.length;
	subArray = eval(SubArrayName);
	optionValue = frmOptionId.value;
	parentLength = parentArray.length;
	subLength = subArray.length;
	frmSubOptionId.options.length = 0;
	if (defaultStr == "")
		defaultStr = "请选择";
	frmSubOptionId.options[k]= new Option(defaultStr,"");
	k ++;
	if (optionValue.length > 0)
	{
		for (i = 0;i < parentLength;i ++)
		{
			if (parentArray[i].value == optionValue)
			{
				connective = parentArray[i].connective;
				break;
			}	
		}
		if (connective.length > 0)
		{
			for (j = 0;j < subLength;j ++)
			{
				if (subArray[j].connective == connective)		
				{
					frmSubOptionId.options[k]= new Option(subArray[j].name,subArray[j].value);
					if (subArray[j].value == selectedValue)
					{
						frmSubOptionId.options[k].selected = true;
					}
					k ++;
				}
			}
		}
	}
}

function MobileClass(name,value,connective,parentConnective)
{
	this.name = name;
	this.value = value;
	this.connective = connective;
	this.parentConnective = parentConnective;
}

function showMobileSubList(optionId,subOptionId,arrayName,SubArrayName,selectedValue,defaultStr)
{
	var frmOptionId = document.getElementById(optionId);
	var frmSubOptionId = document.getElementById(subOptionId);
	var parentArray = new Array();
	var subArray = new Array;
	var parentCode,fieldValue,connective,i,j,k=0,parentLength,subLength;
	parentArray = eval(arrayName);
	parentLength = parentArray.length;
	subArray = eval(SubArrayName);
	optionValue = frmOptionId.value;
	parentLength = parentArray.length;
	subLength = subArray.length;
	frmSubOptionId.options.length = 0;
	if (defaultStr == "")
		defaultStr = "请选择";
	frmSubOptionId.options[k]= new Option(defaultStr,"");
	k ++;
	if (optionValue.length > 0)
	{
		for (i = 0;i < parentLength;i ++)
		{
			if (parentArray[i].value == optionValue)
			{
				connective = parentArray[i].connective;
				break;
			}	
		}
		if (connective.length > 0)
		{
			for (j = 0;j < subLength;j ++)
			{
				if (subArray[j].parentConnective == connective)		
				{
					frmSubOptionId.options[k]= new Option(subArray[j].name,subArray[j].value);
					if (subArray[j].value == selectedValue)
					{
						frmSubOptionId.options[k].selected = true;
					}
					k ++;
				}
			}
		}
	}
}


function genFloatFormat(realNum, preciseBit)
{
	var sourceNum = realNum;
	
	var pos = parseInt(preciseBit);
	if (pos > 0)
	{
		var factor = 1;
		for (var i = 0;i < pos;i ++)
			factor = factor * 10;
		return Math.round(parseFloat(sourceNum.toString()) * factor) / factor;
	}
	else
		return sourceNum;
}

//信息滚动效果
function infoRollEffect(ul, delay, speed, lineHeight)
{ 
	var slideBox = (typeof ul == 'string') ? document.getElementById(ul) : ul; 
	var delay = delay||1000; 
	var speed = speed||20; 
	var lineHeight = lineHeight||20; 
    var tid = null, pause = false; 
    var start = function()
	{ 
		tid=setInterval(slide, speed); 
    } 
    var slide = function()
	{ 
		if (pause) return; 
		slideBox.scrollTop += 2; 
		if (slideBox.scrollTop % lineHeight == 0)
		{ 
			clearInterval(tid); 
			slideBox.appendChild(slideBox.getElementsByTagName('li')[0]); 
			slideBox.scrollTop = 0; 
			setTimeout(start, delay); 
		} 
    } 
    slideBox.onmouseover = function(){pause=true;} 
    slideBox.onmouseout = function(){pause=false;} 
    setTimeout(start, 2000); 
}

//在线客服
function HJLiveChat_loadingJs(url) 
{
	var html_doc = document.getElementsByTagName('head').item(0);
	var js = document.createElement('script');
	js.setAttribute('language', 'javascript');
	js.setAttribute('type', 'text/javascript');
	js.setAttribute('src', url);
	html_doc.appendChild(js);
}

//DIV浮动效果
function FloatingDIV_refresh(divId)
{
	var introDiv = document.getElementById(divId);
	var number = document.getElementById("number");
	var StartPoint, EndPoint;

	StartPoint = parseInt(introDiv.style.top.replace("px",""));
	///EndPoint = document.body.scrollTop;
	EndPoint = (document.documentElement && document.documentElement.scrollTop) ? document.documentElement.scrollTop : document.body.scrollTop;
	if (EndPoint < 0) EndPoint = 0;

	if (StartPoint != EndPoint ) {
	 ScrollAmount = Math.ceil( Math.abs( EndPoint - StartPoint ) / 15 );
	 introDiv.style.top = parseInt(introDiv.style.top) + ( ( EndPoint < StartPoint ) ? -ScrollAmount : ScrollAmount )+"px";
	}

	setTimeout ("FloatingDIV_refresh('" + divId +"');", 3);
}
function FloatingDIV(introDivId)
{
   var introDiv = document.getElementById(introDivId);
   introDiv.style.top = 0;
   FloatingDIV_refresh(introDivId);
} 

function copyUrl(url)
{
	clipboardData.setData('Text', url);
	alert('复制成功');
}

function refurbishCheckCode()
{
	var imgCode = document.getElementById("imgCode");
	window.location.hostname
	imgCode.src = "http://" + window.location.hostname + "/index.php?akm=member&aka=checkCode&act=init&rnd=" + Math.random();
}
