var weekArr = new Array()
	weekArr[0] = "日";
	weekArr[1] = "一";
	weekArr[2] = "二";
	weekArr[3] = "三";
	weekArr[4] = "四";
	weekArr[5] = "五";
	weekArr[6] = "六";
	
// get the curretn date for the format the user input
// example : format: mm-dd-yyyy  :  return : the current date
function getCurrentDate (format)
{
   var date = new Date();  // Get the current date and time
   var defaultValue ="";

   var day   = formateCharacter(date.getDate(),2);
   var month = formateCharacter(date.getMonth()+1,2); 
   var year  = date.getYear();
   var week  = "  星期"+weekArr[date.getDay()];
   defaultValue = format+week;
   defaultValue = defaultValue.replace('dd',day);
   defaultValue = defaultValue.replace('mm',month);
   defaultValue = defaultValue.replace('yyyy',year);   
   
   return defaultValue;
}

// formate the str. get the required length 
// example : str= 2 and length  =3 . return : 002
function formateCharacter(str,length)
{
   str +="";
   while (str.length <length)
   {
      str ="0" + str;
   }
   return str;
}


//disable all the tags
var d = document.all
function disableAll() 
{
	var controlName = new Array("a","table","tr","td","img","body","select","input","textarea");	
	var tags = d.tags;
	for(var j=0 ; j<controlName.length ; j++) 
	{
		for(var i=0 ; i<tags(controlName[j]).length ; i++) 
		{
			tags(controlName[j])[i].onclick="";
			tags(controlName[j])[i].onmouseover="";
			tags(controlName[j])[i].onmouseout="";
			tags(controlName[j])[i].ondblclick="";
			tags(controlName[j])[i].onchange="";
			tags(controlName[j])[i].style.cursor="wait";
			
			if(      controlName[j]=="a") 
			{
				tags(controlName[j])[i].href="#";						
			} 
			else if( controlName[j]=="select") 
			{
				tags(controlName[j])[i].disabled=true;					
			} 
			else if( controlName[j]=="input") 
			{						
				tags(controlName[j])[i].disabled=true;						
			} 
			else if( controlName[j]=="textarea") 
			{						
				tags(controlName[j])[i].disabled=true;						
			}
			else if( controlName[j]=="img") 
			{						
				tags(controlName[j])[i].style.filter="alpha(opacity=50)";					
			}		
		}
	}
	document.body.disabled=true;
	document.body.style.cursor="wait";	
}

function mandataryfield(name,desc){
	this.fieldName = name;
	this.fieldDesc = desc;
}

/*
check if the input is empty
*/
function mandataryCheck(mandataryChkArr) {
	if (mandataryChkArr == null || mandataryChkArr.length == 0) {
		return true;
	}
	
	for (var i=0 ; i<mandataryChkArr.length ; i++) {
		var elementName = mandataryChkArr[i].fieldName;
		if (isNull(getValue(elementName))) {
			alert('请输入' + mandataryChkArr[i].fieldDesc);
			setSelected(elementName);
			return false;
		}
	}	
	return true;	
}

function getValue(fieldName) {
	return document.all[fieldName].value;
}

/*
if the string is empty
*/
function isNull(value) {
	if (trim(value).length == 0) {
		return true;	
	} else {
		return false;
	} 
}

function trim(strText) { 
    if (strText.length == 0) return strText;
    
    // this will get rid of leading spaces 
    while (strText.substring(0,1) == ' ') 
        strText = strText.substring(1, strText.length);
	
	if (strText.length == 0) return strText;
	
    // this will get rid of trailing spaces 
    while (strText.substring(strText.length-1,strText.length) == ' ')
        strText = strText.substring(0, strText.length-1);

   return strText;
} 

function setSelected(fieldName) {	
	try {
		document.all[fieldName].select();
	} catch (e) {	
	}
	document.all[fieldName].focus();
} 

/* To highlight selected row */
function highlightRow(elementID) {
	document.all[elementID].style.backgroundColor = 'b9e3f8';
}

/* To set the original color of the selected row */
function setRowColor(elementID,color) {
	document.all[elementID].style.backgroundColor = color;
}



function openWin(fileName, width, height,winHandler,winName){
	var x = (screen.availWidth - width) / 2;
	var y = (screen.availHeight - height) / 2;
	
	if(winHandler != null)
		winHandler.close();	
	if (winName != null)
		winHandler = window.open(fileName,winName,"HEIGHT="+height+",WIDTH="+width+",LEFT="+x+",TOP="+y);
	else
		winHandler = window.open(fileName,"detail","HEIGHT="+height+",WIDTH="+width+",LEFT="+x+",TOP="+y);
	winHandler.focus();
	return winHandler;
}


function closeWin(){
	self.close();
}

//Check whether the data is valid number
// It will allow : 123456789
function setDefaultValue(field,defaultValue)
{
    if(isNull(field.value) && defaultValue != null)   // default value
    {
      field.value = defaultValue;
      return;
    }
}




//It will get all checked records id
function getCheckedRecords(){
	var records = new Array(0);
	
	var tags = document.all.tags;
	for(var j=0; j<tags("input").length;j++)
	{
	 if(tags("input")[j].type=="checkbox")
	 {
	    if(tags("input")[j].checked)
	      records[records.length] = tags("input")[j].id;
	 }
	}
	return records;
}


function changeImg(id,img){
	document.all[id].src=img;
}

function changeBg(id,img){
		document.all[id].background=img;
}

function clickBg(ids,id,img,img_se){
	for(var i =0 ; i< ids.length; i++){
		document.all[ids[i]].background = img;
	}
	
	document.all[id].background = img_se;
}







 

	





