

//------------------------------------------------
var ThisCallIndex = 1000;
function MakeQJaxCalls(ThisCallURL, TheAction, TheArgument, TheMode)
{    
	alert(ThisCallURL);
	//ZInfo(ThisCallURL, TheAction, TheArgument, TheMode);
	ThisCallIndex = ThisCallIndex 	+ 1;
	var InsertString;
	
    var MyRegularExpression=/^(.*)\#[^\#]*$/;
    ThisCallURL = ThisCallURL.replace(MyRegularExpression,"$1");    
	alert(ThisCallURL);
	var SomeAction = "";
	if(typeof TheAction == "undefined")
	{
		TheAction = "";
	}
	if(typeof TheMode == "undefined")
	{
		TheMode = "CALL";
	}
	if(typeof TheArgument == "undefined")
	{
		TheArgument = "";
	}
	if(TheAction != "")
	{
		if(TheMode == "CALL")
		{
			if(TheArgument == "")
			{
				SomeAction = TheAction + "(this.value);";
				//SomeAction = TheAction + "(this.innerText);";
			}
			else
			{
				SomeAction = TheAction + "(this.value" + ",\'" + ThisCallURL + "\'" + ",\'" + TheArgument + "\');";
				//SomeAction = TheAction + "(this.innerText" + ",\'" + ThisCallURL + "\'" + ",\'" + TheArgument + "\');";
				//alert("MakeQJ"+SomeAction);
			}
		}
		else if(TheMode == "ASSIGN")
		{
			SomeAction = TheAction + "=(this.innerText);";
		}
	}
	InsertString = "<DIV id='TEST" + ThisCallIndex + "' style='display:none;visibility:hidden' onclick='javascript:GetQx(\"" + ThisCallURL + "\", \"TEST" + ThisCallIndex+ "HANDLER\")'>NONE<TEXTAREA id=\"TEST" + ThisCallIndex + "HANDLER\" onchange=\"" + SomeAction + "document.getElementById('TEST" + ThisCallIndex + "').outerHTML='';\"></TEXTAREA></DIV>";  
	document.getElementById("qjax").insertAdjacentHTML('beforeEnd', InsertString);
	//if(parent.parent.IsAdvancedBrowser())
	document.getElementById("TEST" + ThisCallIndex).click();
	/*else
	{
		var evt = document.createEvent("MouseEvents");
  		evt.initMouseEvent("click", true, true, window,0, 0, 0, 0, 0, false, false, false, false, 0, null);
  		var cb = document.getElementById("TEST" + ThisCallIndex); 
  		var canceled = cb.dispatchEvent(evt);
  	}*/
  	alert(InsertString);

}


var WhoToBeToldArrays = new Array(100)
var WhoRequestedArrays = new Array(100)
var SomeCall = 0;
var CallArrays = new Array(100)
var ArgumentArrays = new Array(100)
var HeaderOption = new Array(100)
function GetQx(SomeURL, WhoToBeToldDiv, ArgumentGiven)
{
	var e;
	if(!e){e=window.event;}
	//ZInfo(SomeURL, WhoToBeToldDiv, ArgumentGiven);
	try
	{
		var RegularExpression=/^\-/;
	  	CallArrays[SomeCall] = 'Waiting...';
	  	WhoRequestedArrays[SomeCall] = e.srcElement.id; 
	  	if(WhoToBeToldDiv == '')
	  	{
		  	WhoToBeToldArrays[SomeCall] = e.srcElement.id; 
	  	}
	  	else
	  	{
		  	WhoToBeToldArrays[SomeCall] = WhoToBeToldDiv; 
	  	}
	  	if(typeof ArgumentGiven == 'undefined')
	  	{
	  		ArgumentArrays[SomeCall] = "";
	  	}
	  	else
	  	{
	  		ArgumentArrays[SomeCall] = ArgumentGiven;
	  	}
		if(SomeURL.match('^\s*-'))
		{
			SomeURL=SomeURL.substring(1);
			http.open("HEAD", SomeURL, true);
			HeaderOption[SomeCall]="Last-Modified"; 
		}
		else
		{
			http.open("GET", SomeURL, true);
			HeaderOption[SomeCall]="body";
		}
		var  SomeFunctionDefinition = "DoResult(" + String(SomeCall) + ");";
		SomeCall = SomeCall + 1;
		if(SomeCall == 100)
		{
			SomeCall = 0;
		}
		var SomeNewFunction = new Function(SomeFunctionDefinition) ;
		//alert("SomeNewFunction = "+SomeNewFunction); 
	  	http.onreadystatechange = SomeNewFunction;
	  	http.send(null);

	}
	catch(err)
	{
		// To cancel that call.
		DoResult(SomeCall, true);
	}
}

