﻿
		
function GetDataString(address,controlName)
{ 

	var xmlHttp
	var url=address 
	xmlHttp=GetXmlHttpObject()
	xmlHttp.onreadystatechange = function()
	{
		if (xmlHttp.readyState==4 || xmlHttp.readyState=='complete')
		{ 
			//document.getElementById(controlName).innerHTML = xmlHttp.responseText
			//alert(controlName)
			$("#"+controlName).html("");
			$("#"+controlName).html(xmlHttp.responseText);
			//imgno();
        } 
	} 

	xmlHttp.open("POST", url , true)
	xmlHttp.setRequestHeader( "Content-Type", "text/html;charset=UTF-8" );
	xmlHttp.send('')
} 

function GetDataStringNoReturn(address)
{
    var xmlHttp
	var url=address 
	xmlHttp=GetXmlHttpObject()
	xmlHttp.onreadystatechange = function()
	{
		if (xmlHttp.readyState==4 || xmlHttp.readyState=='complete')
		{ 
		   
        } 
	} 

	xmlHttp.open("POST", url , true)
	xmlHttp.send(null)
}
function LoadFirst()
{
    var xmlHttp
	var url="/ProductModule/Product/Shopping/GlobalAreaList.aspx?ParentId=7"
	xmlHttp=GetXmlHttpObject()
	xmlHttp.onreadystatechange = function()
	{
		if (xmlHttp.readyState==4 || xmlHttp.readyState=='complete')
		{ 
		    var obj=document.getElementById("First");
		    //赋值
			var itemArray = xmlHttp.responseText.split("||"); 
			for(var i=0;i<itemArray.length;i++)
			{
				var valueText = itemArray[i].split("|");
				
				fnAdd(obj,valueText[0],valueText[1]);
	        } 
		    LoadSecondByFirst($('#First').val());
        } 
	} 

	xmlHttp.open("GET", url , true)
	xmlHttp.send(null)
}


function LoadSecondByFirst(parentId)
{
    var xmlHttp
	var url="/ProductModule/Product/Shopping/GlobalAreaList.aspx?ParentId="+parentId
	xmlHttp=GetXmlHttpObject()
	xmlHttp.onreadystatechange = function()
	{
		if (xmlHttp.readyState==4 || xmlHttp.readyState=='complete')
		{ 
		    var obj=document.getElementById("Second");
		     //赋值
			var itemArray = xmlHttp.responseText.split("||"); 
			for(var i=0;i<itemArray.length;i++)
			{
				var valueText = itemArray[i].split("|");
				
				fnAdd(obj,valueText[0],valueText[1]);
	        } 
		    
        } 
	} 

	xmlHttp.open("GET", url , true)
	xmlHttp.send(null)
}

// 编辑加载下拉列表 
//firstEditValue-第一级下拉列表的选中值
//secondEditValue-第二级下拉列表的选中值
function LoadFirstEdit(firstEditValue,secondEditValue)
{
    var xmlHttp
	var url="/ProductModule/Product/Shopping/GlobalAreaList.aspx?ParentId=7"
	xmlHttp=GetXmlHttpObject()
	xmlHttp.onreadystatechange = function()
	{
		if (xmlHttp.readyState==4 || xmlHttp.readyState=='complete')
		{ 
            var obj=document.getElementById("FirstEdit");
            var selectIndex=0;
            //赋值
            var itemArray = xmlHttp.responseText.split("||"); 

            for(var i=0;i<itemArray.length;i++)
            {
                var valueText = itemArray[i].split("|");
                if(valueText[1]==firstEditValue)
                {
                    selectIndex=i;
                }
                fnAdd(obj,valueText[0],valueText[1]);
            } 

            //注意问题：如果在IE6中设置select控件的selected属性的时候，会提示“无法设置selected属性。未指明的错误。”
            //分析：发现这个错误在IE5.5、7及Firefox等浏览器下面没有问题，唯独IE6下有如下的提示。
            //解决方法：就是设置selected属性的时候使用setTimeout函数设定一个时间即可
            setTimeout(function(){obj.options[selectIndex].selected=true;},1);
            LoadSecondByFirstEdit(obj.options[selectIndex].value,secondEditValue);
        } 
       
	} 

	xmlHttp.open("GET", url , false)
	xmlHttp.send(null)
}


