//***************************************************************************************
function getobj(Obj) { return document.getElementById(Obj);}
function getobjs(Objs) {return document.getElementsByName(Objs);}
function $(Obj){return document.getElementById(Obj);}
//***************************************************************************************
function alerts(str) {
if(confirm(str))
{return true;}
return false;
}
//***************************************************************************************
function check_all_yn(obj1,tp)
{
if (tp=="yes")
	{yn=true;}
else if (tp=="no")
	{yn=false;}
	
	
  for (var i=0;i<obj1.length;i++)
    {obj1[i].checked = yn; }  
}

function check_all(obj1,obj2)
{
  for (var i=0;i<obj1.length;i++)
    {
       obj1[i].checked = obj2.checked;
    }  
}

function check_all_f(obj)
{
	if(obj.length)
	{
		for(var i=0;i<obj.length;i++)
		{
			obj[i].checked=!obj[i].checked
		}
	}else{
		
		obj.checked=!obj.checked
	}
}


function is_checked(obj,str) 
{ 
    var result=0
    if(obj.length)
    {
        for(var i=0;i<obj.length;i++)
        {
            if(obj[i].checked)
            {
                result++
            }
        }
    }else{
        result=obj.checked?1:0
    }
	
	if(result==0)
	{
		alert(str)
		return false
	}
	
} 	

function  check_v(obj)   
{   
  var ostr=''
  var o = getobjs(obj); 
  for(var i=0;i<o.length;i++)   
  {  
	  if(o[i].type  ==  'radio'  &&  o[i].checked)  {ostr+='['+o[i].value+']'; }  
	  if(o[i].type  ==  'checkbox'  &&  o[i].checked)  {ostr+='['+o[i].value+']';}  
  } 
  return ostr;
} 

//检查数字输入 并提示
function CheckNumber(Obj,str)
{
	if (Obj.value!='' && (isNaN(Obj.value) || Obj.value<0))
	{
		alert(str+"应填有效数字！");
		Obj.value="";
		Obj.focus();
	}
}
//***************************************************************************************
function change_tx(obj,obj1)
{
//document.getElementById(obj1).src=obj.value;
document.getElementById("imgDiv").innerHTML="<img src='"+obj.value+"' id='pic' onerror=  GetError(this,'请选择图像文件!','/images/tx.gif')   onload='GetSizes_tx()'>";
}
function GetError_tx(obj,obj1,obj2)
{
alert(obj1);
obj.src=obj2
}
function GetSizes_tx()
{
	var width,height;
	var imgObj=document.getElementById("pic");
	width=imgObj.width;
	height=imgObj.height;
//document.getElementById("err_msgs").innerHTML="图片大小(宽&#215;高):<font color=red>" + width + "&#215;" + height + "</font>";
	if(width>75){
		 imgObj.width=75;
		 imgObj.height=imgObj.height/(imgObj.width/75);
	}
}

function change_txxx(obj,obj1)
{
//document.getElementById(obj1).src=obj.value;
document.getElementById("imgDiv").innerHTML="<img src='"+obj.value+"' id='pic' onerror=  GetError(this,'请选择图像文件!','/images/nopic.jpg')   onload='GetSizes()'>";
}
function GetError(obj,obj1,obj2)
{
alert(obj1);
obj.src=obj2
}
function GetSizes()
{
	var width,height;
	var imgObj=document.getElementById("pic");
	width=imgObj.width;
	height=imgObj.height;
//document.getElementById("err_msgs").innerHTML="图片大小(宽&#215;高):<font color=red>" + width + "&#215;" + height + "</font>";
	if(width>164){
		 imgObj.width=164;
		 imgObj.height=imgObj.height/(imgObj.width/164);
	}
}  
//********************************************************************ddd*******************
function showneirong(i,a){
if (i.style.display == "none") {
		i.style.display = "";
		document.images[a].src="/images/Cprevious.gif";
	}else{
		i.style.display = "none";
		document.images[a].src="/images/Cnext.gif";
	}
}


 function ck_add(form)
 {  
    if (form.lb.value=="0")
      {alert("请选择分类！");
      form.lb.focus();
       return (false);
       }	      	   	   
    if (form.title.value=="")
      {alert("请输入标题！");
       form.title.focus();
       return (false);
       }
    if (FCKeditorAPI.GetInstance("content").GetXHTML()=="")
      {alert("请输入内容！");
       var oEditor = FCKeditorAPI.GetInstance('content');
       oEditor.Focus();
       return (false);
       }		 
    return (true);
  }
//*************************
	function FontZoom(fsize){
		var ctext = document.getElementById("arctext");
		ctext.style.fontSize = fsize +"px";
	}
	function cleartext(e) {
		e.value='';
		e.focus();
	}