function DoResult(SomeInt, IsCallFailedFlag)
{
	if(typeof IsCallFailedFlag == "undefined")
	{
		IsCallFailedFlag = false;
	}
	if ((http.readyState == 4) || (IsCallFailedFlag == true))
	{
		if(IsCallFailedFlag == true)
		{
			CallArrays[SomeInt] = "CallFailed";		
			//alert("Call Failed");
		}		
		else if(HeaderOption[SomeInt] == "Last-Modified")
		{
			CallArrays[SomeInt] = http.getResponseHeader("Last-Modified");
		}
		else if(HeaderOption[SomeInt] == "body")
		{
			try
			{
				CallArrays[SomeInt] = http.responseText;
			}
			catch(err)
			{
				CallArrays[SomeInt] = "";
			}
		}
		else
		{
			return;
		}
		//Alert('Header of file : '+http.getAllResponseHeaders());	
		if
		(
			(document.getElementById(WhoToBeToldArrays[SomeInt]).tagName == 'INPUT')
		)
		{
			document.getElementById(WhoToBeToldArrays[SomeInt]).value = escape(CallArrays[SomeInt]) ;		
			document.getElementById(WhoToBeToldArrays[SomeInt]).onchange();
		}
		else if
		(
			(document.getElementById(WhoToBeToldArrays[SomeInt]).tagName == 'TEXTAREA')
		)
		{
			document.getElementById(WhoToBeToldArrays[SomeInt]).value = escape(CallArrays[SomeInt]) ;		
			document.getElementById(WhoToBeToldArrays[SomeInt]).onchange();
		}
		else
		{
			document.getElementById(WhoToBeToldArrays[SomeInt]).innerHTML = CallArrays[SomeInt] ;
			document.getElementById(WhoToBeToldArrays[SomeInt]).onchange();
		}
	}
}

function FindDivParent(SomeSourceElementControl)
{
	var sourceElementControl = SomeSourceElementControl;
	// should not step through above body.
	while(	(sourceElementControl.tagName != "DIV")
			&&(sourceElementControl.tagName != "SPAN")
			&&(sourceElementControl.tagName != "BODY")
		  )
	{ 
		sourceElementControl = sourceElementControl.parentElement;
	}	
	return(sourceElementControl);
}

/*function NetStencil(SomeString,SomeFlag)
{
 	var StencilCode= SomeString;
    var date = new Date();
	var  KeyValue='Stencil';
	KeyValue+=date.getTime();
	var MaxValue=1000;
	var RandomNumber = Math.round(Math.random()*MaxValue);
	KeyValue+=RandomNumber;
	if(SomeFlag==true)
	{
		UpdateNetVariables(KeyValue,StencilCode,'Global');
	}
	else
	{
		UpdateNetVariables(KeyValue,StencilCode);
	}

}*/

