﻿/**
 * @author Jack (SWL)
 * 
 * @copyright www.uaa.cn
 * @projectDescription - uaa -  保险系统.
 * 实现保险系统公用方法.		
 * 
 * ======================================================================
 */
  



//修改网页的宽度和高度  
function windowResize(windowW,windowH,topsize){
	window.resizeTo(windowW,windowH);
	if(window.screenTop>1000){
		window.moveTo((screen.width-windowW)/2,(screen.height-windowH)/2);
	}
	if(!isNaN(topsize)){
		window.moveTo((screen.width-windowW)/2,topsize);
	}
}

function daysTime4(_date,day)
{
	var time = _date.split("-");

    var now = new Date(time[0],time[1]-1,time[2]);  //
	var milliseconds = day*1000*60*60*24;
	var testdate = milliseconds + now.getTime(); 
	var testDate = new Date();
	testDate.setTime(testdate);
    return testDate.getYear()+ "-" + (testDate.getMonth()+1) + "-" + testDate.getDate();
}

//验证是否有非常字符
function checkStr(obj,str){
	var obj=eval(obj);
	var checkString="`~!@#$%^&*()+=[]{}\\|;':\",./<>?";
	//if(typeof(str)!="undefined")checkString=str;
	for (var j=0;j<checkString.length;j++)
	{
		if(obj.value.indexOf(checkString.substring(j,j+1))!=-1)
		{
			alert("不能有非常字符:\""+checkString.substring(j,j+1)+"\"");
			obj.select();
			return true;
		}
	}
}


//验证EMAIL 
function isEmail(val){
	var pass=0; 
	if (window.RegExp){
	  var tempS="a"; 
	  var tempReg=new RegExp(tempS);
	  if (tempReg.test(tempS)) pass=1;
	}
	if(!pass)return(val.indexOf(".")>2) && (val.indexOf("@")>0);
	var r1=new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
	var r2=new RegExp("^[a-zA-Z0-9\\.\\!\\#\\$\\%\\&\\??\\*\\+\\-\\/\\=\\?\\^\\_\\`\\{\\}\\~]*[a-zA-Z0-9\\!\\#\\$\\%\\&\\??\\*\\+\\-\\/\\=\\?\\^\\_\\`\\{\\}\\~]\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
	return (!r1.test(val) && r2.test(val)); 
}

//验证手机号
function isMobile(val){ 
	var myreg =  /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+\d{8})$/;
	return (myreg.test(val));
} 

//验证电话号码
function  isTel(val){
	var Letters = "1234567890-"; 
	var i;
	var c;
	if(val.charAt(0)=='-')
		return false;
	if(val.charAt(val.length -1)=='-')
		return false;
	for( i = 0; i < val.length; i++){  
	c    =    val.charAt(i);
	if(Letters.indexOf(c)<0)
		return false;
	}
	if(val.length<6){
		return false;
	}
	return true;
}




//把最后一个","替换掉
function takeOutLastSymbol(val){
	var okval = val;
	if(val.substring(val.length-1,val.length)==","){
		okval = val.substring(0,val.length-1);
	}
	return okval;
}

//去掉字符串头尾空格 luzhonghua
function trim(str)
{
  var strReturn;
  strReturn = leftTrim(str);
  strReturn = rightTrim(strReturn);
  return strReturn;
}

//去掉字符串头空格  luzhonghua
function leftTrim(strValue)
{
  var re =/^\s*/;
  if(strValue==null)
    return null;

 strValue= "" + strValue;
  var strReturn = strValue.replace(re,"");

  return strReturn;
}

//去掉字符串尾空格  luzhonghua
function rightTrim(strValue)
{
  var re =/\s*$/;
  if(strValue==null)
    return null;

  var strReturn = strValue.replace(re,"");

  return strReturn;
}

//对输入域是否是整数的校验,即只包含字符0123456789  luzhonghua
function isInteger(strValue)
{
  var result = regExpTest(strValue,/\d+/);
  return result;
}

//对输入域是否是数字的校验  luzhonghua
function isNumeric(strValue)
{
  var result = regExpTest(strValue,/\d*[.]?\d*/);
  return result;
}

//RegExt Test  luzhonghua
function regExpTest(source,re)
{
  var result = false;

  if(source==null || source=="")
    return false;

  if(source==re.exec(source))
    result = true;

  return result;
}

