/*------以下是各个国家的省份或相应行政级别列表------*/
var ChinaProvinceList = global_Resource.ChinaProvinceList;
var AmericanProvinceList = global_Resource.AmericanProvinceList;
var CanadaProvinceList = global_Resource.CanadaProvinceList;
var ArgentinaProvinceList = global_Resource.ArgentinaProvinceList;
var AustraliaProvinceList = global_Resource.AustraliaProvinceList;
var WhiteRussiaProvinceList = global_Resource.WhiteRussiaProvinceList;
var BelgiumProvinceList = global_Resource.BelgiumProvinceList;
var DenmarkProvinceList = global_Resource.DenmarkProvinceList;
var FinlandProvinceList = global_Resource.FinlandProvinceList;
var FrenchProvinceList = global_Resource.FrenchProvinceList;
var GermanyProvinceList = global_Resource.GermanyProvinceList;
var GreeceProvinceList = global_Resource.GreeceProvinceList;
var HongkongProvinceList = global_Resource.HongkongProvinceList;
var HungaryProvinceList = global_Resource.HungaryProvinceList;
var IndiaProvinceList = global_Resource.IndiaProvinceList;
var IranProvinceList = global_Resource.IranProvinceList;
var IrelandProvinceList = global_Resource.IrelandProvinceList;
var ItalyProvinceList = global_Resource.ItalyProvinceList;
var JapanProvinceList = global_Resource.JapanProvinceList;
var KoreaProvinceList = global_Resource.KoreaProvinceList;
var MacaoProvinceList = global_Resource.MacaoProvinceList;
var MalaysiaProvinceList = global_Resource.MalaysiaProvinceList;
var MexicoProvinceList = global_Resource.MexicoProvinceList;
var HolandProvinceList = global_Resource.HolandProvinceList;
var NewZealandProvinceList = global_Resource.NewZealandProvinceList;
var NorwayProvinceList = global_Resource.NorwayProvinceList;
var PakistanProvinceList = global_Resource.PakistanProvinceList;
var ParaguayProvinceList = global_Resource.ParaguayProvinceList;
var PeruProvinceList = global_Resource.PeruProvinceList;
var FilipineProvinceList = global_Resource.FilipineProvinceList;
var PolandProvinceList = global_Resource.PolandProvinceList;
var PortugalProvinceList = global_Resource.PortugalProvinceList;
var RussiaProvinceList = global_Resource.RussiaProvinceList;
var SingaporeProvinceList = global_Resource.SingaporeProvinceList;
var SouthAfricaProvinceList = global_Resource.SouthAfricaProvinceList;
var SpainProvinceList = global_Resource.SpainProvinceList;
var SwedenProvinceList = global_Resource.SwedenProvinceList;
var SwitzerlandProvinceList = global_Resource.SwitzerlandProvinceList;
var TaiwanProvinceList = global_Resource.TaiwanProvinceList;
var ThailandProvinceList = global_Resource.ThailandProvinceList;
var EnglandProvinceList = global_Resource.EnglandProvinceList;
var otherProvinceList = global_Resource.otherProvinceList;
/*------以上是各个国家的省份或相应行政级别列表------*/

/*
 *当用户改变国家时，设置对应国家的省份或相应行政级别列表
 *@author fufei
 *@param 
 *      theForm:需要更新省份或相应行政级别列表的form表单
 *      homeOrWork:为"home"表示用户改变家庭地址中的国家，为"work"表示用户改变工作地址中的国家。
 */
