﻿function changeBG(ctrlName,className)
{
    var ctrl = document.getElementById(ctrlName);
    ctrl.className = className;
}

function changeDisplay(ctrlName,isDisplay)
{
    var ctrl = document.getElementById(ctrlName);
    if(isDisplay == true)
        ctrl.style.display = "";
    else
        ctrl.style.display = "none";
}

function hideOrShow(ctrlName)
{
    var ctrl = document.getElementById(ctrlName);
    if(ctrl.style.display != "none")
        ctrl.style.display = "none";
    else
        ctrl.style.display = "";
}

function changeEnabled(ctrlName, IsEnabled)
{
	var ctrl = document.getElementById(ctrlName);
	if(IsEnabled == true)ctrl.disabled = false;
	else ctrl.disabled = true;
}

function changeReadonly(ctrlName, IsReadonly)
{
	var ctrl = document.getElementById(ctrlName);
	if(IsReadonly == false) ctrl.Readonly = "";
	else ctrl.Readonly = "Readonly";
}

function setCtrlValue(ctrlName,setValue)
{
    var ctrl = document.getElementById(ctrlName);
    ctrl.Value = setValue;
    ctrl.value = setValue;
}

function keyDownSummit(buttonName,event)
{
    var keyNum = window.event ? event.keyCode :event.which;           //兼容IE与FireFox。keyCode是IE的，which是FireFox的
    if(keyNum == 13)
    {
//        event.which = 9;
        event.returnValue = false;
        var btn = document.getElementById(buttonName);
        btn.focus();
        btn.click();
    }
}

function setFocus(ctrlName)
{
    var ctrl = document.getElementById(ctrlName);
    ctrl.focus();
}

function PopCalendar(obj)
{
	showx = event.screenX - event.offsetX - 4 - 10 ; // + deltaX;
	showy = event.screenY - event.offsetY -168; // + deltaY;
	newWINwidth = 210 + 4 + 18;
	var e = document.getElementById(obj);
 	window.showModalDialog("/CSIIS_Client/JS/calendar.htm",e,"dialogWidth:206px; dialogHeight:230px; dialogLeft:"+showx+"px; dialogTop:"+showy+"px; status:no; directories:yes;scrollbars:no;Resizable=no; ");    
}

function DrawImage(ImgD, requireWidth, requireHeight)
{
	var image=new Image();
	var iwidth = requireWidth; //定义允许图片宽度
	var iheight = requireHeight; //定义允许图片高度
	var Img = document.getElementById(ImgD);
	image.src=Img.src;
	if(image.width>0 && image.height>0)
	{
		flag=true;
		if(image.width/image.height>= iwidth/iheight)
		{
			if(image.width>iwidth)
			{ 
				ImgD.width=iwidth;
				ImgD.height=(image.height*iwidth)/image.width;
			}
			else
			{
				ImgD.width=image.width; 
				ImgD.height=image.height;
			}
			ImgD.alt=image.width+"×"+image.height;
		}
		else
		{
			if(image.height>iheight)
			{ 
				ImgD.height=iheight;
				ImgD.width=(image.width*iheight)/image.height; 
			}
			else
			{
				ImgD.width=image.width; 
				ImgD.height=image.height;
			}
			ImgD.alt=image.width+"×"+image.height;
		}
	}
} 

function submitWithValidation(validationGroup, submitName, submitMessageCtrl)
{
	if(Page_ClientValidate(validationGroup))
	{
		changeDisplay(submitName,false);
		changeDisplay(submitMessageCtrl,true);
	}
}

function submitWithNoValidation(submitName, submitMessageCtrl)
{
	changeDisplay(submitName,false);
	changeDisplay(submitMessageCtrl,true);
}