//验证身份证号码
function checkIdcardT(xcardid){
  //var idcard=xcardid;
  if (xcardid.length!=15 && xcardid.length!=18){
        alert("身份证号长度应为15位或18位！");
        return false;
    }
}

//动态修改IFRAME 的高度 frmid iframe ID  xheight想增加或减小的高度  正数是加 负数是减  minheight iframe 最低高度
function changeHeightIframe(frmid,xheight,minheight){
	var xminheight = parseInt(minheight);
	var frmObj = document.getElementById(frmid);
   if(parseInt(xheight)>0)
			frmObj.height = parseInt(frmObj.height) + parseInt(xheight);

	if(parseInt(frmObj.height)>xminheight && parseInt(xheight)<0){
			frmObj.height = parseInt(frmObj.height) - parseInt((xheight+"").replace("-",""));
	}
}

//去两位小数
function round(number, digit) { 
    var multiple  = 1; 
    for( var i = 0; i < digit; i++ ) 
    { 
        multiple  *= 10; 
    } 
    return parseInt(number * multiple  + 0.5) / multiple; 
} 

//通过ID取名称
function getNameById(objList,id,text_id){
	for(var i=0;i<objList.length;i++){
		if(parseInt(objList[i][0])==parseInt(id)){
			if(text_id!=null)
				return objList[i][text_id];
			else
				return objList[i][1];
		}
	}
	return "";
}





//js 数据字典部份
document.writeln("<script type='text/javascript'src='/commonjs/initDictionary.js'></script>");

//取城市名字
function CARISgetXcityName(id){
	return getNameById(CARISxcity,id);
}

//取服务方式
function CARISgetXservicMode(id){
	return getNameById(CARISxservicemode,id);
}

//取支付方式
function CARISgetXpayMode(id){
	return getNameById(CARISxpaymode,id);
}
   
//取支付方式
function CARISgetVehicleClassForModelrentauto(id){ 
	return getNameById(CARISvehicleClassForModelrentauto,id);
}

//预订单处理结果
function CARISgetXdispose(id){
	return getNameById(CARISxdispose,id);
}

//预订单处理结果 
function CARISgetXclient(id){
	return getNameById(CARISxclient,id);
}

//取汽车颜色
function CARISgetXcarColor(id){
	return getNameById(CARISxcarcolor,id);
}

//取汽车状态
function CARISgetXcarStatus(id){
	return getNameById(CARISvehiclexstatus,id);
}

//取合同状态
function CARISgetXbargainStatus(id){
	return getNameById(CARISbargainstatus,id);
}

//取合同结算方式
function CARISgetXpayStates(id){
	return getNameById(CARISpaystates,id);
}


//取合同结算状态
function CARISgetXpayStatus(id){
	return getNameById(CARISpaystatus,id);
}

//取银行名称
function CARISgetXbandks(id){
	return getNameById(CARISbandks,id);
}

//取调度单状态
function CARISgetAttemperStatus(id)
{
	return getNameById(CARISAttemper,id);
 }

//取会员级别
function CARIgetSmemberlevel(id){
	return getNameById(CARISmemberlevel,id);
}

//取合作单位
function CARISgetcooperatecompany(id){
	return getNameById(CARIScooperatecompany,id);
}

//取国航卡名称
function CARISgetCAcard(id){
	return getNameById(CARISCAcard,id);
}

//取国航卡名称
function CARISgetRJcard(id){
	return getNameById(CARISRJcard,id);
}

//取上航卡名称
function CARISgetSAcard(id){  
	return getNameById(CARISSAcard,id);
}

//取人寿名称
function CARISgetRScard(id){  
	return getNameById(CARISRScard,id);
}


//取上航卡名称
function CARISgetHUcard(id){  
	return getNameById(CARISHUcard,id);
}

//取车范围
function CARISgetgivecarAddress(id){  
	return getNameById(CARISgivecarAddress,id);
}


//会员卡级别
function CARIgetScardnolevel(id){
	return getNameById(CARIScardnolevel,id);
}

//会员民族    
function CARIgetSnation(id){
	return getNameById(CARISnation,id);
}
  