function setProvince(theForm,homeOrWork,initProvince){
	var country;
	var province;
	var provinceList;
	if(homeOrWork=='home'){//如果是家庭地址
		country = theForm.hcountry;
		province = theForm.hprovince;
	}else if(homeOrWork=='work'){//如果是工作地址
		country = theForm.bcountry;
		province = theForm.bprovince;
	}
	switch(country.value){
		case global_Resource.China:   
				provinceList = ChinaProvinceList;
				break; 
		case global_Resource.USA:      
				provinceList = AmericanProvinceList;
				break;   
		case global_Resource.Canada:    
				provinceList = CanadaProvinceList;
				break;     
		case global_Resource.Argentina:    
				provinceList = ArgentinaProvinceList;
				break;  
		case global_Resource.Australia:  
				provinceList = AustraliaProvinceList;
				break;  
		case global_Resource.WhiteRussia:  
				provinceList = WhiteRussiaProvinceList;
				break;
		case global_Resource.Belgium:    
				provinceList = BelgiumProvinceList;
				break;    
		case global_Resource.Danmark:      
				provinceList = DenmarkProvinceList;
				break;    
		case global_Resource.Finland:      
				provinceList = FinlandProvinceList;
				break;    
		case global_Resource.France:      
				provinceList = FrenchProvinceList;
				break;     
		case global_Resource.German:      
				provinceList = GermanyProvinceList;
				break;    
		case global_Resource.Greece:      
				provinceList = GreeceProvinceList;
				break;     
		case global_Resource.Hongkong:  
				provinceList = HongkongProvinceList;
				break;   
		case global_Resource.Hungary:    
				provinceList = HungaryProvinceList;
				break;    
		case global_Resource.India:      
				provinceList = IndiaProvinceList;
				break;      
		case global_Resource.Iran:      
				provinceList = IranProvinceList;
				break;       
		case global_Resource.Ireland:    
				provinceList = IrelandProvinceList;
				break;    
		case global_Resource.Italy:    
				provinceList = ItalyProvinceList;
				break;      
		case global_Resource.Japan:      
				provinceList = JapanProvinceList;
				break;      
		case global_Resource.Korean:      
				provinceList = KoreaProvinceList;
				break;      
		case global_Resource.Macow:  
				provinceList = MacaoProvinceList;
				break;      
		case global_Resource.Malaysia:  
				provinceList = MalaysiaProvinceList;
				break;   
		case global_Resource.Mexico:    
				provinceList = MexicoProvinceList;
				break;     
		case global_Resource.Horland:      
				provinceList = HolandProvinceList;
				break;     
		case global_Resource.NewZealand:    
	
				provinceList = NewZealandProvinceList;
				break; 
		case global_Resource.Norway:      
				provinceList = NorwayProvinceList;
				break;     
		case global_Resource.Pakistan:  
				provinceList = PakistanProvinceList;
				break;   
		case global_Resource.Paraguay:    
				provinceList = ParaguayProvinceList;
				break;   
		case global_Resource.Peru:      
				provinceList = PeruProvinceList;
				break;       
		case global_Resource.Philippine:    
				provinceList = FilipineProvinceList;
				break;   
		case global_Resource.Porland:      
				provinceList = PolandProvinceList;
				break;     
		case global_Resource.Portugal:    
				provinceList = PortugalProvinceList;
				break;   
		case global_Resource.Russia:    
				provinceList = RussiaProvinceList;
				break;     
		case global_Resource.Singapore:    
				provinceList = SingaporeProvinceList;
				break;  
		case global_Resource.SouthAfrica:      
				provinceList = SouthAfricaProvinceList;
				break;
		case global_Resource.Spain:    
				provinceList = SpainProvinceList;
				break;      
		case global_Resource.Sweden:      
				provinceList = SwedenProvinceList;
				break;     
		case global_Resource.Switzerland:      
				provinceList = SwitzerlandProvinceList;
				break;
		case global_Resource.Thailand:      
				provinceList = ThailandProvinceList;
				break;   
		case global_Resource.English:      
				provinceList = EnglandProvinceList;
				break;
		case global_Resource.other:      
				provinceList = otherProvinceList;
				break;
		default:
				provinceList = otherProvinceList;
				break;
	}	
	
	//如果第三个参数有合法值
	if(initProvince!=null && initProvince.length>0){
		var flag_existence = false;//省份下拉列表框中是否存在指定的省份
		for(var i=0;i<provinceList.length;i++){
				if(provinceList[i]==trim(initProvince)){
						flag_existence = true;
						break;
				}
		}
		if(!flag_existence){
				//alert("old provinceList is:"+provinceList.join(';')+",initProvince is:"+initProvince);
				var temp = provinceList[provinceList.length-1];//最后一个item是"其他"。
				provinceList[provinceList.length-1] = trim(initProvince);
				provinceList[provinceList.length] = temp;
				//alert("new provinceList is:"+provinceList.join(';'));
		}
	}
	
	province.options.length = 0;//清空省份列表。
	//构造所选国家的省份列表
	for (i=0;i<provinceList.length;i++){
		var newOption = document.createElement("OPTION");
		newOption.text = provinceList[i];
		newOption.value = provinceList[i];
		province.options.add(newOption);
	}	
}