function NetCustomStencil(CategoryName,SomeString,SomeFlag,SomeNetID)
{
 	if(typeof SomeFlag == undefined)
 	{
 		SomeFlag = false;
 	}
 	if(typeof CategoryName== undefined)
 	{
 		CategoryName= "";
 	}
 	if(typeof SomeNetID== undefined)
 	{
 		SomeNetID= "";
 	}

 	var StencilCode= SomeString;
    var date = new Date();
//org	var  KeyValue='priya_pak@yahoo.com^^'; // change with the current user id variable
	var  KeyValue=SomeNetID +'^^';
	KeyValue+=date.getTime();
	var MaxValue=1000;
	var RandomNumber = Math.round(Math.random()*MaxValue);
	KeyValue+=RandomNumber;
	if(SomeFlag==true)
	{
		UpdateNetVariables("GlobalList",CategoryName,"123","GLOBALSTENCIL");
		//CategoryName=CategoryName+"_123";
		UpdateNetVariables("CategoryList",KeyValue,SomeString,CategoryName);
		//Dummy(KeyValue,SomeString,CategoryName);
		
	}
	else
	{
		UpdateNetVariables("",KeyValue,StencilCode);
	}
}
/*function Dummy(KeyValue,SomeString,CategoryName)
{
	UpdateGlobalList(KeyValue,SomeString,CategoryName);
	//UpdateNetVariables("CategoryList",KeyValue,SomeString,CategoryName);

}
function UpdateGlobalList(SomeKey,SomeValue,SomeID)
{
	var ActionString = "http://216.165.209.224:8080/NetVariable";
	var CreateForms='';
	var SomeIFrameName = CreateNewIFrameNo();
	var SomeFormName = "Form" + SomeIFrameName;
	CreateForms = "<FORM name='"+ SomeFormName + "' id='" + SomeFormName + "' target='"+SomeIFrameName+"' action='" + ActionString +"' method='post' >";
	CreateForms=CreateForms + "<input Name='"+SomeKey+"' type='hidden' value='" +escape(SomeValue)+ "'/>";
	CreateForms=CreateForms + "<input Name='NETID'  type='hidden' value='"+SomeID+"' />";
	CreateForms=CreateForms + "<input Name='action'  type='hidden' value='SET' />";
	CreateForms=CreateForms +"</FORM>";
	document.getElementById("FormContent").innerHTML = CreateForms;
	document.all(SomeFormName).submit();
	setTimeout("KillForm_2('"+SomeIFrameName+"')",500);
	CreateForms="";
}
var SomeIFrameNo = 0;
function CreateNewIFrameNo()
{
	SomeIFrameNo = SomeIFrameNo + 1;
	var NewIFrameNo="<IFRAME ID='IFrame" + SomeIFrameNo + "' name='IFrame" + SomeIFrameNo + "' FRAMEBORDER=0 SCROLLING=NO SRC=''></IFRAME>";
	document.getElementById("FormHolder").insertAdjacentHTML('beforeEnd', NewIFrameNo);
	return("IFrame" + SomeIFrameNo );
}
function KillForm_2(SomeIFrameName)
{
	var FormName = "Form"+SomeIFrameName 
	document.all(FormName).innerHTML="";
	SomeIFrameName.innerHTML="";	
}*/


function UpdateNetVariables(SomeList,SomeKey,SomeValue,SomeID)
{
	if(SomeID == undefined)
	{
		SomeID=ActualNetID;
	}
	if(SomeList == "")
	{
		SomeList="CustomList";
	}
	if( SomeList!="GlobalList")
	{
		var ActionString = "http://nv.zcubes.com:8080/NetVariable";
		//var ActionString = "http://216.165.209.224:8080/NetVariable";
		var CreateForms='';
		var SomeIFrameName = CreateNewIFrame();
		var SomeFormName = "Form" + SomeIFrameName;
		CreateForms = "<FORM name='"+ SomeFormName + "' id='" + SomeFormName + "' target='"+SomeIFrameName+"' action='" + ActionString +"' method='post' >";
		CreateForms=CreateForms + "<input Name='"+SomeKey+"' type='hidden' value='" +escape(SomeValue)+ "'/>";
		CreateForms=CreateForms + "<input Name='NETID'  type='hidden' value='"+SomeID+"' />";
		CreateForms=CreateForms + "<input Name='action'  type='hidden' value='SET' />";
		CreateForms=CreateForms +"</FORM>";
		document.getElementById("FormContent").innerHTML = CreateForms;
		document.all(SomeFormName).submit();
		setTimeout("KillForm_1('"+SomeIFrameName+"')",500);
		CreateForms="";
	 }
	 else
	 { 
		  var ActionString = "http://nv.zcubes.com:8080/NetVariable?NETID="+SomeID+"&action=SET&"+SomeKey+"="+SomeValue;
		  var NewCallLink = "http://www.zcubes.com/Manage/GetRemoteContent.aspx?link=" + escape(ActionString) + "&type=content";
		  MakeQJaxCalls(NewCallLink,"TestFunction");
	 }
}
var SomeIFrame = 0;
function CreateNewIFrame()
{
	SomeIFrame = SomeIFrame + 1;
	var NewIFrame="<IFRAME ID='IFrame" + SomeIFrame + "' name='IFrame" + SomeIFrame + "' FRAMEBORDER=0 SCROLLING=NO SRC=''></IFRAME>";
	document.getElementById("FormHolder").insertAdjacentHTML('beforeEnd', NewIFrame);
	return("IFrame" + SomeIFrame);
}
function KillForm_1(SomeIFrameName)
{
	var FormName = "Form"+SomeIFrameName 
	document.all(FormName).innerHTML="";
	SomeIFrameName.innerHTML="";	
}
function TestFunction()
{
}
function SelectStencil(SomeID,SomeText)
{
	var StencilZnote = parent.parent.ApplyFunctionToGlobalZList("ZGet","IsStencilZnote");
	if(StencilZnote != "")
	{
		parent.parent.ZK(parent.parent.ParseAndGetID(StencilZnote));
	}
	if(SomeID != 'Custom_Stencil'  && SomeID != 'Global_Stencil')
	{
		StencilZnote=parent.parent.MoveTo(parent.parent.ZMakeSystemBox(parent.parent.AddContentCodePlusIFRAMEAndExpand( parent.parent.ThisServer+"/zboard/Stencil/"+SomeID+".htm"),SomeText),"232","110","200","200");
		parent.parent.ZSet(StencilZnote, "IsStencilZnote", true);	
	}
	else
	{
		//org ActualNetID = parent.parent.GetLoggedInUser();
		ActualNetID= GetUserUIN();
		if (ActualNetID != "" && ActualNetID !=null)
		{ 
			StencilZnote=parent.parent.MoveTo(parent.parent.ZMakeSystemBox(parent.parent.AddContentCodePlusIFRAMEAndExpand( parent.parent.ThisServer+"/zboard/Stencil/"+SomeID+".htm"),SomeText),"232","110","350","250");
			parent.parent.ZSet(StencilZnote, "IsStencilZnote", true);
		}
		/* org else
		{
    		alert("please login to see stencil");
		}*/
	}
	//parent.parent.ZSet(StencilZnote, "IsStencilZnote", true);
	parent.parent.GetEventCancelled();	
}
//-----------------------------