//通用两级联方法核心代码  2007-10-13 added by Jack
function SelectWithTwolevel(json_Obj){
	var Obj1,Obj2;
	var tempDate = new Array();
	tempDate[0]=["",json_Obj.isDisplayText];//初始始数内容
	XisQueryForm=json_Obj.isDisplayAll;//是否显示所有 全局变量见 sys_form.js
	Obj1 = document.getElementById(json_Obj.selectFieldObj1);
	Obj2 = document.getElementById(json_Obj.selectFieldObj2);
	
	//启动实列
	this.setup = function(){
		callServer(json_Obj.path1,json_Obj.method1,json_Obj.where1,buffer0);
	}

	//ONGET 列表，如果增加新的二级联菜单，这里是要新加方法的;
	//*****************************************************************************	
	on_dictionary_getVehiclecompanys = function(){
		return on_getAll1();
	}
	on_dictionary_getVehiclemodes = function(){
		return on_getAll2();
	}

	

	//*****************************************************************************

	
	//第一个SELECT框 取 BUFF 信息的回调方法
	on_getAll1 = function(){

		if(eval(json_Obj.buff1)!=""){
			XbindControlWithDictionary(Obj1,eval(json_Obj.buff1));
			XbindControlWithDictionary(Obj2,tempDate);

			//只做了简单的浏览器判断 在IE和FF测试通过
			if(navigator.appName=="Netscape"){
				Obj1.addEventListener("change", changeSelectObj, false);
			}else{
				Obj1.attachEvent("onchange",changeSelectObj);
			}


			//初始化数值
			if(json_Obj.selectFieldValue1!=""){
					for(var i=0;i<Obj1.options.length;i++){
						if(Obj1.options[i].value==json_Obj.selectFieldValue1){
							Obj1.value=json_Obj.selectFieldValue1;
							return changeSelectObj();
						}
					}

			}


		}else{
			alert("数据不存在!");
		}
	}

	//修改第一个SELECT框触发的方法
	changeSelectObj = function(){
		//alert('方法已触发')
		callServer(json_Obj.path2,json_Obj.method2,"&where=" + json_Obj.where2Linkedwhere1column + "=" + getObj1Value()  + "&orderby=xid",buffer0);

	}

	//取第一个SELECT框的值
	getObj1Value = function(){
		var objvalue = "";
		if(Obj1.value == "" ){
			objvalue="-1"
		}else{
			objvalue=Obj1.value
		}
		return objvalue;
	}

	//第二个SELECT框 取 BUFF 信息的回调方法
	on_getAll2 = function(){
		Obj2.options.length=0;
		XbindControlWithDictionary(Obj2,eval(json_Obj.buff2));
		
		//初始化数值
		if(json_Obj.selectFieldValue2!=""){
				for(var i=0;i<Obj2.options.length;i++){
					if(Obj2.options[i].value==json_Obj.selectFieldValue2){
						Obj2.value=json_Obj.selectFieldValue2;
					}
				}
				
		}

	}
	
}



