﻿//----------------------------//
//Common JavaScript Function  //
//----------------------------//
//-----------------------------------------------------------------

	function fn_SelectAll( theForm )
	{
		if ( theForm.SELECTALL.type == "checkbox" ){
			if (theForm.SELECTALL.checked){
				for ( i = 0 ; i < theForm.elements.length ; i ++ )
				{		
					if ( theForm.elements[i].type == "checkbox" && theForm.elements[i].name != "SELECTALL")
					{
						theForm.elements[i].checked = true ;	
					}			
				}				
			}else{
				for ( i = 0 ; i < theForm.elements.length ; i ++ )
				{		
					if ( theForm.elements[i].type == "checkbox" && theForm.elements[i].name != "SELECTALL")
					{
						theForm.elements[i].checked = false ;	
					}			
				}				
			}
		}
	}

//-----------------------------------------------------------------	

	function fn_SeletcCount( theForm )	
	{
		j=0;
		for ( i = 0 ; i < theForm.elements.length ; i ++ )
		{
			if ( theForm.elements[i].type == "checkbox" && theForm.elements[i].name != "SELECTALL")
			{
				if ( theForm.elements[i].checked )
				{
					j++;
				}
			}
		}
		return j;		
	}

//-----------------------------------------------------------------	

	function fn_GoToPage ( theForm , intNo )
	{
		theForm.target="";
		theForm.action="";
		theForm.method="post";
		theForm.Pages.value = intNo;
		theForm.submit() ;				
	}


//-----------------------------------------------------------------

	function isEmpty ( theValue , theValueName )
	{
		if ( theValue == "" )
		{
			if ( theValueName != null )
			{
				alert( "\"" + theValueName + "\"" + "必须填写！" );
			}
			return true;
		}
		return false;
	}


//-----------------------------------------------------------------

	function isNumber ( theValue )
	{
		strReg=/[^\d]/;
		if ( theValue.search( strReg ) != -1 )
		{
			alert("请填写数字！");
			return false;
		}
		return true;		
	}

//-----------------------------------------------------------------

	function isEmail ( theValue )
	{
		strReg=/\w+@\w+\.\w+/;
		if ( theValue.search( strReg ) == -1 )
		{
			alert("E-mail格式错误！");
			return false;
		}
		return true;		
	}

//-----------------------------------------------------------------

	function isZip ( theValue )
	{
		strReg = /\d{6}/
		if ( theValue.search( strReg ) == -1 )
		{
			alert("邮政编码格式错误！");
			return false;
		}
		return true;		
	}
//-----------------------------------------------------------------
/*	function imgResize(obj,maxwidth,maxheight)

	{

		if(parseFloat(obj.width)/obj.height>parseFloat(maxwidth)/maxheight)

		{

		if(obj.width>maxwidth)obj.width=maxwidth;

		}

		else

		{

		if(obj.height>maxheight)obj.height=maxheight;

		}

	}*/

//-----------------------------------------------------------------


	function fn_SetCurrentRowColor ( theRow , theColor )
	{
		var theRowLength = theRow.cells.length;
    	for (var i = 0; i < theRowLength; i++) 
        	theRow.cells[i].bgColor = theColor;
	}

//-----------------------------------------------------------------

	function isValidity ( theValue , theValidityValue )
	{
		var theFlag=true;
		if (theValidityValue.length==0) return true;
		for (i = 0;  i < theValue.length;  i++)
		{
			for (j = 0;  j < theValidityValue.length;  j++)
				if (theValue.charAt(i)==theValidityValue.charAt(j))
				{
					theFlag=true;
					break;
				}else
					theFlag=false;	
			if (!theFlag)
			{
				alert("含有非法字符！");
				return false;
			}
		}
		return true;
	}
//-----------------------------------------------------------------

	function isDateTime ( theValue )
	{
		var strReg=/^\d{2}(([02468][048]|[13579][26])-((0?[13578]|1[02])-(0?[1-9]|[1-2][0-9]|3[01])|(0?[469]|11)-(0?[1-9]|[1-2][0-9]|30)|0?2-(0?[1-9]|[1-2][0-9]))|([02468][1235679]|[13579][01345789])-((0?[13578]|1[02])-(0?[1-9]|[1-2][0-9]|3[01])|(0?[469]|11)-(0?[1-9]|[1-2][0-9]|30)|0?2-(0?[1-9]|1[0-9]|(2[0-8]))))(\s(0?[1-9]|1[0-9]|2[0-4]):(0?[1-9]|[1-5][0-9]):(0?[1-9]|[1-5][0-9]))?$/;
		
		if ( theValue.search( strReg ) == -1 )
		{
			alert("日期或时间格式错误！");
			return false;
		}
		return true;		

		
	}