//***************************************************************************************
function setCookie(name, value)		//cookies设置
{
	var argv = setCookie.arguments;
	var argc = setCookie.arguments.length;
	var expires = (argc > 2) ? argv[2] : null;
	if(expires!=null){
		var LargeExpDate = new Date ();
		LargeExpDate.setTime(LargeExpDate.getTime() + (expires*1000*3600*24));
	}
	document.cookie = name + "=" + escape (value) + "; path=/;" +((expires == null) ? "" : (" expires=" +LargeExpDate.toGMTString()));
}

function getCookie(Name)			//cookies读取
{
	var search = Name + "=";
	if(document.cookie.length > 0){
		offset = document.cookie.indexOf(search);
		if(offset != -1)	{
			offset += search.length;
			end = document.cookie.indexOf(";", offset);
			if(end == -1){
				end = document.cookie.length;
			}
			return unescape(document.cookie.substring(offset, end));
		}
	}
	return "";
}
//***************************************************************************************
function createXMLHttps()
{
    var ret = null;
    try {
        ret = new ActiveXObject('Msxml2.XMLHTTP');
    }
    catch (e) {
        try {
            ret = new ActiveXObject('Microsoft.XMLHTTP');
        }
        catch (ee) {
            ret = null;
        }
    }
    if (!ret && typeof XMLHttpRequest != 'undefined')
        ret = new XMLHttpRequest();
    return ret;
}

function indiv_str(URL)
{
if(URL)
{
    //DIVID.innerHTML = '<img border=0 src=loading.gif>'
	var xmlhttp = createXMLHttps();
	xmlhttp.open("GET",URL,true);
	xmlhttp.onreadystatechange = function()
	{
		//alert(xmlhttp.responseText);
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
		{
			backstr = xmlhttp.responseText;
		}
	}
	return backstr;
	xmlhttp.send(null);
}
}
function indiv(URL,DIVID)
{
var DIVID=document.getElementById(DIVID);
if(DIVID)
{
    //DIVID.innerHTML = '<img border=0 src=loading.gif>'
	var xmlhttp = createXMLHttps();
	xmlhttp.open("GET",URL,true);
	xmlhttp.onreadystatechange = function()
	{
		//alert(xmlhttp.responseText);
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
		{
			DIVID.innerHTML = xmlhttp.responseText;
		}
	}
	xmlhttp.send(null);
}
}
/***************************************************************************************
 * @Title        : JavaScript Document
 * @Description  : JobCn.Com JavaScript Document
 * @Author       : Lzj.Liu
 * @version      : 9.0
 * @Copyright    : (c)2003-2004 Jobcn.Com All Rights Reserved
 ***************************************************************************************/
// 一般页面的常规变量定义
var All  = document.all;
var echo = document.write;
//删除用户输入的空格
function delnbsp(strs)
{
          var Finds=/ /g;
          strs=strs+strs.replace(Finds,"");
          return strs;
}
/**
 * 字串相关 String
 */
/** 修剪字串前后的空格 Base 20030820 */
function trim(s) {
  var count = s.length;
  var st    = 0;       // start
  var end   = count-1; // end

  if (s == "") return s;
  while (st < count) {
    if (s.charAt(st) == " ")
      st ++;
    else
      break;
  }
  while (end > st) {
    if (s.charAt(end) == " ")
      end --;
    else
      break;
  }
  return s.substring(st,end + 1);
}