//通用三级联方法核心代码  2007-10-17 added by Jack
function SelectWithThreelevel(json_Obj){
	var Obj1,Obj2,Obj3;
	var tempDate = new Array();
	tempDate[0]=["","-----"];//初始始数内容
	XisQueryForm=json_Obj.isDisplayAll;//是否显示所有 全局变量见 sys_form.js
	Obj1 = document.getElementById(json_Obj.selectFieldObj1);
	Obj2 = document.getElementById(json_Obj.selectFieldObj2);
	Obj3 = document.getElementById(json_Obj.selectFieldObj3);
	
	//启动实列
	this.setup = function(){
		callServer(json_Obj.path1,json_Obj.method1,json_Obj.where1,buffer0);
	}

	//ONGET 列表，如果增加新的三级联菜单，这里是要新加方法的;
	//*****************************************************************************	
	on_dictionary_getVehicleclasss = function(){
		return on_getAll1();
	}

	on_dictionary_getVehiclecompanys = function(){
		return on_getAll2();
	}

	on_dictionary_getVehiclemodes = function(){
		return  on_getAll3();
	}

	//*****************************************************************************

	//修改第一个SELECT框触发的方法
	changeSelectObjOneToTwo = function(){
		callServer(json_Obj.path2,json_Obj.method2,"&where=" + json_Obj.where2Linkedwhere1column + "=" + getObj1Value1()  + "&orderby=xid",buffer0);
		Obj3.options.length=0;
		XbindControlWithDictionary(Obj3,tempDate);
	}
	//修改第二个SELECT框触发的方法
	changeSelectObjTwoToThree = function(){
		callServer(json_Obj.path3,json_Obj.method3,"&where=" + json_Obj.where3Linkedwhere2column + "=" + getObj1Value2()  + "&orderby=xid",buffer0);
	}


	//取第一个SELECT框的值
	getObj1Value1 = function(){
		var objvalue = "";
		if(Obj1.value == "" ){
			objvalue="-1"
		}else{
			objvalue=Obj1.value
		}
		return objvalue;
	}
	//取第二个SELECT框的值
	getObj1Value2 = function(){
		var objvalue = "";
		if(Obj1.value == "" ){
			objvalue="-1"
		}else{
			objvalue=Obj2.value
		}
		return objvalue;
	}
	
	//第一个SELECT框 取 BUFF 信息的回调方法
	on_getAll1 = function(){
		if(eval(json_Obj.buff1)!=""){
			XbindControlWithDictionary(Obj1,eval(json_Obj.buff1));
			//只做了简单的浏览器判断 在IE和FF测试通过
			if(navigator.appName=="Netscape"){
				Obj1.addEventListener("change", changeSelectObjOneToTwo, false);
			}else{
				Obj1.attachEvent("onchange",changeSelectObjOneToTwo);
			}

			//初始化数值
			if(json_Obj.selectFieldValue1!=""){
					for(var i=0;i<Obj1.options.length;i++){
						if(Obj1.options[i].value==json_Obj.selectFieldValue1){
							Obj1.value=json_Obj.selectFieldValue1;
							return changeSelectObjOneToTwo();
						}
					}
			}
		}else{
			alert("数据不存在!");
		}
	}
	//第二个SELECT框 取 BUFF 信息的回调方法
	on_getAll2 = function(){
		Obj2.options.length=0;
		XbindControlWithDictionary(Obj2,eval(json_Obj.buff2));
		if(json_Obj.selectFieldValue2!=""){
				for(var i=0;i<Obj2.options.length;i++){
					if(Obj2.options[i].value==json_Obj.selectFieldValue2){
						Obj2.value=json_Obj.selectFieldValue2;
						return changeSelectObjTwoToThree();
					}
				}
		}
		//只做了简单的浏览器判断 在IE和FF测试通过
		if(navigator.appName=="Netscape"){
			Obj2.addEventListener("change", changeSelectObjTwoToThree, false);
		}else{
			Obj2.attachEvent("onchange",changeSelectObjTwoToThree);
		}
	}


	//第三个SELECT框 取 BUFF 信息的回调方法
	on_getAll3 = function(){
		Obj3.options.length=0;
		XbindControlWithDictionary(Obj3,eval(json_Obj.buff3));
		if(json_Obj.selectFieldValue3!=""){
				for(var i=0;i<Obj3.options.length;i++){
					if(Obj3.options[i].value==json_Obj.selectFieldValue3){
						Obj3.value=json_Obj.selectFieldValue3;
					}
				}
		}

	}

}


//日期转成字符串 
function setDateToString(val){
	return  val.substring(0,16).replace(/-/g,"").replace(/ /g,"").replace(/:/g,"");
}

//把日期取前16位
function FormatDateSingle16(val){
	return val.substring(0,16);
}

//把日期取前10位
function FormatDateSingle10(val){
	return val.substring(0,10);
}
//计算天数差的函数 add by luzhonghua
  function DateDiff(sDate1, sDate2){  //sDate1和sDate2是2002-12-18格式

    var aDate, oDate1, oDate2, iDays;
    aDate = sDate1.split("-");
    oDate1 = new Date(aDate[1] + '-' + aDate[2] + '-' + aDate[0]);  //转换为12-18-2002格式
    aDate = sDate2.split("-");
    oDate2 = new Date(aDate[1] + '-' + aDate[2] + '-' + aDate[0]);
    //alert(oDate1 - oDate2);
    iDays = parseInt(Math.abs(oDate1 - oDate2) / 1000 / 60 / 60 /24/365);  //把相差的毫秒数转换为天/年数
    //alert(iDays);
    return iDays;
  } 

//日期与天数相加后的日期  getYear() getMonth() getDate() getHours() getMinutes() getSeconds() 
function daysTime2(_date,day)
{
    var tmpArray = _date.split(" ");
	var YearMonthDate = tmpArray[0].split("-");
	var HourMinSec = tmpArray[1].split(":");

    var now = new Date(YearMonthDate[0],YearMonthDate[1]-1,YearMonthDate[2],HourMinSec[0],HourMinSec[1]);  //
	var milliseconds = day*1000*60*60*24;
	var testdate = milliseconds + now.getTime(); 
	var testDate = new Date();
	testDate.setTime(testdate);
    return testDate.getYear()+ "-" + (testDate.getMonth()+1) + "-" + testDate.getDate() + " " + testDate.getHours() + ":" + testDate.getMinutes();
}
function daysTime3(_date,day)
{
    var tmpArray = _date.split(" ");
	var YearMonthDate = tmpArray[0].split("-");
	var HourMinSec = tmpArray[1].split(":");

    var now = new Date(YearMonthDate[0],YearMonthDate[1]-1,YearMonthDate[2],HourMinSec[0]);  //
	var milliseconds = day*1000*60*60*24;
	var testdate = milliseconds + now.getTime(); 
	var testDate = new Date();
	testDate.setTime(testdate);
    return testDate.getYear()+ "-" + (testDate.getMonth()+1) + "-" + testDate.getDate() + " " + testDate.getHours();
}

