// JavaScript Document

String.prototype.Contains = function( textToCheck ){
	return ( this.indexOf( textToCheck ) > -1 ) ;
}

String.prototype.Equals = function(){
	var aArgs = arguments ;

	// The arguments could also be a single array.
	if ( aArgs.length == 1 && aArgs[0].pop )
		aArgs = aArgs[0] ;

	for ( var i = 0 ; i < aArgs.length ; i++ )
	{
		if ( this == aArgs[i] )
			return true ;
	}
	return false ;
}

String.prototype.IEquals = function(){
	var thisUpper = this.toUpperCase() ;

	var aArgs = arguments ;

	// The arguments could also be a single array.
	if ( aArgs.length == 1 && aArgs[0].pop )
		aArgs = aArgs[0] ;

	for ( var i = 0 ; i < aArgs.length ; i++ )
	{
		if ( thisUpper == aArgs[i].toUpperCase() )
			return true ;
	}
	return false ;
}

String.prototype.ReplaceAll = function( searchArray, replaceArray ){
	var replaced = this ;

	for ( var i = 0 ; i < searchArray.length ; i++ )
	{
		replaced = replaced.replace( searchArray[i], replaceArray[i] ) ;
	}

	return replaced ;
}

String.prototype.StartsWith = function( value ){
	return ( this.substr( 0, value.length ) == value ) ;
}

// Extends the String object, creating a "EndsWith" method on it.
String.prototype.EndsWith = function( value, ignoreCase ){
	var L1 = this.length ;
	var L2 = value.length ;

	if ( L2 > L1 )
		return false ;

	if ( ignoreCase )
	{
		var oRegex = new RegExp( value + '$' , 'i' ) ;
		return oRegex.test( this ) ;
	}
	else
		return ( L2 == 0 || this.substr( L1 - L2, L2 ) == value ) ;
}

String.prototype.Remove = function( start, length ){
	var s = '' ;

	if ( start > 0 )
		s = this.substring( 0, start ) ;

	if ( start + length < this.length )
		s += this.substring( start + length , this.length ) ;

	return s ;
}

String.prototype.Trim = function(){
	// We are not using \s because we don't want "non-breaking spaces to be caught".
	return this.replace( /(^[ \t\n\r]*)|([ \t\n\r]*$)/g, '' ) ;
}

String.prototype.LTrim = function(){
	// We are not using \s because we don't want "non-breaking spaces to be caught".
	return this.replace( /^[ \t\n\r]*/g, '' ) ;
}

String.prototype.RTrim = function(){
	// We are not using \s because we don't want "non-breaking spaces to be caught".
	return this.replace( /[ \t\n\r]*$/g, '' ) ;
}

String.prototype.ReplaceNewLineChars = function( replacement ){
	return this.replace( /\n/g, replacement ) ;
}

String.prototype.Replace = function( regExp, replacement, thisObj ){
	if ( typeof replacement == 'function' )
	{
		return this.replace( regExp,
			function()
			{
				return replacement.apply( thisObj || this, arguments ) ;
			} ) ;
	}
	else
		return this.replace( regExp, replacement ) ;
}

Array.prototype.IndexOf = function( value ){
	for ( var i = 0 ; i < this.length ; i++ )
	{
		if ( this[i] == value )
			return i ;
	}
	return -1 ;
}
function checkEmail(val){
	var tomatch=/[A-Za-z0-9]\w{1,}@[A-Za-z0-9-]{1,}\.[A-Za-z]{2,}/
	if(tomatch.test(val)){
		return true;
	}
	return false;
}

function $(objId){
	if(!objId){
		throw new Error("o(String objId) mast no empty");
	}
	if(document.getElementById){
		return eval('document.getElementById("'+objId+'")');
	}
	else if(document.layers){
		return eval("document.layers['"+objId+"']");
	}
	else{
		return eval('document.all.'+objId);
	}
}