/**检查是否为有效字符串*/
function IsValidString(checkStr)
{
var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_";
var allValid = true;
if (checkStr.length<1)
 allValid=false;
  for (i=0;i<checkStr.length;i++)
  {
    ch=checkStr.charAt(i);
    for(j=0;j<checkOK.length;j++)
      if(ch==checkOK.charAt(j))
        break;
    if(j==checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  return allValid;
}
/** 测量有汉字时的字串实际长度，其中一个汉字占两个字符 Base 20030820 */
function len(s){
	var length = 0;
	var tmpArr = s.split("");

	for (i = 0; i < tmpArr.length; i++){
		if (tmpArr[i].charCodeAt(0) < 299)
			length ++;
		else
			length += 2;
	}
	return length;
}
/** 是否为合法字串，指只包括字母，数字和_的字串　*/
//edit by liujy2004-06-09 14:57:11 
function isStr(s) {
	if (s.length == 0) return false;
	var regu = "^[0-9A-Za-z_]*$";
	var re   = new RegExp(regu);
    //alert("ssss---s.search(re):"+s.search(re));
    s = s.replace('@', '');
    s = s.replace('.', '');
	if (s.search(re) != -1)
		return true;
	else
    {
        if (isEmail(s)) return true;
		else return false;
    }
}
/** 测试是否为空，或是空格 */
function isNvl(s) {
	return trim(s)==""?true:false;
}
//-------------------------------------------------------------------
/**
 * EMail相关
 */
/** 检测Email是否合法 */
function checkMail(s){
	if (s == "") return false;
	if (s.indexOf("'")!=-1 || s.indexOf("/")!=-1 || s.indexOf("\\")!=-1 || s.indexOf("<")!=-1 || s.indexOf(">")!=-1) return false;

	invalidChars = " /:"; // 不合法字符
    //edit by liujy 2004-08-04 09:30:01 
    s = s.replace('(', '');
    s = s.replace(')', '');
    s = s.replace('（', '');
    s = s.replace('）', '');

	for (i=0; i < invalidChars.length; i++) {
		invalidChar = invalidChars.charAt(i);
		if (s.indexOf(invalidChar,0) != -1)
			return false;
	}
	atPos = s.indexOf("@", 1);
	if (atPos == -1)
		return false;
	periodPos = s.indexOf(".", atPos);
	if (periodPos == -1)
		return false;
	if (periodPos + 3 > s.length)
		return false;

	return true;
}
/** 检测Email是否合法 */
/*
Mender:Lzj.Liu
Date:2004-05-26
Reason:以前的表达式检查ss@ss.hk或z@ss.com;s@dd.net时不能通过
*/
function isEmail(s) {
	if (s.length > 100)	return false;
	if (s.indexOf("'")!=-1 || s.indexOf("/")!=-1 || s.indexOf("\\")!=-1 || s.indexOf("<")!=-1 || s.indexOf(">")!=-1) return false;
    //edit by liujy 2004-08-04 09:30:01 
    s = s.replace('(', '');
    s = s.replace(')', '');
    s = s.replace('（', '');
    s = s.replace('）', '');

	var regu = "^(([0-9a-zA-Z]+)|([0-9a-zA-Z]+[_.0-9a-zA-Z-]*[_.0-9a-zA-Z]+))@([a-zA-Z0-9-]+[.])+(.+)$";
	//{2}|net|NET|com|COM|gov|GOV|mil|MIL|org|ORG|edu|EDU|int|INT|cn|CN|cc|CC
	var re = new RegExp(regu);
	if (s.search(re) != -1)
		return true;
	else
		return false;
}

//-------------------------------------------------------------------
/**
 * 日期相关 Date
 */
/** 检测输入日期是否合法 kerne */
function checkDate(inputyear,inputmonth,inputday){
	var nowdate = new Date();
	var result;
	var varleap_year;
	result = true;
    //alert('### yy='+inputyear+'--mm='+inputmonth+'--dd='+inputday);
	if ((inputyear<1850) || (inputyear>2500) || (!isNum(inputyear))) result=false;
	if ((inputmonth<1) || (inputmonth>12) || (!isNum(inputmonth))) result=false;
	if ((inputday<1) || (inputmonth>31) || (!isNum(inputmonth))) result=false;
	if ((((parseInt(inputyear)%4) == 0) && ((parseInt(inputyear)%100) != 0)) || ((parseInt(inputyear)%400) == 0)) {
		if ((parseInt(inputmonth) == 2) && (parseInt(inputday) > 29)) result=false;
		switch(parseInt(inputmonth)){
			case 4:
				if (parseInt(inputday) > 30) {
					result = false;
					break;
				}
			case 6:
				if (parseInt(inputday)>30) {
					result=false;
					break;
				}
			case 9:
				if (parseInt(inputday)>30) {
					result=false;
					break;
				}
			case 11:
				if (parseInt(inputday)>30) {
					result=false;
					break;
				}
		}
	} else {
		switch(parseInt(inputmonth)) {
			case 2:
				if (parseInt(inputday)>28) {
					result=false;
					break;
				}
			case 4:
				if (parseInt(inputday)>30) {
					result=false;
					break;
				}
			case 6:
				if (parseInt(inputday)>30) {
					result=false;
					break;
				}
			case 9:
				if (parseInt(inputday)>30) {
					result=false;
					break;
				}
			case 11:
			if (parseInt(inputday)>30) {
				result=false;
				break;
			}
		}
	}
    //alert('result--'+result);
	return result;
}
/**
 *取任意一个日期的当月最大天数,如8月有31天
 *@Param:合格的日期,如:new Date()
 *@Return:当月最大天数
 */
function getDays(dDate) 
{ 	
	var iYear = dDate.getFullYear(); 
	var iMonth = dDate.getMonth()-1; 
	var iDay = dDate.getDate(); 

	var dStart = new Date(iYear, iMonth, 1); 
	var dEnd = dateAdd("m", 1, dStart); 

	var iDays = dateDiff("d", dStart, dEnd); 
	var iStartDay = (dStart.getDay() + 1); 
	for (i = 1;  i < 43; i++) 
	{         
		if ((i < iStartDay) || ((i - iStartDay + 1) > iDays)) null; 
		else var dayScount=(i - iStartDay + 1); 
	} 
	return parseInt(dayScount); 
} 
/**
 *返回已添加指定时间间隔的日期
 *@Param:sInterval时间单位
 *@Param:iNumber要添加间隔数
 *@Param:dDate标准的日期格式
 *@Return:标准的日期格式
 */
function dateAdd(sInterval, iNumber, dDate) 
{ 
	dTemp = new Date(dDate); 
	if (dTemp == "NaN") dTemp = new Date(); 
	switch (sInterval) 
	{ 
		case "s" : 	//秒
			return new Date(Date.parse(dTemp) + (1000 * iNumber)); 
		case "n" : 	//分
			return new Date(Date.parse(dTemp) + (60000 * iNumber)); 
		case "h" : 	//小时
			return new Date(Date.parse(dTemp) + (3600000 * iNumber)); 
		case "d" : 	//天
			return new Date(Date.parse(dTemp) + (86400000 * iNumber)); 
		case "w" : 	//星期
			return new Date(Date.parse(dTemp) + ((86400000 * 7) * iNumber)); 
		case "m" : 	//月
			return new Date(dTemp.getFullYear(), (dTemp.getMonth()) + iNumber, dTemp.getDate()); 
		case "y" : 	//年
			return new Date((dTemp.getFullYear() + iNumber), dTemp.getMonth(), dTemp.getDate()); 
	} 
} 
/**
 *返回两个日期之间的时间间隔
 *@Param:sInterval时间单位
 *@Param:dStart开始时间
 *@Param:dEnd结束时间
 *@Return:间隔数
 */
function dateDiff(sInterval, dStart, dEnd) 
{ 
	dStart = new Date(dStart); 
	if (dStart == "NaN") dStart = new Date(); 
	dEnd = new Date(dEnd); 
	if (dEnd == "NaN") dEnd = new Date(); 
	switch (sInterval) 
	{ 
		case "s" : 	//秒
			return parseInt((Date.parse(dEnd) - Date.parse(dStart)) / 1000); 
		case "n" : 	//分
			return parseInt((Date.parse(dEnd) - Date.parse(dStart)) / 60000); 
		case "h" : 	//小时
			return parseInt((Date.parse(dEnd) - Date.parse(dStart)) / 3600000); 
		case "d" : 	//天
			iScrap = (Date.parse(dEnd) - Date.parse(dStart)) / 86400000 
			iScrap = iScrap + .1 
			return parseInt(iScrap); 
		case "w" : 	//星期
			return parseInt((Date.parse(dEnd) - Date.parse(dStart)) / (86400000 * 7)); 
		case "m" : 	//月
			return (dEnd.getMonth() - dStart.getMonth()); 
		case "y" : 	//年
			return (dEnd.getFullYear() - dStart.getFullYear()); 
	} 
}
//-------------------------------------------------------------------
/**
 * 电话号码相关
 * 很差劲,需要测试[重复]
 */
//检查是否为正确的电话号码
function isTel(checkStr){
var checkOK = "0123456789-/,()";
var allValid = true;
if (checkStr.length<1)
 allValid=false;
  for (i=0;i<checkStr.length;i++)
  {
    ch=checkStr.charAt(i);
    for(j=0;j<checkOK.length;j++)
      if(ch==checkOK.charAt(j))
        break;
    if(j==checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  return allValid;
}

/** 检查电话号码输入是否合法 */
function checkPhone(s){
	if (s.length < 1) return false;

	var tmpChar = "0123456789-/,()";

	for (i = 0; i < s.length; i++) {
		ch = s.charAt(i);
		for(j = 0; j < tmpChar.length; j++) {
			if (ch == tmpChar.charAt(j))
				break;
			if (j == tmpChar.length - 1)
				return false;
		}
	}
	return true;
}

/** 检查电话号码输入是否合法 Base 20030820 */
function isPhone(s) {
	var regu = "^(([(0-9)]+)|([0-9-]+))(([0-9-]+)|([0-9]+))([0-9])$";
	var re   = new RegExp(regu);
	if (s.search(re) != -1)
		return true;
	else
		return false;
}

//idx:1,电话;2,手机;3,呼机;4.其它
function getCheckErrInfo(idx)
{
    var info = '';
    switch (idx)
    {
        case 1:
            info = '不是有效电话号码,请修改!(如010-3366291-129)请注意:全角字符不能通过校验!';
            break;
        case 2:
            info = '不是有效手机号码,请修改!([0]13xxxxxxxxx)请注意:全角字符不能通过校验!';
            break;
        case 3:
            info = '不是有效呼机号码,请修改!(如[010-]90951-95005)请注意:全角字符不能通过校验!';
            break;
        default:
            info = '不是有效电话号码,请修改!(如010-3366291-129)请注意:全角字符不能通过校验!';
    }
    alert(info);
    //return info;
}
