﻿//--AJAX BRICK 1.30 BETA 1-------------------------------------------------
//--RED TOY BRICKS-- 2007


//--[BASE]BaseFunction-----------------------------------------------------------
var sHttpRequest;
var sOutPutPanel;
var sVisFlag;

//[]Main function
//[]pURL       - URL
//[]pDispPanel - Write data panel
//[]pVisFlag   - Data start and end flag - Data source flag
function sendRequestBase(pURL,pDispPanel,pVisFlag)
{
	pURL=pURL+"&CacheKiller="+getCookieValue(pURL.split(".")[0]);
	//alert(pURL+" * "+pURL.split(".")[0]);
	sOutPutPanel=document.getElementById(pDispPanel);
	sVisFlag=pVisFlag;
	
	try
	{sHttpRequest=new ActiveXObject("microsoft.XMLHTTP");}
	catch(e)
	{sHttpRequest=new ActiveXObject("Msxml2.XMLHTTP");}
	sHttpRequest.open("GET",pURL);
	sHttpRequest.onreadystatechange=sendCallBackBase;
	sHttpRequest.send(null);

}

//[]Call back function
function sendCallBackBase()
{
	//alert(sHttpRequest.responseText);
	if(sHttpRequest.readyState==4)
	{
		if(getDataFromRequestByFlagBaes(sHttpRequest.responseText,sVisFlag).indexOf("sendRequestBase")>=0)
		{sOutPutPanel.innerHTML=getDataFromRequestByFlagBaes(sHttpRequest.responseText,sVisFlag);}
		else
		{sOutPutPanel.innerHTML="<div class='UnButStyleR01'>Non data has been load.<div>";}
	}
	else
	{sOutPutPanel.innerHTML="<div class='UnButStyleR01'>LOADING...<div>"+sOutPutPanel.innerHTML;}

}

//[]Part function
//[]Get data from request by flag , single find - find by flag
//<!--S."+pDisp+"-->
//<!--E."+pDisp+"-->
function getDataFromRequestByFlagBaes(pSource,pVisFlag)
{
	var outPutData="";
	var startFlag="<!--S."+pVisFlag+"-->";
	var endFlag="<!--E."+pVisFlag+"-->";
	var startIndex=0;
	var endIndex=0;
	//[]
	startIndex=pSource.indexOf(startFlag)+startFlag.length;
	endIndex=pSource.indexOf(endFlag);
	outPutData=pSource.substr(startIndex,endIndex-startIndex);
	

	return outPutData;
}



//[]
function getCookieValue(pCookieName)
{
	var retCode=0;
	//[]Initial parameter
	var Coun=0;
	
	var tmpSTR="";
	var tmpSplitSTR=";";
	var tmpSTRARRR01;
	var tmpSTRARRR02;
	//[]Split COOKIES STR
	//alert(document.cookie);
	tmpSTRARRR01=document.cookie.split(tmpSplitSTR);
	//[]Wheel cookies
	Coun=0;
	while(tmpSTRARRR01.length>Coun)
	{
		tmpSTRARRR02=tmpSTRARRR01[Coun].replace(";").split("=");
		if(tmpSTRARRR02[0]==pCookieName || tmpSTRARRR02[0]==" "+pCookieName)
		{retCode=tmpSTRARRR02[1];}
		Coun++;
	}

	
	return retCode;
}