/*
 *当初次进入页面时初始化省份或相应行政级别列表
 *@author fufei
 *@param 
 *      theForm:需要更新省份或相应行政级别列表的form表单
 *      bprovince:工作地址中的省份.
 *      hprovince:家庭地址中的省份.
 */
function initProvince(theForm,bprovince,hprovince){
	setProvince(theForm,"work",bprovince);
	setProvince(theForm,"home",hprovince);
	setProvince(theForm,"work",bprovince);
	theForm.bprovince.value = bprovince;
	theForm.hprovince.value = hprovince;
}
//=================检验手机号==========================
function checkMobile(v)
{
  v= v+";";
  var reg = /^((([\w|\u4e00-\u9fa5]+),{0,1}([\w|\u4e00-\u9fa5]+):\s*)?13[0-9]{9};)+$/;
  var r =v.match(reg);
  if(r == null)
  {
     return false;
  }
  return true;
}
//=================检验emaild地址==========================
function checkEmail(v)
{
	v=trim(v);
	//var reg =/^\w+@\w+\..{2,3}$/;
	//var reg = /^\w +[@]\w +[.][\w.] +$/;
   var reg =/^\w+([-+.]\w+)*([-+.])*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
   //var reg =/^.+@.+\..{2,3}$/;
   var r =v.match(reg);
  	if(r == null)
  	{
    	return false;
  	}
  	return true;
  	

}

//////////////////////////////////////////////////////

function checkwholetime(time)
{
  var t = time.split(":");
  if(!checktimeValue(1,t[0]) || !checktimeValue(2,t[1]))
    return false;
  return true;
}
function checktimeValue(type,tt_mm)
{
	var hour;
	var minu;
 	if(type == 1)
 	{
          if(tt_mm=='0')
	  hour = 0;
	 else
	 {
      	if(isNaN(parseInt(tt_mm)))
	  {
       		return false;
	   }
	hour = parseInt(tt_mm);
    if(hour < 0 || hour > 23)
    {
     return false;
	 }
	}
	}
	else
	{
	if(tt_mm == '0')
	   minu = 0;
	else
	 {
	  if(isNaN(parseInt(tt_mm)))
     {
	  return false;
	  }
	 minu = parseInt(tt_mm);
	 if(minu < 0 || minu > 59)
	 {
     return false;
	 }
	 }
	}
	return true;
}
function checktime(type,tt_mm)
{
	var hour;
	var minu;
 	if(type == 1)
 	{
          if(tt_mm.value=='0')
	  hour = 0;
	 else
	 {
      	if(isNaN(parseInt(tt_mm.value)))
	  {
	 	alert(global_Resource.hournotnumber);
       		return false;
	   }
	hour = parseInt(tt_mm.value);
    if(hour < 0 || hour > 23)
    {
      alert(global_Resource.houroverrange);
     return false;
	 }
	}
	}
	else
	{
	if(tt_mm.value == '0')
	   minu = 0;
	else
	 {
	  if(isNaN(parseInt(tt_mm.value)))
     {
       alert(global_Resource.minutenotnumber);
	  return false;
	  }
	 minu = parseInt(tt_mm.value);
	 if(minu < 0 || minu > 59)
	 {
	  alert(global_Resource.minuteoverrange);
     return false;
	 }
	 }
	}
	return true;
}

﻿
function getDateFromStr(str)
{
  if(!checkSingleDate(str))
  {
    return null;
  }
  var reg = /^([1-2][0-9]{3})-([0,1]?[0-9])-([0-3]?[0-9])$/;
  var r = str.value.match(reg);
  r[2] = r[2] - 1;
  var d = new Date(r[1], r[2], r[3]);
  return d;
}