//-----------------------------------------------------------------

	function isDate ( theValue )
	{
		var strReg=/^\d{2}(([02468][048]|[13579][26])-((0?[13578]|1[02])-(0?[1-9]|[1-2][0-9]|3[01])|(0?[469]|11)-(0?[1-9]|[1-2][0-9]|30)|0?2-(0?[1-9]|[1-2][0-9]))|([02468][1235679]|[13579][01345789])-((0?[13578]|1[02])-(0?[1-9]|[1-2][0-9]|3[01])|(0?[469]|11)-(0?[1-9]|[1-2][0-9]|30)|0?2-(0?[1-9]|1[0-9]|(2[0-8]))))$/;
		
		if ( theValue.search( strReg ) == -1 )
		{
			alert("日期格式错误！");
			return false;
		}
		return true;		

		
	}

//-----------------------------------------------------------------

	function isTime ( theValue )
	{
		var strReg=/^(\s(0?[1-9]|1[0-9]|2[0-4]):(0?[1-9]|[1-5][0-9]):(0?[1-9]|[1-5][0-9]))?$/;
		
		if ( theValue.search( strReg ) == -1 )
		{
			alert("时间格式错误！");
			return false;
		}
		return true;		

		
	}
//-----------------------------------------------------------------

function CheckForm(theForm){
var strValidityNick = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_";
  var strValidityPassword = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
  //var strValidityTopNick="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
  var strValidityPhonenum="0123456789";

	if (isEmpty(theForm.username.value,'用户名'))
	{
		theForm.username.focus();
		return false;
	}


	if (!isValidity(theForm.username.value,strValidityNick))
	{
		theForm.username.focus();
		return false;
	}


	if (isEmpty(theForm.password.value,'密码'))
	{
		theForm.password.focus();
		return false;
	}
	if (isEmpty(theForm.confirmcode.value,'验证码'))
	{
		theForm.confirmcode.focus();
		return false;
	}
	return true;
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
  }
  ///----------------------------------------------------------
