var StrNewNamespace="http://schemas.microsoft.com/WebPart/v2";
function SplitIndex(Index)
{
	var sPropURN="";
	var sPropName="";
	var pos=Index.lastIndexOf("#");
	if( -1==pos )
	{
		pos=Index.lastIndexOf(":");
	}
	if( -1==pos )
	{
		sPropName=Index;
	}
	else
	{
		sPropName=Index.substring(pos+1, Index.length);
		sPropURN=Index.substring(0, pos);
	}
	var Splitted={PropURN : sPropURN, PropName : sPropName};
	return Splitted;
}
function String2XML(Value)
{
	var XMLString="";
	var re=/&/g;
	XMLString=Value.replace(re,"&amp;");
	re=/</g;
	XMLString=XMLString.replace(re,"&lt;");
	re=/>/g;
	XMLString=XMLString.replace(re,"&gt;");
	re=/"/g;
	XMLString=XMLString.replace(re,"&quot;");
	re=/'/g;
	XMLString=XMLString.replace(re,"&apos;");
	return XMLString;
}
function URL2Unicode(strURL)
{
	return Utf8ToUnicode(unescape(strURL));
}
function Unicode2URL(strUnicode)
{
	return URLEncode(strUnicode);
}
function URLEncode(strURL)
{
	var strSpecialUrl=" <>\"#%{}|^~[]`'&?+=";
	var strEncode="";
	var i;
	var chUrl;
	var iCode;
	strURL+="";
	for (i=0; i<strURL.length; i++)
	{
		chUrl=strURL.charAt(i);
		iCode=chUrl.charCodeAt(0);
		if (iCode<=parseInt(0x7F))
		{
			if (strSpecialUrl.indexOf(chUrl) !=-1)
			{
				strEncode+="%"+iCode.toString(16).toUpperCase();
			}
			else
			{
				strEncode+=chUrl;
			}
		}
		else
		{
			strEncode+=GetUTFCode(iCode);
		}
	}
	return strEncode;
}
function GetUTFCode(UniCode)
{
	var BitLen=11;
	var ByteLen=2;
	var UTFCode="";
	var FirstByte=0xC0;	
	var i;
	while(UniCode >=(1<<BitLen))
	{
		FirstByte=FirstByte>>1;
		BitLen+=5;
		ByteLen++;
	}
	for( i=0; i < ByteLen; i++)
	{
		var Code=0x80 | (UniCode & 0x3f);
		UniCode=UniCode >>> 6;
		if( i==ByteLen-1 )
		{
			Code |=FirstByte;
		}
		UTFCode="%"+Code.toString(16).toUpperCase()+UTFCode;
	}
	return UTFCode;
}
function Utf8ToUnicode(strUtf8)
{
	if(strUtf8==null)
	{
		return "";
	}
	var bstr="";
	var nTotalChars=strUtf8.length;	
	var nOffset=0;					
	var nRemainingBytes=nTotalChars;	
	var nOutputPosition=0;
	var iCode, iCode1, iCode2;			
	while (nOffset < nTotalChars)
	{
		iCode=strUtf8.charCodeAt(nOffset);
		if ((iCode & 0x80)==0)			
		{
			if ( nRemainingBytes < 1 )
			{	
				break;
			}
			bstr+=String.fromCharCode(iCode & 0x7F);
			nOffset++;
			nRemainingBytes -=1;
		}
		else if ((iCode & 0xE0)==0xC0)	
		{
			iCode1=strUtf8.charCodeAt(nOffset+1);
			if ( nRemainingBytes < 2 || 		
			   (iCode1 & 0xC0) !=0x80 )		
			{
				break;
			}
			bstr+=String.fromCharCode(((iCode & 0x3F) << 6) | (iCode1 & 0x3F));
			nOffset+=2;
			nRemainingBytes -=2;
		}
		else if ((iCode & 0xF0)==0xE0)	
		{
			iCode1=strUtf8.charCodeAt(nOffset+1);
			iCode2=strUtf8.charCodeAt(nOffset+2);
			if ( nRemainingBytes < 3   ||		
			   (iCode1 & 0xC0) !=0x80 ||		
			   (iCode2 & 0xC0) !=0x80 )
			{
				break;
			}
			bstr+=String.fromCharCode(((iCode & 0x0F) << 12) |
					((iCode1 & 0x3F) <<  6) |
					(iCode2 & 0x3F));
			nOffset+=3;
			nRemainingBytes -=3;
		}
		else
		{
			break;
		}
	}
	if (0 !=nRemainingBytes)
	{
		bstr="";
	}
	return bstr;
}
function SPSoapRequestBuilder(functionName)
{
	var object=new Object();
	function AddParameter(parameterName, parameterValue)
	{
		var index=this.parameterNameList.length;
		this.parameterNameList[index]=parameterName;
		this.parameterValueList[index]=parameterValue;
	}
	function SendSOAPMessage(xmlhttp)
	{
		var funcName=this.functionName;
		var paramNames=this.parameterNameList;
		var paramValues=this.parameterValueList;
		xmlhttp.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
		xmlhttp.setRequestHeader("SOAPAction", "http://microsoft.com/sharepoint/webpartpages/"+funcName);
		var soapData='<?xml version="1.0" encoding="utf-8"?>'+						'<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">'+						'<soap:Body>'+						'<'+funcName+' xmlns="http://microsoft.com/sharepoint/webpartpages">';
		for(var i=0; i < paramNames.length; i++)
		{
			var soapParam=(typeof(paramValues[i])=="string") ? String2XML(paramValues[i]) : paramValues[i];
			soapData+='<'+paramNames[i]+'>'+soapParam+'</'