//日期与小时相加后的日期 
function hoursTime2(_date,hours)
{
	var tmpArray = _date.split(" ");
	var YearMonthDate = tmpArray[0].split("-");
	var HourMinSec = tmpArray[1].split(":");
    var now = new Date(YearMonthDate[0],YearMonthDate[1]-1,YearMonthDate[2],HourMinSec[0]);  //
	var milliseconds = hours*1000*60*60;
	var testdate = milliseconds + now.getTime(); 
	var testDate = new Date();
	testDate.setTime(testdate);
	//return testDate;
    return testDate.getYear()+ "-" + (testDate.getMonth()+1) + "-" + testDate.getDate() + " " + testDate.getHours();
}
function hoursTime3(_date,hours)
{

	var tmpArray = _date.split(" ");
	var YearMonthDate = tmpArray[0].split("-");
	var HourMinSec = tmpArray[1].split(":");
	

	
    var now = new Date(YearMonthDate[0],YearMonthDate[1]-1,YearMonthDate[2],HourMinSec[0]);  //

	var milliseconds = hours*1000*60*60;

	var testdate = milliseconds + now.getTime(); 
	
	var testDate = new Date();
	testDate.setTime(testdate);
	//return testDate;
	
    return testDate.getYear()+ "-" + (testDate.getMonth()+1) + "-" + testDate.getDate() + " " + testDate.getHours();
}
  
//处理传入时间为24的时间
function hoursTime4(_date)
{
 
	var tmpArray = _date.split(" ");
	var YearMonthDate = tmpArray[0].split("-");
	var HourMinSec = tmpArray[1].split(":");
	
    var now = new Date(YearMonthDate[0],YearMonthDate[1]-1,YearMonthDate[2],HourMinSec[0]);  //


	var testdate = now.getTime(); 
	
	var testDate = new Date();
	testDate.setTime(testdate);
	//return testDate;


	
    return testDate.getYear()+ "-" + (testDate.getMonth()+1) + "-" + testDate.getDate() + " " + testDate.getHours();
}


//判断两个日期大少
function compareTime(leasetime,returntime){ 
	var tmpArray1 = leasetime.split(" ");
	var tmpArray2 = returntime.split(" ");
	if(tmpArray1.length<2 || tmpArray2.length<2){
		var YearMonthDate1 = tmpArray1[0].split("-");
		var now1 = new Date(YearMonthDate1[0],YearMonthDate1[1]-1,YearMonthDate1[2]);
				 
		var YearMonthDate2 = tmpArray2[0].split("-");
		var now2 = new Date(YearMonthDate2[0],YearMonthDate2[1]-1,YearMonthDate2[2]); 	
			
		if(now1<now2){
			return false;
		}else{
			return true;
		}
	}else{
		var YearMonthDate1 = tmpArray1[0].split("-");
		var HourMinSec1 = tmpArray1[1].split(":");
		var now1 = new Date(YearMonthDate1[0],YearMonthDate1[1]-1,YearMonthDate1[2],HourMinSec1[0],HourMinSec1[1]); 
		 
		var YearMonthDate2 = tmpArray2[0].split("-");
		var HourMinSec2 = tmpArray2[1].split(":");
		var now2 = new Date(YearMonthDate2[0],YearMonthDate2[1]-1,YearMonthDate2[2],HourMinSec2[0],HourMinSec2[1]); 
		
		if(now1<now2){
			return false;
		}else{
			return true;
		}
	}
}


//调用身份验证页面
function call_identitycard_validate(xname,xidentitycard)
{
		//再验证一次
		   window.open("/CARAdmin/member/identitycard_validate.html?xname="+xname+"&xidentitycard="+xidentitycard,"","height=600, width=800, top=20, left=20,,status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes");
}

  
  
  