function checkDateValue(date)
{
  var reg = /^([1-2][0-9]{3})-([0,1]?[0-9])-([0-3]?[0-9])$/;
  var r = date.match(reg);
  if(r == null)
  {
    //alert("日期不合法！");
		return false;
  }
  r[2] = r[2] - 1;
  var d = new Date(r[1], r[2], r[3]);
  if(d == null)
  {
    //alert("日期不合法！ null");
		return false;
  }
	if(d.getDate() != r[3])
	{
		//alert("日期不合法！date"+ r[3]);
		return false;
	}
	if(d.getMonth() != r[2])
	{
		//alert("日期不合法！month" + d.getMonth()+" "+ d.getDate());
		return false;
	}

  return true;
}
//检查单个日期的合法性
function checkSingleDate(date)
{
  var reg = /^([1-2][0-9]{3})-([0,1]?[0-9])-([0-3]?[0-9])$/;
  var r = date.value.match(reg);
  if(r == null)
  {
    //alert("日期不合法！");
	return false;
  }
  r[2] = r[2]-1;
  var d = new Date(r[1], r[2], r[3]);
  if(d == null)
  {
    //alert("日期不合法！");
	return false;
  }
  if(d.getMonth() != r[2])
  {
    //alert("日期不合法！");
    if(d.getMonth() != r[2])
      return false;
  }
  if(d.getDate() != r[3])
  {
    alert(global_Resource.datefault+d);
	return false;
  }
  return true;
}
function checkdate(date1,date2)
{
  if(!checkSingleDate(date1) || ! checkSingleDate(date2))
  {
     //alert("输入的日期不合法！请检查");
     return false;
  }
  var d1 = getDateFromStr(date1);
  var d2 = getDateFromStr(date2);
  if (d2 < d1)
  {
     //alert("后一日期必须大于等于前一日期！");
     return false;
  }
  return true;
}

function checkdate(date1,date2,flag)
{
  if(!checkSingleDate(date1) || ! checkSingleDate(date2))
  {
     return false;
  }
  var d1 = getDateFromStr(date1);
  var d2 = getDateFromStr(date2);
  if (d2 < d1)
  {
     return false;
  }
  return true;
}


// ===================================== lib ===============================================

function trim ( str ) {
  if ( str == "" ) return "";
  var i = 0;
  while ( i < str.length && str.charAt ( i ) == ' ' ) i ++;
  str = str.substring ( i, str.length );
  if ( str == "" ) return "";
  i = str.length - 1;
  while ( i >= 0 && str.charAt ( i ) == ' ' ) i --;
  str = str.substring ( 0, i + 1 );
  return str;
}
var type_over_pwlModify = "#FFFFFF";
var type_out_pwlModify =  null;
var recd_over_pwlModify = "#CCCCCC";
var recd_clicked_pwlModify = "#CCCCCC";
var recd_out_pwlModify = null;
var previous_clicked_tr_pwlModify = null;
function recdchgbgByPWLmodify ( td, action ) {
	if ( action == 1 ) {                                       //    mouse over
		recd_out_pwlModify = td.bgColor;
		td.bgColor = recd_over_pwlModify;
		if(previous_clicked_tr!=null){
			//alert("previous_clicked_tr!=null and action=1");
			previous_clicked_tr_pwlModify.bgColor = recd_clicked_pwlModify;
		}
	}
	if ( action == 2 ) {                                       //    mouse out
		td.bgColor = recd_out_pwlModify;
		if(previous_clicked_tr_pwlModify!=null){
			//alert("previous_clicked_tr!=null and action=2");
			previous_clicked_tr_pwlModify.bgColor = recd_clicked_pwlModify;
		}
	}
}
// ===================================== change bg color on mouse ... ========================
var type_over = "#FFFFFF";
var type_out =  null;
var recd_over = "#DDDDFF";
var recd_clicked = "#DDDDFF";
var recd_out = null;
var previous_clicked_tr = null;
function typechgbg ( td, action ) {
	if ( action == 1 )  {                                         //  mouse over
		type_out = td.bgColor;
		td.bgColor = type_over;
	}
	if ( action == 2 )  { 								       //   mouse out
		td.bgColor = type_out;
	}
}
function recdchgbg ( td, action ) {
	if ( action == 1 ) {                                       //    mouse over
		recd_out = td.bgColor;
		td.bgColor = recd_over;
		if(previous_clicked_tr!=null){
			//alert("previous_clicked_tr!=null and action=1");
			previous_clicked_tr.bgColor = recd_clicked;
		}
	}
	if ( action == 2 ) {                                       //    mouse out
		td.bgColor = recd_out;
		if(previous_clicked_tr!=null){
			//alert("previous_clicked_tr!=null and action=2");
			previous_clicked_tr.bgColor = recd_clicked;
		}
	}
	if( action == 3) {               //left clicked		
		//alert("before previous_clicked_tr:"+previous_clicked_tr);
		if(previous_clicked_tr!=null){
			previous_clicked_tr.bgColor = recd_out;
		}
		td.bgColor = recd_clicked;
		previous_clicked_tr = td;
		//alert("previous_clicked_tr.bgColor:"+previous_clicked_tr.bgColor);
	}
}
function simaover ( sc ) {
  sc.style.color = "red";
//  sc.style.text.decoration = "underline";
}
function simaout ( sc ) {
  sc.style.color = "blue";
//  sc.style.decoration = "none";
}
// =============================== 保存当前选中的条目ID ========================================
var selectedEntryList = ",";
function chgSeledEntryList ( checkbox, id ) { 

	if ( checkbox.checked ) {
      		selectedEntryList += id + ",";
	} else {
      		var i = selectedEntryList.indexOf ( "," + id + ",", 0 );
      		if ( i >= 0 )  {
        		selectedEntryList = selectedEntryList.substring ( 0, i ) + selectedEntryList.substring ( i + id.length + 1, selectedEntryList.length );
      		}
	}
}
function openWindow(url, formName, features) {
		window.showModalDialog(contentRootUrl + url, formName, features); 	
		//openNormalWindow(url, formName, features)		
}