function LoadSecondByFirstEdit(parentId,secondEditValue)
{
    var xmlHttp
	var url="/ProductModule/Product/Shopping/GlobalAreaList.aspx?ParentId="+parentId
	xmlHttp=GetXmlHttpObject()
	xmlHttp.onreadystatechange = function()
	{
		if (xmlHttp.readyState==4 || xmlHttp.readyState=='complete')
		{ 
		    $('#SecondEdit').empty();
            var obj=document.getElementById("SecondEdit");
           
             //赋值
            var itemArray = xmlHttp.responseText.split("||"); 
            for(var i=0;i<itemArray.length;i++)
            {
                var valueText = itemArray[i].split("|");
	            if(valueText[1]==secondEditValue)
                {
                    selectIndex=i;
                }
                fnAdd(obj,valueText[0],valueText[1]);
            } 
            //注意问题：如果在IE6中设置select控件的selected属性的时候，会提示“无法设置selected属性。未指明的错误。”
            //分析：发现这个错误在IE5.5、7及Firefox等浏览器下面没有问题，唯独IE6下有如下的提示。
            //解决方法：就是设置selected属性的时候使用setTimeout函数设定一个时间即可
        
            setTimeout(function(){obj.options[selectIndex].selected=true;},1);

	     
        } 
	} 

	xmlHttp.open("GET", url , false)
	xmlHttp.send(null)
}

function fnAdd(oListbox, sName, sValue) 
{
    var oOption = document.createElement("option");
    oOption.appendChild(document.createTextNode(sName));

    if (arguments.length == 3) 
    {
        oOption.setAttribute("value", sValue);
    }

    oListbox.appendChild(oOption);
}
function GetXmlHttpObject()
{ 
	var xmlHttp;
	if(window.XMLHttpRequest)
	{
		xmlHttp = new XMLHttpRequest();
		return xmlHttp;
	}
	try
	{
		xmlHttp = new ActiveXObject('MSXML2.XMLHTTP.4.0');
		return xmlHttp;
	}
	catch(e)
	{
		try
		{
			xmlHttp = new ActiveXObject('MSXML2.XMLHTTP.3.0');
			return xmlHttp;
		}
		catch(e)
		{
			try
			{
				xmlHttp = new ActiveXObject('MSXML2.XMLHTTP.2.6');
				return xmlHttp;
			}
			catch(e)
			{
				try
				{
					xmlHttp = new ActiveXObject('MSXML2.XMLHTTP');
					return xmlHttp;
				}
				catch(e)
				{
					try
					{
						xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
						return xmlHttp;
					}
					catch(e)
					{
						alert("Your browser does not support AJAX!");        
						return null;
					}
				}
			}
		}
	}
}



///以下是同步使用的方法-----------------------------------------------
function GetStringFromUrl(url)
{
	var result = "";
	//xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	xmlhttp = createXmlhttp() ;
	xmlhttp.open("POST",url,false);
	xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 
	xmlhttp.send(null);
	result = xmlhttp.responseText;
	return result; 
}
   
   function createXmlhttp()
    {
        var xmlhttp = false;
        try
        {
            xmlhttp = new XMLHttpRequest();
        }
        catch(e1)
        {
            try
            {
                xmlhttp = new ActiveXObject("MsXml2.XMLHTTP");
            }
            catch(e2)
            {
                try
                {
                    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                }
                catch(e3)
                {
                    xmlhttp = false;
                }
            }
        }
       
        if (!xmlhttp)
        {
            document.write("Error XMLHttpRequest");
        }
        return xmlhttp;
    }

function PaginationBtnClick(PaginationType,MAccessPageAddressAjax,MAccessPageAddressLink,ReceptacleName,message,txtName)
{
	var txtPagination = document.getElementById(txtName)
	var type = PaginationType
	if(isDigit(txtPagination.value,message))
	{

		if(type == "ajax")
		{
			GetDataString(MAccessPageAddressAjax + 'Page=' + txtPagination.value,ReceptacleName)
		}
		else
		{
			window.location = MAccessPageAddressLink + 'Page=' + txtPagination.value
		}
	}
}
function isDigit(s,message)
{
	var patrn=/^[0-9]{1,20}$/;


	if (!patrn.exec(cTrim(s,0)))
	{
		
		//alert(message) ;
		return false
	}
	
	return true
}
//**************************************************************** 
// Description: sInputString 为输入字符串，iType为类型，分别为 
// 0 - 去除前后空格; 1 - 去前导空格; 2 - 去尾部空格 
//**************************************************************** 
function cTrim(sInputString,iType) 
{ 
    var sTmpStr = ' ' 
    var i = -1 

    if(iType == 0 || iType == 1) 
    { 
        while(sTmpStr == ' ') 
        { 
            ++i 
            sTmpStr = sInputString.substr(i,1) 
        } 
        sInputString = sInputString.substring(i) 
    } 

    if(iType == 0 || iType == 2) 
    { 
        sTmpStr = ' ' 
        i = sInputString.length 
        while(sTmpStr == ' ') 
        { 
            --i 
            sTmpStr = sInputString.substr(i,1) 
        } 
        sInputString = sInputString.substring(0,i+1) 
    } 
    return sInputString 
} 