function getHTTPObject() {
 /*@cc_on
  @if (@_jscript_version >= 5)
    try 
    {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } 
    catch (e) 
    {
      try 
      {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

      }
      catch (E) 
      {
        xmlhttp = false;
      }
    }
  @else
	  xmlhttp = false;
  @end @*/
  var xmlhttp;
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
    } 
    catch (e) 
    {
      xmlhttp = false;
    }
  }
  return xmlhttp;
}
var http = getHTTPObject(); // Make the HTTP Object
function IsLink(SomeString){return((IsStartsWith(SomeString , 'http://') == true)||(IsStartsWith(SomeString , 'https://') == true));}
function CloseIt()
{
	var ZCubesSession = GetConfigSetting('ZCubes_Exit', 'Yes');
	if(ZCubesSession == 'Yes')
	{
		//event.returnValue = 'You have made changes to your ZSpace.\n\n1. Press [Cancel] to stay in ZCubes. \n2. Press [OK] to leave ZCubes and go to the new site.\n\nZTips:\n(a) [Shift+Left Button Click] can open a hyperlink in a new browser window.\n(b) If you press [Shift] while dropping a link into ZSpace, you can open the website in the "Cute" mode.';
		//event.returnValue = 'You have made changes to your ZSpace.\n\n1. Press [Cancel] to stay in ZCubes. \n2. Press [OK] to leave ZCubes and go to the new site.';
		event.returnValue = 'You have made changes to your ZSpace.\n';
		
		//(c) You can also drag a link to the ZSpace with [Ctrl] key pressed to load it into the ZSpace Browser.
	}
}
//var SomeLookupArray = new Array(new Array('g.', true, 'http://www.google.com/search?query=', ''),new Array('msnq.', true, 'http://search.msn.com/results.aspx?q=', ''),new Array('y.', true, 'http://search.yahoo.com/search?p=' , ''),new Array('ams.', true, 'http://www.amazon.com/gp/search/ref=nb_ss_gw/102-4931566-3663363?url=search-alias%3Daps&field-keywords=', '&Go.x=0&Go.y=0'),new Array('es.', true, 'http://search.ebay.com/search/search.dll?from=R40&satitle='  , ''),new Array('mm.', true, 'http://search.msdn.microsoft.com/search/default.aspx?siteId=0&tab=0&query=' , ''),new Array('mx.', true, 'https://mail.bitsofcode.com/exchange' , ''),new Array('b.', true, 'http://www.bitsofcode.com' , ''),new Array('we.', true, 'http://www.weather.com/' , ''),new Array('amc.', true, 'http://www.amctheatres.com/' , ''),new Array('boc.', true, 'http://www.bitsofcode.com' , ''),new Array('ms.', true, 'http://www.microsoft.com' , ''),new Array('am.', true, 'http://www.amazon.com' , ''),new Array('bb.', true, 'http://www.bestbuy.com/' , ''),new Array('cc.', true, 'http://www.circuitcity.com/' , ''),new Array('cu.', true, 'http://www.compusa.com/' , ''),new Array('e.', true, 'http://www.ebay.com' , ''),new Array('wal.', true, 'http://www.walmart.com/' , ''),new Array('a.', true, 'http://search.aol.com/' , ''),new Array('msns.', true, 'http://search.msn.com/' , ''),new Array('g.', true, 'http://www.google.com' , ''),new Array('bn.', true, 'http://news.bbc.co.uk/' , ''),new Array('gn.', true, 'http://news.google.com/' , ''),new Array('yn.', true, 'http://news.yahoo.com/' , ''),new Array('cnn.', true, 'http://www.cnn.com/' , ''),new Array('nt.', true, 'http://www.nytimes.com/' , ''),new Array('gm.', true, 'http://maps.google.com' , ''),new Array('yam.', true, 'http://maps.yahoo.com' , ''),new Array('mq.', true, 'http://www.mapquest.com ' , ''),new Array('mqd.', true, 'http://www.mapquest.com/directions/' , ''),new Array('ym.', true, 'http://mail.yahoo.com' , ''),new Array('h.', true, 'http://www.hotmail.com' , ''),new Array('aol.', true, 'http://www.aol.com/' , ''),new Array('bbc.', true, 'http://www.bbc.co.uk/?ok' , ''),new Array('msn.', true, 'http://www.msn.com' , ''),new Array('ns.', true, 'http://www.netscape.com/' , ''),new Array('y.', true, 'http://www.yahoo.com' , ''),new Array('en.', true, 'http://en.wikipedia.org/wiki/Main_Page' , ''),new Array('dow.', true, 'http://www.download.com/' , ''),new Array('di.', true, 'http://dictionary.cambridge.org/' , ''),new Array('ent.', true, 'http://www.enterprise.com/car_rental/' , ''),new Array('j.', true, 'http://www.justlisted.com' , ''),new Array('z.', true, 'http://service.spiderbrowse.com/zsave/zcategorydefault/default.asp?localpath=', ''),new Array('d.', true, 'http://www.google.com/search?query=define:', ''),new Array('wi.', true, 'http://en.wikipedia.org/wiki/', ''));
var SomeLookupArray = new Array(new Array('z.', true, 'http://service.spiderbrowse.com/zsave/zcategorydefault/default.asp?localpath=', ''),new Array('g.', true, 'http://www.google.com/search?query=', ''),new Array('gm.', true, 'http://maps.google.com/', ''),new Array('gn.', true, 'http://news.google.com/', ''),new Array('m.', true, 'http://search.msn.com/results.aspx?q=', ''),new Array('y.', true, 'http://search.yahoo.com/search?p=' , ''),new Array('e.', true, 'http://search.ebay.com/search/search.dll?satitle=', ''),new Array('d.', true, 'http://www.google.com/search?query=define:', ''),new Array('mm.', true, 'http://search.msdn.microsoft.com/search/default.aspx?siteId=0&tab=0&query=' , ''),new Array('a.', true, 'http://www.aol.com/' , ''),new Array('cnn.', true, 'http://www.cnn.com/' , ''),new Array('fnc.', true, 'http://www.foxnews.com/' , ''),new Array('bbc.', true, 'http://news.bbc.co.uk/' , ''),new Array('enfl.', true, 'http://sports.espn.go.com/nfl/index', ''),new Array('bb.', true, 'http://www.bestbuy.com/' , ''),new Array('cc.', true, 'http://www.circuitcity.com/' , ''));
function IsHttpOrHttps(SomeLink)
{
	if((IsStartsWith(SomeLink, "http://") == true) || (IsStartsWith(SomeLink, "https://") == true))
	{
		return true;
	}
	else
	{
		return false;
	}
}