//==============================================================
function selectAll(form,selectType)
	{
	var userform = form;
	var id = userform.ids;
	var sel = true;
	if(id!=null){
			if(selectType == 0)
				sel = false;
			if(id.length == null||id.length<1)
			 {	
			 id.checked = sel;
			 }
			else{	
					for(var i = 0; i < id.length; i++)
					  {
						id[i].checked = sel;
					  } 
			  }
	  }
}

function chgSeldListOnSubmint ( form ) {
    selectedList=","; 
    var check=form.ids;
	if(check != null){
	if(check.length < 1 || check.length == null)
	{
	          if ( check.checked ) {
						selectedList += check.value + ",";
				} 
	}
	else{
			var isChecked = false;
			 for(var i=0;i<check.length;i++)
			 {
					if ( check[i].checked )
					{
					  isChecked = true;
					  selectedList += check[i].value + ",";
					}
			 }
	   }
	}   
	   return selectedList;
}


function dellist(listform,delform,delformSelIDList,type ) {
 var selectedList=","; 
 selectedList=chgSeldListOnSubmint ( listform ); 
  if(selectedList == ",") {
		alert(global_Resource.selectdelete+type);
		return ;
	}
	
  var form = delform;
  var d = window.confirm(global_Resource.ifdelete+type);
  if(d) {
	  if ( selectedList.length == 1 ) delformSelIDList.value = ",";
	  else delformSelIDList.value = selectedList.substring (1, selectedList.length - 1);
	  form.submit ();
  }
}

function editList(listform,delform,delformSelIDList,type,operation ) {
 var selectedList=","; 
 selectedList=chgSeldListOnSubmint ( listform ); 
  if(selectedList == ",") {
		alert(global_Resource.selectone+type);
		return ;
	}
	
  //delform.operation.value=operation;
  var form = delform;
  
	  if ( selectedList.length == 1 ) delformSelIDList.value = ",";
	  else delformSelIDList.value = selectedList.substring (1, selectedList.length - 1);
	  
	  var planId=0;
	  var sepstr = ",";
	  var i = delformSelIDList.value.indexOf ( sepstr );
	  //i=delformSelIDList.value.indexOf(',');
	  if(i<0)
	  {
		  planId=delformSelIDList.value;
  	  }
  	  else {
      	planId=delformSelIDList.value.substring ( 0, i );      	
  	  }
  	  if(operation=="editAgenda"){
  	  		var url = contentRootUrl + "schedule/schedule/delPlanDoAction.do?action=new&operation="+operation+"&planId="+planId;	
  	  		this.location.href = url; 
	  }else{
	  		var url = contentRootUrl + "schedule/schedule/delPlanDoAction.do?action=new&operation="+operation+"&planId="+planId;	
  	  		window.open(url,global_Resource.newplan, ' height=400, width=700, top=200,left=200, toolbar=no, menubar=no, scrollbars=yes, resizable=yes,location=no, status=no');
	  }
	  //form.submit ();
  
}