function DrawLogo(ImgD){
	var flag = false;
	var image=new Image();
	var iwidth = 130;//定义允许图片宽度 
	var iheight = 40;//定义允许图片高度 
	image.src=ImgD.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 autoSzPic(ImgD, iwidth, iheight){
	var flag = false;
	var image=new Image();
	image.src=ImgD.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 AttachEvent(obj, eventName, eventHandler){
	if(obj) {
		if(eventName.substring(0, 2) == "on") {
			eventName = eventName.substring(2,eventName.length);
		}
		if (obj.addEventListener){
			obj.addEventListener(eventName, eventHandler, false);
		} else if (obj.attachEvent){
			obj.attachEvent('on'+eventName, eventHandler);
		}
	}
}
function txtMsg(tbox,msg, s){
	if(s&&tbox.value==msg){
		tbox.value='';
	}else{
		if(tbox.value.Trim()==''){
			tbox.value=msg;
		}
	}
}
//Ajax Start
function DoCallback(url, postData, callback){
	var xmlHttpRequest=false,qzzc;

	function qzzs(){

		if(qzzc.readyState&&qzzc.readyState!=4&&qzzc.readyState!='complete'){

			return ;

		};
		var responseText=qzzc.responseText;

		if(responseText!="")
		{
		    callback.call(this, responseText);
			delete qzzc;
		    return;
		}
		//////////////////////////////
		if(xmlHttpRequest){

			qzzc=qzzc.responseXML;

		};

		if(qzzc&&qzzc.documentElement){
			var ReadData=function(qzau){return qzau.firstChild.nodeValue;};
			var arData=qzzc.documentElement,sEncodedContent=ReadData(arData),sContent=sEncodedContent.replace(/\$\$\$CART_CDATA_CLOSE\$\$\$/g,"]]>");

            callback.call(this, sContent);
			delete qzzc;
            return;

    	}
		else {
			alert('The data could not be loaded.');
		};

	};

	/////////////////////////////////////
	if(window.XMLHttpRequest){

		xmlHttpRequest=true;
		qzzc=new XMLHttpRequest();
		qzzc.onreadystatechange=qzzs;
		qzzc.open("get",url,true);
		qzzc.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		qzzc.send(postData);


	}
	else if(document.implementation&&document.implementation.createDocument)
	{

		qzzc=document.implementation.createDocument("","",null);
		qzzc.onload=qzzs;

	}
	else if(document.all){

		if(window.ActiveXObject){

			try{

				qzzc=new ActiveXObject("Microsoft.XMLHTTP");
				qzzc.onreadystatechange=qzzs;
				qzzc.open("get",url,true);
				qzzc.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
				qzzc.send(postData);
				xmlHttpRequest=true;

			}
			catch(ex){

			};

		};
		if(qzzc==null){

			var qzac=this.Id+'_island',qzv=document.getElementById(qzac);
			if(!qzv){

				qzv=document.createElement('xml');
				qzv.id=qzac;
				document.body.appendChild(qzv);

			};
			if(qzv.XMLDocument){
				qzzc=qzv.XMLDocument;
				qzzc.onreadystatechange=qzzs;
			}
			else {
				return false;
			};
		};

	}
	else {
		if(this.Postback){
			this.Postback();
		};
		return false;

	};
	if(!xmlHttpRequest){

		qzzc.async=true;
		try{

			qzzc.load(url+"?"+postData);

		}
		catch(ex){

			alert("Data not loaded: "+(ex.message?ex.message:ex));

		};

	};
	return true;

};

//Ajax End


var s = navigator.userAgent.toLowerCase() ;

var BrowserInfo ={
	IsIE		: /*@cc_on!@*/false,
	IsIE7		: /*@cc_on!@*/false && ( parseInt( s.match( /msie (\d+)/ )[1], 10 ) >= 7 ),
	IsIE6		: /*@cc_on!@*/false && ( parseInt( s.match( /msie (\d+)/ )[1], 10 ) >= 6 ),
	IsSafari	: s.Contains(' applewebkit/'),		// Read "IsWebKit"
	IsOpera		: !!window.opera,
	IsAIR		: s.Contains(' adobeair/'),
	IsMac		: s.Contains('macintosh')
};

// Completes the browser info with further Gecko information.
(function( browserInfo ){
	browserInfo.IsGecko = ( navigator.product == 'Gecko' ) && !browserInfo.IsSafari && !browserInfo.IsOpera ;
	browserInfo.IsGeckoLike = ( browserInfo.IsGecko || browserInfo.IsSafari || browserInfo.IsOpera ) ;

	if ( browserInfo.IsGecko )
	{
		var geckoMatch = s.match( /rv:(\d+\.\d+)/ ) ;
		var geckoVersion = geckoMatch && parseFloat( geckoMatch[1] ) ;

		// Actually "10" refers to Gecko versions before Firefox 1.5, when
		// Gecko 1.8 (build 20051111) has been released.

		// Some browser (like Mozilla 1.7.13) may have a Gecko build greater
		// than 20051111, so we must also check for the revision number not to
		// be 1.7 (we are assuming that rv < 1.7 will not have build > 20051111).

		if ( geckoVersion )
		{
			browserInfo.IsGecko10 = ( geckoVersion < 1.8 ) ;
			browserInfo.IsGecko19 = ( geckoVersion > 1.8 ) ;
		}
	}
})(BrowserInfo) ;

function getQueryString(key)
{
    var value = ""; 
    //获取当前文档的URL,为后面分析它做准备
    var sURL = window.document.URL;

    //URL中是否包含查询字符串
    if (sURL.indexOf("?") > 0)
    {
        var str = window.location.search.substring(1,window.location.search.length);
        var arrayURLParams = str.split("&");

        //遍历分解后的键值对
        for (var i = 0; i < arrayURLParams.length; i++)
        {
            //分解一个键值对
            var sParam =  arrayURLParams[i].split("=");
            if ((sParam[0] == key) && (sParam[1] != ""))
            {
                //找到匹配的的键,且值不为空
                value = sParam[1];
                break;
            }
        }
    }
    return value;
}
function WdKeyPress(e){
	var e=e||event;
	var currKey=e.keyCode||e.which||e.charCode;
	if(currKey==13){
		doTopSearch();
		return false;
	}
}
function doTopSearch(){
	var tWd = $('topSrchWd');
	var tTyp = $('topSrchType');
	if(tWd.value==''){
		alert('请输入关键字!');
		return;
	}
	window.location.href = tTyp.value + escape(tWd.value);
}
