function OpenNewWin(strURL,winName){
 window.open(strURL,"newWin"+winName,"channelmode=no,directories=no,fullscreen=no,location=no,menubar=no,resizable=yes,scrollbars=yes,status=yes,toolbar=no");

}

function OpenNewWinSmall(strURL,winName){
 window.open(strURL,"newWin"+winName,"channelmode=no,directories=no,fullscreen=no,location=no,menubar=no,resizable=yes,scrollbars=yes,status=yes,toolbar=no,width=450,height=450");

}

function OpenNewWinVerySmall(strURL,winName){
window.open(strURL,"newWin"+winName,"channelmode=no,directories=no,fullscreen=no,location=no,menubar=no,resizable=no,scrollbars=no,status=yes,toolbar=no,width=300,height=300");
}

function Openloginwin(strURL,winName){
window.open(strURL,"newWin"+winName,"channelmode=no,directories=no,fullscreen=no,location=no,menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no,width=350,height=220");
}

function OpenPrintCardWin(strURL,winName){
window.open(strURL,"newWin"+winName,"channelmode=no,directories=no,fullscreen=no,location=no,menubar=yes,resizable=no,scrollbars=no,status=no,toolbar=no,width=300,height=150");
}

function OpenNewWinQyrygl(strURL,winName){
 window.open(strURL,"newWin"+winName,"channelmode=no,directories=no,fullscreen=no,location=no,menubar=no,resizable=yes,scrollbars=yes,status=yes,toolbar=no,height=300");

}

function parseCookie(){
  var j;
  cookieList=document.cookie.split(";");
       var cookieArray=new Array();
  for(var i=0;i<cookieList.length;i++){
    cookieList[i]=strTrim(cookieList[i]);
    j=cookieList[i].indexOf("=");
    
    cookieArray[cookieList[i].substring(0,j)]=cookieList[i].substring(j+1,cookieList[i].length);
  }
  return cookieArray;
}

function OpenNewWinWithMenu(strURL,winName){
 window.open(strURL,"newWin"+winName,"channelmode=no,directories=no,fullscreen=no,location=no,menubar=yes,resizable=yes,scrollbars=yes,status=yes,toolbar=no");

}

function strTrim(instr){
  instr+="|";
  var j=instr.length-1;
  var result_str="";
  for(var i=0;i<j;i++)
    if(instr.charAt(i)!=" ") result_str+=instr.charAt(i);
  return result_str;
} //strTrim()

function isEmpty(str){
  if((str+"|"=="null|")||(str+"|"=="undefined|")) return true;
  for(var i=0;i<str.length;i++)
    if(" "!=str.charAt(i)) return false;
  return true;
}  //isEmpty()

function valid_date(elem){
  var daysInMonth=new Array(31,28,31,30,31,30,31,31,30,31,30,31);
  var index;
  var buffer="";
  var ch;
  var flag=0;

  var instr=strTrim(elem.value);
  if(instr.length==0) return;
  for(index=0;index<instr.length;index++)
  {
    ch=instr.charAt(index);
    if(('0'<=ch)&&(ch<='9')) buffer+=ch;
    else if(flag<2){buffer+="/"; flag++;}
    else{elem.value="1900/01/01"; alert("有效日期格式:yyyy/mm/dd。"); elem.focus();return;}
  }
  if(flag!=2){elem.value="1900/01/01"; alert("有效日期格式:yyyy/mm/dd。"); elem.focus();return;}
  var date_array=buffer.split('/');
  if((date_array[0].length!=2)&&(date_array[0].length!=4)){elem.value="1900/01/01"; alert("无效年份。"); elem.focus();return;}
  if(date_array[1].length==0){elem.value="1900/01/01"; alert("无效月份。"); elem.focus();return;}
  if(date_array[2].length==0){elem.value="1900/01/01"; alert("无效日期。"); elem.focus();return;}
  if(date_array[0].length==2)
  {
    if(date_array[0].charAt(0)!='0') date_array[0]="19"+date_array[0];
    else date_array[0]="20"+date_array[0];
  }
  if(date_array[1].length==1) date_array[1]="0"+date_array[1];
  if(date_array[2].length==1) date_array[2]="0"+date_array[2];
  var year=parseInt(date_array[0],10);   //year
  var month=parseInt(date_array[1],10);  //month
  if((month<1)||(month>12)){elem.value="1900/01/01"; alert("无效月份。"); elem.focus();return;}
  var day=parseInt(date_array[2],10);  //day
  if(month==2)  //February
  {
    index=((0==year%4)&&(0!=(year%100)))||(0==year%400)?29:28;
    if((day<1)||(day>index)){elem.value="1900/01/01"; alert("无效日期。"); elem.focus();return;}
  }
  else
  {
    index=daysInMonth[month-1];
    if((day<1)||(day>index)){elem.value="1900/01/01"; alert("无效日期。"); elem.focus();return;}
  }
  elem.value=date_array[0]+"/"+date_array[1]+"/"+date_array[2];
}  //valid_date()

function stuff(instr,stf_dir,stf_char,stf_len){
  instr+="|";
  var j=stf_len-instr.length+1;
  var result_str;
  var stf_str="";
  for(var i=0;i<j;i++) stf_str+=stf_char;
  instr=instr.substring(0,instr.length-1);
  if(stf_dir=="head") result_str=stf_str+instr;
  else if(stf_dir=="tail") result_str=instr+stf_str;
  return result_str;
} //stuff()

function isDigit(str){
  var num="0123456789";

  for(var i=0;i<str.length;i++)
    if(-1 == num.indexOf(str.charAt(i))) return false;
  return true;
}  //isNumeric()

function strReplace(oldstr,pattern,str){
  var sResult=oldstr;
  while(sResult.indexOf(pattern)>0){
	sResult=sResult.replace(pattern,str);
  }
  
  return sResult;
}  //strReplace()

function strIndexOf(str,pattern,occurence){
  var i=0;
  var index=0;
 
  if(str.indexOf(pattern)==0) i++;
  if(i==occurence) return 0;
  while(index>=0 && index<str.length){
    if((index=str.indexOf(pattern,index+1))>=0) i++;
    else if(index==-1) return -1;
    if(i==occurence) return index;
    if(index==str.length) return -1;
  }
  
  return -1;
}  //strReplace()

function valid_figure(elem,minValue,maxValue){
  if(isEmpty(elem.value)){
    elem.value="00";
    return;
  }
  if(!isDigit(elem.value)||parseInt(elem.value,10)>maxValue||parseInt(elem.value,10)<minValue){
	elem.value="00"; 
	alert("有效数字范围"+minValue+"至"+maxValue+"。"); 
	elem.focus();
	return;
  }
}  //valid_figure

function openHelpWin(strURL,winName){
 screenWidth=screen.width;
 screenHeight=screen.height;
 winTop=0;
 winLeft=screenWidth-210;
 winHeight=screenHeight-200;
 window.open(strURL,"newWin"+winName,"channelmode=no,directories=no,fullscreen=no,location=no,menubar=no,resizable=no,scrollbars=yes,status=no,toolbar=no,left="+winLeft+",top="+winTop+",width=200,height="+winHeight);

}

function ConfirmDel(str){
 if(! window.confirm(str)){window.event.returnValue=false;return} 
}

function openCalendarWin(url,calendarDate)
{
var rtn=window.showModalDialog(url,calendarDate,"dialogHeight: 300px; dialogWidth: 308px;help: No;edge: Raised;resizable: No; status: No;");
return rtn;
}