function EncodeUtf8(s1)
  {
      var s = escape(s1);
      var sa = s.split("%");
      var retV ="";
      if(sa[0] != "")
      {
         retV = sa[0];
      }
      for(var i = 1; i < sa.length; i ++)
      {
           if(sa[i].substring(0,1) == "u")
           {
               retV += Hex2Utf8(Str2Hex(sa[i].substring(1,5)));
               
           }
           else retV += "%" + sa[i];
      }
      
      return retV;
  }
  function Str2Hex(s)
  {
      var c = "";
      var n;
      var ss = "0123456789ABCDEF";
      var digS = "";
      for(var i = 0; i < s.length; i ++)
      {
         c = s.charAt(i);
         n = ss.indexOf(c);
         digS += Dec2Dig(eval(n));
           
      }
      //return value;
      return digS;
  }
  function Dec2Dig(n1)
  {
      var s = "";
      var n2 = 0;
      for(var i = 0; i < 4; i++)
      {
         n2 = Math.pow(2,3 - i);
         if(n1 >= n2)
         {
            s += '1';
            n1 = n1 - n2;
          }
         else
          s += '0';
          
      }
      return s;
      
  }
  function Dig2Dec(s)
  {
      var retV = 0;
      if(s.length == 4)
      {
          for(var i = 0; i < 4; i ++)
          {
              retV += eval(s.charAt(i)) * Math.pow(2, 3 - i);
          }
          return retV;
      }
      return -1;
  } 
  function Hex2Utf8(s)
  {
     var retS = "";
     var tempS = "";
     var ss = "";
     if(s.length == 16)
     {
         tempS = "1110" + s.substring(0, 4);
         tempS += "10" +  s.substring(4, 10); 
         tempS += "10" + s.substring(10,16); 
         var sss = "0123456789ABCDEF";
         for(var i = 0; i < 3; i ++)
         {
            retS += "%";
            ss = tempS.substring(i * 8, (eval(i)+1)*8);
            
            
            
            retS += sss.charAt(Dig2Dec(ss.substring(0,4)));
            retS += sss.charAt(Dig2Dec(ss.substring(4,8)));
         }
         return retS;
     }
     return "";
  } 
  
  
  function addSenToEventHandle(EHObj,insSen){
	var preSen;
	if (EHObj!=null){preSen=EHObj.toString();
		
		}else{preSen="";} 
		
	
	var reg=/^(function +[\w|\$|\.]+ *\([\w|\$|\,|\.]*\) *\{)([\W|\w]*)(\})$/;
	var preBody=preSen.replace(reg,"$2");
	
	var newFunObj=new Function(preBody+insSen);
	
	return newFunObj; 
} 


function image_onload(ImgD, nWidth, nHeight)

{

       var image=new Image(); 

       image.src=ImgD.src; 

       if(image.width>0 && image.height>0)

       { 

              flag=true; 

              if(image.width/image.height>= nWidth/nHeight)

              { 

                   if(image.width>nWidth)

                     {

                         ImgD.width=nWidth; 

                      ImgD.height=(image.height*nHeight)/image.width; 

   }else{ 

    ImgD.width=image.width;

    ImgD.height=image.height; 

   } 

   /*ImgD.alt="bigpic"  */

  } 

  else{ 

   if(image.height>nHeight){

    ImgD.height=nHeight; 

    ImgD.width=(image.width*nHeight)/image.height; 

   }else{ 

    ImgD.width=image.width;

    ImgD.height=image.height; 

   } 

    /*ImgD.alt="bigpic"  */ 

  } 

}

}