function CheckForm(theForm){
var strValidityNick = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_";
  var strValidityPassword = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
  //var strValidityTopNick="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
  var strValidityPhonenum="0123456789";
	if (isEmpty(theForm.username.value,'用户名'))
	{
		theForm.username.focus();
		return false;
	}


	if (!isValidity(theForm.username.value,strValidityNick))
	{
		theForm.username.focus();
		return false;
	}


	if (isEmpty(theForm.password.value,'密码'))
	{
		theForm.password.focus();
		return false;
	}
	if (isEmpty(theForm.confirmcode.value,'验证码'))
	{
		theForm.confirmcode.focus();
		return false;
	}
	return true;
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function xxCheckInputText()
{
	var obj = event.srcElement;
	var str = obj.value;
	var len = str.length;
	var totallength = 0;
	for (var i = 0; i < str.length; i++) 
	{
		var intCode = str.charCodeAt(i);
		if (intCode>=0 && intCode<=255) 
		{
			totallength = totallength + 1;
		}
		else 
		{
			totallength = totallength + 2;
		}
	}
	if (totallength > obj.maxLength) 
	{
		obj.value = str.substring(0,len - 1);
		return false;
	}
	else
	{
		return true;
	}
}
function xxCheckInputTextAll() 
{
	var inputarr = document.getElementsByTagName('input');
	var num = 0;
	for (var i = 0; i < inputarr.length; i++)
	{
		var objText = inputarr[i]
		if (objText.type == 'text')
		{
			objText.attachEvent ('onkeyup',checkInputText);
		}
	}
}
function xxSwithDisplay(chk,ctrl) 
{
	if (ctrl.style.display == 'none') 
	{
		ctrl.style.display = 'block';
	} 
	else 
	{
		ctrl.style.display = 'none';
	}
}
function CreateXMLHttpRequest()
{
	var xmlhttp = false;
	try 
	{
		xmlhttp = new ActiveXObject('Msxml2.XMLHTTP');
	} 
	catch (e)
	{
		try 
		{
			xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
		}
		catch (e)
		{
			xmlhttp = null;
		}
	}
	if (!xmlhttp && typeof(XMLHttpRequest)!='undefined') 
		xmlhttp = new XMLHttpRequest();
	return xmlhttp;
}
function xx_RequestUrl2Div(divID,url,waitHtml)
{
	var div=document.getElementById(divID);
	if (waitHtml) div.innerHTML=waitHtml;
	var xmlHttp = new CreateXMLHttpRequest();
	if (!xmlHttp)
	{
		div.innerHTML='<strong>ajax</strong>';
		return;
	}
	xmlHttp.onreadystatechange = function()
	{
		if (xmlHttp && xmlHttp.readyState==4)
		{
			div.innerHTML=xmlHttp.responseText;
			xmlHttp = null;
		}
	}
	var dt = new Date();
	url += (url.indexOf('?') < 0) ? '?xx_dt=' + dt.toString() : '&xx_dt=' + dt.toString();
	xmlHttp.open('get', url, true);
	xmlHttp.send(null);
}
function xx_RequestUrl(url,data,func)
{
	var xmlHttp = new CreateXMLHttpRequest();
	if (!xmlHttp) return '';
	var async = (func==true || typeof(func) == 'function');
	if (async)
	{
		xmlHttp.onreadystatechange = function()
		{
			if (xmlHttp && xmlHttp.readyState==4)
			{
				if (typeof(func) == 'function') 
					func(xmlHttp.responseText);
				xmlHttp = null;
			}
		}
	}
	var dt = new Date();
	url += (url.indexOf('?') < 0) ? '?xx_dt=' + dt.toString() : '&xx_dt=' + dt.toString();
	xmlHttp.open('get', url, async);
	xmlHttp.send(data);
	if(!async)
	{
		var strResult = xmlHttp.responseText;
		xmlHttp = null;
		return strResult;
	}
}
function xxCheckFieldOnly(inputID,table)
{
	var formDoc = '<CheckField>';
	formDoc += '<FieldName>' + inputID.name + '</FieldName>';
	formDoc += '<FieldValue>' + inputID.value + '</FieldValue>';
	formDoc += '<Table>' + table + '</Table>';
	formDoc += '</CheckField>';
	var xmlHttp = CreateXMLHttpRequest();
	if (!xmlHttp)
	{
		alert('');
		return true;
	}
	var strResult = '';
	xmlHttp.open('post', 'xp_checkfieldonly.aspx', false);
	xmlHttp.send(formDoc);
	strResult = xmlHttp.responseText;
	var xml = xmlHttp.responseXML;
	xmlHttp = null;
	return (strResult == '')
}
function xxCheckForm(form)
{
	var spanList = document.body.getElementsByTagName('span');
	for (var i=0; i<spanList.length; ++i)
	{
		if (spanList[i].id.substring(0,3) == 'xx_')
		{
			spanList[i].innerHTML = '';
		}
	}
	var span = document.getElementById('xx_' + form.id + '_msg');
	var formDoc = '<FormData>';
	var strUrl = location.href;
	if (strUrl.indexOf('?') > -1) 
		strUrl = strUrl.substring(0,strUrl.indexOf('?'));
	formDoc += '<SourceUrl>' + strUrl + '</SourceUrl>';
	formDoc += '<Action>' + form.action + '</Action>';
	var valid = true;
	for (i = 0; i<form.elements.length; i++)
	{
		var elem = form.elements[i];
		if (elem.type=='text' || elem.type=='hidden' || elem.type=='password' || elem.tagName.toLowerCase()=='textarea')
		{
			if (elem.value == elem.noticeValue)
			{
				valid = false;
				break;
			}
			var name = elem.id;
			if (name.length > 0) 
				formDoc += '<' + name + '>' + escape(elem.value) + '</' + name + '>';
		}
	}
	if (!valid)
	{
		if (span) span.innerHTML = '';
		return false;
	}
	formDoc += '</FormData>';
	var xmlHttp = CreateXMLHttpRequest();
	if (!xmlHttp)
	{
		if (span) 
			span.innerHTML = '';
		return true;
	}
	var strResult = '';
	xmlHttp.open('post', 'xp_validateform.aspx', false);
	xmlHttp.send(formDoc);
	strResult = xmlHttp.responseText;
	var xml = xmlHttp.responseXML;
	xmlHttp = null;
	if (strResult == '') return true;
	var values = strResult.split('|');
	if (values[0] == 'False')
	{
		var errMsg = '';
		var firstField = values[1].substr(0,values[1].indexOf('$'));
		for (var i=1;i<values.length;i++)
		{
			errMsg += values[i].substr(values[i].indexOf('$') + 1) + '</br>';
		}
		errMsg = errMsg.substr(0,errMsg.length - 5);
		if (span)
			span.innerHTML = errMsg;
		var input = form.elements.namedItem(firstField);
		if (input.type!='hidden')
		{
			input.value=values[1].substr(values[1].indexOf('$') + 1);
			input.select();
			input.focus();
		}
		return false;
	}
	return true;
}
var xx_FileObj=null;
function SetUrl( url )
{
	if (xx_FileObj) xx_FileObj.value=url;
}
function xx_OpenFile(obj,editorPath,type,currentUrl)
{
	xx_FileObj = obj;
	var iLeft = screen.availWidth / 6 ;
	var iTop  = screen.availHeight / 6 ;
	var width = screen.availWidth * 2 / 3 ;
	var height  = screen.availHeight * 2 / 3 ;
	var sOptions = 'toolbar=no,status=no,resizable=yes,dependent=yes' ;
	sOptions += ',width=' + width ;
	sOptions += ',height=' + height ;
	sOptions += ',left=' + iLeft ;
	sOptions += ',top=' + iTop ;
	if (editorPath == null || editorPath == '') 
		editorPath = '/inc/fckeditor/';
	var strBrowser = 'browser.html';
	if (currentUrl != null && currentUrl!='') 
		strBrowser = 'browser_sys.html';
	var url = editorPath + '/editor/filemanager/browser/default/' + strBrowser + '?Connector=xp_fck_connector.aspx';
	if (type != null && type != '') 
		url += '&Type=' + type;
	if (currentUrl != null && currentUrl!='') 
		url += '&ServerPath=' + currentUrl
	if (navigator.appName.indexOf('Explorer')>-1)
	{
		var oWindow = window.open( url, 'xxFCKBrowseWindow', sOptions ) ;
		if ( oWindow ) oWindow.opener = window ;
	}
	else
		window.open( url, 'xxFCKBrowseWindow', sOptions ) ;
}
function imgResize(img,width,height) 
{
	if (width == 0 && height == 0) return;
	var obj = new Image();
	obj.src = img.src;
	if (width == 0)
	{
		if(obj.height>=height) 
		{
			img.removeAttribute('width');
			img.height=height;
		}
		obj = null;
		return;
	}
	if (height == 0)
	{
		if(obj.width>=width)
		{
			img.removeAttribute('height');
			img.width=width;
		}
		obj = null;
		return;
	}
	if ((obj.width/obj.height) > (width/height)) 
	{
		if(obj.width>=width)
		{
			img.removeAttribute('height');
			img.width=width;
		}
	} 
	else 
	{
		if(obj.height>=height) 
		{
			img.removeAttribute('width');
			img.height=height;
		}
	}
	obj = null;
}
function imgWheel(o)
{
	var zoom = parseInt(o.style.zoom, 10)||100;
	zoom += event.wheelDelta / 12;
	if (zoom>0) o.style.zoom = zoom + '%';
	return false;
}
function imgResizeAll(obj,width,height) 
{
	for (var i = 0; i < obj.children.length; i ++) 
	{
		var img = obj.children[i];
		if (img.tagName.toLowerCase() == 'img')
		{
			imgResize(img,width,height)
		}
		imgResize(obj.children[i]);
	}
}
function chkImgPreview(txtObj,imgPreview,noImgUrl) 
{
	if (txtObj.value == '') 
	{
		imgPreview.src = noImgUrl;
	} 
	else 
	{
		imgPreview.src = txtObj.value;
	}
}
function xx_SetCookies(sName, sValue, iMinutes)
{
	date = new Date();
	if (iMinutes<1)
	{
		var y=date.getFullYear();
		date.setFullYear(y+2);
	}
	else
	{
		var m = date.getMinutes();
		date.setMinutes(m+iMinutes);
	}
	document.cookie = sName + '=' + escape(sValue) + ';	expires=' + date.toGMTString();
}
function xx_GetCookies(sName)
{
	var aCookie = document.cookie.split('; ');
	for (var i=0; i < aCookie.length; i++)
	{
		var aCrumb = aCookie[i].split('=');
		if (sName == aCrumb[0])
			return unescape(aCrumb[1]);
	}
	return null;
}
function xx_DelCookies(sName)
{
	document.cookie = sName + '=; expires=Fri, 31 Dec 1999 23:59:59 GMT;';
}
//--------------------------------------------------------
var base64EncodeChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
var base64DecodeChars = new Array(
    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63,
    52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1,
    -1,  0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14,
    15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1,
    -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
    41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1);

function tobase64(str)
{
    return base64encode(utf16to8(str))
}

function frombase64(str)
{
    return utf8to16(base64decode(str))
}

function base64encode(str) {
    var out, i, len;
    var c1, c2, c3;

    len = str.length;
    i = 0;
    out = "";
    while(i < len) {
    c1 = str.charCodeAt(i++) & 0xff;
    if(i == len)
    {
        out += base64EncodeChars.charAt(c1 >> 2);
        out += base64EncodeChars.charAt((c1 & 0x3) << 4);
        out += "==";
        break;
    }
    c2 = str.charCodeAt(i++);
    if(i == len)
    {
        out += base64EncodeChars.charAt(c1 >> 2);
        out += base64EncodeChars.charAt(((c1 & 0x3)<< 4) | ((c2 & 0xF0) >> 4));
        out += base64EncodeChars.charAt((c2 & 0xF) << 2);
        out += "=";
        break;
    }
    c3 = str.charCodeAt(i++);
    out += base64EncodeChars.charAt(c1 >> 2);
    out += base64EncodeChars.charAt(((c1 & 0x3)<< 4) | ((c2 & 0xF0) >> 4));
    out += base64EncodeChars.charAt(((c2 & 0xF) << 2) | ((c3 & 0xC0) >>6));
    out += base64EncodeChars.charAt(c3 & 0x3F);
    }
    return out;
}

function base64decode(str) {
    var c1, c2, c3, c4;
    var i, len, out;

    len = str.length;
    i = 0;
    out = "";
    while(i < len) {
    /* c1 */
    do {
        c1 = base64DecodeChars[str.charCodeAt(i++) & 0xff];
    } while(i < len && c1 == -1);
    if(c1 == -1)
        break;

    /* c2 */
    do {
        c2 = base64DecodeChars[str.charCodeAt(i++) & 0xff];
    } while(i < len && c2 == -1);
    if(c2 == -1)
        break;

    out += String.fromCharCode((c1 << 2) | ((c2 & 0x30) >> 4));

    /* c3 */
    do {
        c3 = str.charCodeAt(i++) & 0xff;
        if(c3 == 61)
        return out;
        c3 = base64DecodeChars[c3];
    } while(i < len && c3 == -1);
    if(c3 == -1)
        break;

    out += String.fromCharCode(((c2 & 0XF) << 4) | ((c3 & 0x3C) >> 2));

    /* c4 */
    do {
        c4 = str.charCodeAt(i++) & 0xff;
        if(c4 == 61)
        return out;
        c4 = base64DecodeChars[c4];
    } while(i < len && c4 == -1);
    if(c4 == -1)
        break;
    out += String.fromCharCode(((c3 & 0x03) << 6) | c4);
    }
    return out;
}

function utf16to8(str) {
    var out, i, len, c;

    out = "";
    len = str.length;
    for(i = 0; i < len; i++) {
    c = str.charCodeAt(i);
    if ((c >= 0x0001) && (c <= 0x007F)) {
        out += str.charAt(i);
    } else if (c > 0x07FF) {
        out += String.fromCharCode(0xE0 | ((c >> 12) & 0x0F));
        out += String.fromCharCode(0x80 | ((c >>  6) & 0x3F));
        out += String.fromCharCode(0x80 | ((c >>  0) & 0x3F));
    } else {
        out += String.fromCharCode(0xC0 | ((c >>  6) & 0x1F));
        out += String.fromCharCode(0x80 | ((c >>  0) & 0x3F));
    }
    }
    return out;
}

function utf8to16(str) {
    var out, i, len, c;
    var char2, char3;

    out = "";
    len = str.length;
    i = 0;
    while(i < len) {
    c = str.charCodeAt(i++);
    switch(c >> 4)
    { 
      case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7:
        // 0xxxxxxx
        out += str.charAt(i-1);
        break;
      case 12: case 13:
        // 110x xxxx   10xx xxxx
        char2 = str.charCodeAt(i++);
        out += String.fromCharCode(((c & 0x1F) << 6) | (char2 & 0x3F));
        break;
      case 14:
        // 1110 xxxx  10xx xxxx  10xx xxxx
        char2 = str.charCodeAt(i++);
        char3 = str.charCodeAt(i++);
        out += String.fromCharCode(((c & 0x0F) << 12) |
                       ((char2 & 0x3F) << 6) |
                       ((char3 & 0x3F) << 0));
        break;
    }
    }

    return out;
}