﻿function getPageScroll()
{
    var yScroll;
    if (self.pageYOffset) 
    {
        yScroll = self.pageYOffset;
    } 
    else if (document.documentElement && document.documentElement.scrollTop)
    {   
        // Explorer 6 Strict
        yScroll = document.documentElement.scrollTop;
    } 
    else if (document.body) 
    {
        // all other Explorers
        yScroll = document.body.scrollTop;
    }
    arrayPageScroll = new Array('',yScroll) 
    return arrayPageScroll;
}

function getPageSize()
{  
    var xScroll, yScroll;  
    if (window.innerHeight && window.scrollMaxY) 
    {  
        xScroll = document.body.scrollWidth;
        yScroll = window.innerHeight + window.scrollMaxY;
    } 
    else if (document.body.scrollHeight > document.body.offsetHeight)
    { 
        // all but Explorer Mac
        xScroll = document.body.scrollWidth;
        yScroll = document.body.scrollHeight;
    } 
    else 
    { 
        // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
        xScroll = document.body.offsetWidth;
        yScroll = document.body.offsetHeight;
    }

    var windowWidth, windowHeight;
    if (self.innerHeight) 
    {
        // all except Explorer
        windowWidth = self.innerWidth;
        windowHeight = self.innerHeight;
    } 
    else if (document.documentElement && document.documentElement.clientHeight) 
    { 
        // Explorer 6 Strict Mode
        windowWidth = document.documentElement.clientWidth;
        windowHeight = document.documentElement.clientHeight;
    } 
    else if (document.body) 
    { 
        // other Explorers
        windowWidth = document.body.clientWidth;
        windowHeight = document.body.clientHeight;
    }  

    // for small pages with total height less then height of the viewport
    if(yScroll < windowHeight)
    {
        pageHeight = windowHeight;
    } 
    else 
    { 
        pageHeight = yScroll;
    }

    if(xScroll < windowWidth)
    {  
        pageWidth = windowWidth;
    } 
    else 
    {
        pageWidth = xScroll;
    }

    arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
    return arrayPageSize;
}


function pageResize()
{
    var obj = document.getElementById("ctl_MainTr");
    if (obj)
    {
        obj.style.height = getPageSize()[3] - 88;
    }
    var leftAdDiv = document.getElementById("LeftAdDiv");
    if (leftAdDiv)
    {
        leftAdDiv.style.top = getPageScroll()[1] + 50;
    }
    var rightAdDiv = document.getElementById("RightAdDiv");
    if (rightAdDiv)
    {
        rightAdDiv.style.top = getPageScroll()[1] + 50;
        rightAdDiv.style.left = document.body.scrollLeft + document.body.clientWidth-rightAdDiv.offsetWidth;
    }
}

/* Begin: Popup Window */
function PopWin(myurl,width,height) 
{
    var Height=window.screen.height;
    var Width=window.screen.width;
    var top,left;
    if (Height==600)
    {
       top="10px";
       left=(Width-parseInt(width))/2;
    }
    else
    {
      top=(Height-parseInt(height))/2;
      left=(Width-parseInt(width))/2;
    }
	newwin = window.open(myurl,"","width="+width+",height="+height+",top="+top+",left="+left+",scrollbars,resizable"); 
	
}
/* End: Popup Window */

function toggle(obj, img)
{
	var e = document.getElementById(obj);
	var i = document.getElementById(img);
	if(!e) return;
	if(e.style.display == "none")
	{
		e.style.display = "block";	
		if(i) i.src = "/CSClient/Images/Common/ItemExpand.gif";
	}
	else
	{
		e.style.display = "none";
		if(i) i.src = "/CSClient/Images/Common/ItemClose.gif";
	}	
}


 function OpenUrl(obj)
{//打开下拉列表项的站点

    if(obj.options[obj.selectedIndex].value!="")
    {
        window.open(obj.options[obj.selectedIndex].value);
    }
}
function selecttext(obj)
{//选择当前文本

    obj.value="";
}


function PopCalendar(obj)
{
    if (!obj) return;
    if (obj.disabled) return;
	showx = event.screenX - event.offsetX - 4 - 10 ; // + deltaX;
	showy = event.screenY - event.offsetY -168; // + deltaY;
	newWINwidth = 210 + 4 + 18;
	
	window.showModalDialog("/CSClient/Scripts/calendar.htm",obj,"dialogWidth:206px; dialogHeight:233px; dialogLeft:"+showx+"px; dialogTop:"+showy+"px; status:no; directories:yes;scrollbars:no;Resizable=no; ");    
}


//日期通用校验函数
function CheckDate(source,args)
{
	if(IsDate(args.Value)==false) args.IsValid = false;
}


//日期校验函数
function IsDate(DateString , Dilimeter) 
{
	if (DateString==null) return false;
	if (Dilimeter=='' || Dilimeter==null) Dilimeter = '-';
	var tempy='';
	var tempm='';
	var tempd='';
	var tempArray;
	if (DateString == "") return true;
	if (DateString.length<8 || DateString.length>10) return false;
	tempArray = DateString.split(Dilimeter);
	if (tempArray.length!=3) return false;
	if (tempArray[0].length==4) 
	{
		tempy = tempArray[0];
		tempd = tempArray[2];
	}
	else
	{
		tempy = tempArray[2];
		tempd = tempArray[1];
	} 
	tempm = tempArray[1];
	var tDateString = tempy + '/' + tempm + '/' + tempd + ' 8:0:0';
	
	if(tempm.substr(0,1) == '0') tempm=tempm.substr(1,1);
	if(tempd.substr(0,1) == '0') tempd=tempd.substr(1,1);				
	var tempDate = new Date(tDateString); 
	if (isNaN(tempDate))  return false;
	if (((tempDate.getUTCFullYear()).toString()==tempy)&&(tempDate.getMonth()==(parseInt(tempm)-1))&&((tempDate.getDate()).toString()==tempd))
	{
		return true;
	}
	else
	{
		return false;
	} 
}
