
function displayBlockForHistory(){
	//////////alert("loading displayBlockForHistory");
		openHistoryBlock('My History', '', '','','750','440','');
	}
	function displayBlockForDownload(){
	//////////alert("loading displayBlockForHistory");
		openDownloadBlock('My History', '', '','','750','440','');
	}
	function displayBlockForTraining(){
	//////////alert("loading displayBlockForHistory");
		opentrainingBlock('My History', '', '','','750','440','');
	}
	function displayBlockForNotes(){
	//////////alert("loading displayBlockForHistory");
		openNotesBlock('My History', '', '','','750','440','');
	}

function openHistoryBlock(window_title,blockDiagUrl,code,psp_URL,width,height,fastpreview){
				var url = "/webapp/history/fetchHistory.sp";
			//////alert("loading openHistoryBlock");
			if(document.getElementById('historyajaxbox')!=null)
	     {
			document.getElementById("dhtmlwindowholder").removeChild(document.getElementById('historyajaxbox'));
			
			
			}
		ajaxwinhistory=dhtmlwindow.open('historyajaxbox',url,window_title, 'width='+width+'px,height='+height+'px,left=83px,top=64px','history');
		//////alert(document.getElementbyId('ajaxbox').style.zIndex);
		//ajaxwinhistory.style.overflowX="hidden";
	//ajaxwinhistory.style.overflowY="auto";
		ajaxwinhistory.style.zIndex=51;
		//ajaxwinhistory.style.overflowY ="auto";
		//ajaxwinhistory.style.overflowX="hidden";
		/* dcsMultiTrack('DCS.dcsuri',blockDiagUrl,'WT.ti','Block Diagram View','DCS.dcsref',psp_URL,'WT.dl','1'); */
		return ajaxwinhistory ;
	}
	function openDownloadBlock(window_title,blockDiagUrl,code,psp_URL,width,height,fastpreview){
				var url = "/webapp/history/fetchHistory.sp?commandID=FETCH_DOWNLOAD";
			//	////////alert("loading openHistoryBlock");
			if(document.getElementById('historyajaxbox')!=null)
	     {
			document.getElementById("dhtmlwindowholder").removeChild(document.getElementById('historyajaxbox'));
			
			
			}
		ajaxwinhistory=dhtmlwindow.open('historyajaxbox',url,window_title, 'width='+width+'px,height='+height+'px,left=83px,top=64px','downloaded');
		/* dcsMultiTrack('DCS.dcsuri',blockDiagUrl,'WT.ti','Block Diagram View','DCS.dcsref',psp_URL,'WT.dl','1'); */
		ajaxwinhistory.style.zIndex=51;
		return ajaxwinhistory ;
	}
	function opentrainingBlock(window_title,blockDiagUrl,code,psp_URL,width,height,fastpreview){
				var url = "/webapp/history/fetchHistory.sp?commandID=FETCH_LAUNCH_TRNG";
			//	////////alert("loading openHistoryBlock");
			if(document.getElementById('historyajaxbox')!=null)
	     {
			document.getElementById("dhtmlwindowholder").removeChild(document.getElementById('historyajaxbox'));
			
			}
		ajaxwinhistory=dhtmlwindow.open('historyajaxbox',url,window_title, 'width='+width+'px,height='+height+'px,left=83px,top=64px','training');
		/* dcsMultiTrack('DCS.dcsuri',blockDiagUrl,'WT.ti','Block Diagram View','DCS.dcsref',psp_URL,'WT.dl','1'); */
		ajaxwinhistory.style.zIndex=51;
		return ajaxwinhistory ;
	}
	function openNotesBlock(window_title,blockDiagUrl,code,psp_URL,width,height,fastpreview){
				var url = "/webapp/history/fetchHistory.sp?commandID=FETCH_WEBNOTES_HISTORY";
			//	////////alert("loading openHistoryBlock");
			if(document.getElementById('historyajaxbox')!=null)
	     {
			document.getElementById("dhtmlwindowholder").removeChild(document.getElementById('historyajaxbox'));
			
			
			}
		ajaxwinhistory=dhtmlwindow.open('historyajaxbox',url,window_title, 'width='+width+'px,height='+height+'px,left=83px,top=64px','webnote');
		/* dcsMultiTrack('DCS.dcsuri',blockDiagUrl,'WT.ti','Block Diagram View','DCS.dcsref',psp_URL,'WT.dl','1'); */
		ajaxwinhistory.style.zIndex=51;
		return ajaxwinhistory ;
	}


//////////////alert("request ajax js");

var Request = new Object();

Request.queue = [];

Request.readyState = true;

Request.timeOut = null;

Request.processQueue = function() {
	if (Request.queue.length > 0) {
		if (Request.readyState == true) {
			var params = Request.queue.shift();
			Request.readyState = false;
			Request.send (params.url, params.method, params.callback, params.data, params.urlencoded, params.name);
			Request.timeOut = setTimeout(Request.processQueue, 20);
		} else {
			Request.timeOut = setTimeout(Request.processQueue, 20);
		}
	} else {
		Request.timeOut = null;
	}
}

Request.queueUrl = function(url, method, data, callback, args, urlencoded, name) {
	var params = new Object();
	params.url = url;
	params.method = method;
	params.callback = callback;
	params.data = data;
	params.urlencoded = urlencoded;
	params.name = name;
	Request.queue.push(params);
	if (Request.timeOut == null) {
		Request.timeOut = setTimeout(Request.processQueue, 20);
	}
	return params;
}

Request.send = function(url, method, data, callback, args, urlencoded, name) {
	 //////////////alert('requesting : ' + url);
	var req;
	if (window.XMLHttpRequest) {
		req = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		req = new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (typeof name == "undefined") {
		name = "";
	} else {
		name += "\n";
	}




	var readychange = function() {
		if (req.readyState == 4) {// only if req shows "loaded"
			if (req.status < 400) {// only if "OK"
					callback(req,args);
					delete callback;
			} else if (typeof req == "undefined" || typeof req.status == "undefined") {
				// don't do anything. user has navigated away
				delete callback;
			} else if (req.status == 401) { // unauthorized
				////////////alert(_("Session Expired. You would need to relogin"));
				delete callback;
				//window.location.href = "/webapp/";
			} else if (req.status == 404) {
				// should not happen, but ignore it for now
			} else {
				switch(req.status) {
					// windows error codes
					case 12002: // server timeout
					case 12029: case 12030: case 12031: // dropped connection
					case 12152: // connection closed by server
					case 13030:
						////////////alert(name + _("There was a network problem. Please reload the page."));
						break;
					case 500: case 503:
						////////////alert(name + _("There was an internal server error. Please try later."));
						break;
					default:
						////////////alert(_("There was a problem loading data:") + "\nstatus: " + req.status+ "/" + req.statusText + "\n" + url);

				}
				delete callback;
			}
			Request.readyState = true;
		}
	};
	function do_request() {
		if (method=="POST") {
			req.open("POST", url, true);
			if (urlencoded) req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			req.onreadystatechange = readychange;
			req.send(data);
		} else {
			req.open("GET", url, true);
			req.onreadystatechange = readychange;
			req.send(null);
		}
	};
	do_request();
	return req;
}

Request.sendRawPOST = function(url, data, callback, args, name) {
	Request.send(url, "POST", data, callback, args, false, name);
}
Request.sendPOST = function(url, data, callback, args, name) {
	Request.send(url, "POST", data, callback, args, true, name);
}
Request.sendGET = function(url,  callback, args, name) {
	// ////////////alert('within sendGET');
	return Request.send(url, "GET", '', callback, args, name);
}
function getKey(varName){
	var varName_a = new Array();
	varName_a = varName.split('<;>');
	////////alert(varName_a[0]);
	////////alert(""+varName_a[1]);

	
	return varName_a;
}
function callbackBROWSE_WEBPAGE(response)
{
var mdiv = document.getElementById('BROWSE_WEBPAGE');
var mdiv1=document.getElementById('button_WEBPAGE');
var key=getKey(response.responseText);
if(typeof key[1] != 'undefined' && key[1] != null)
	{////////alert(" key[1] != 'undefined'");
mdiv.innerHTML=key[0];
mdiv.style.height="22.1em";
mdiv1.innerHTML=key[1];
	}
 else
	{
     ////////alert(" key[1] =undefined'");
	mdiv.innerHTML=key[0];
 mdiv1.style.display='none';
	}
};
function callbackDownLoad(response)
{var mdiv = document.getElementById('DOWNLOAD');
var mdiv1=document.getElementById('button_undefined');
var key=getKey(response.responseText);
if(typeof key[1] != 'undefined' && key[1] != null)
	{////////alert(" key[1] != 'undefined'");
mdiv.innerHTML=key[0];
mdiv.style.height="27.2em";
mdiv1.innerHTML=key[1];
	}
 else
	{
     ////////alert(" key[1] =undefined'");
	mdiv.innerHTML=key[0];
 mdiv1.style.display='none';
	}
}
function callbackWATCH_VIDEO(response)
{var mdiv = document.getElementById('WATCH_VIDEO');
var mdiv1=document.getElementById('button_VIDEO');
var key=getKey(response.responseText);
if(typeof key[1] != 'undefined' && key[1] != null)
	{////////alert(" key[1] != 'undefined'");
mdiv.innerHTML=key[0];
mdiv.style.height="22.1em";
mdiv1.innerHTML=key[1];
	}
 else
	{
     ////////alert(" key[1] =undefined'");
	mdiv.innerHTML=key[0];
 mdiv1.style.display='none';
	}

}
function callbackWEBNOTES_HISTORY(response)
{
	var mdiv = document.getElementById('WEBNOTES_HISTORY');
var mdiv1=document.getElementById('button_HISTORY');
var key=getKey(unescape(response.responseText));
if(typeof key[1] != 'undefined' && key[1] != null)
	{////////alert(" key[1] != 'undefined'");
mdiv.innerHTML=key[0];
mdiv.style.height="23.4em";
mdiv1.innerHTML=key[1];
	}
 else
	{
     ////////alert(" key[1] =undefined'");
	mdiv.innerHTML=key[0];
 mdiv1.style.display='none';
	}
	var notesCnt = document.getElementById('totalNotesCnt').value;
			//////alert('notesCnt:'+notesCnt);
			for(i=0;i<notesCnt; i++){
				var noteId = 'noteBody'+i;
				////alert(noteId);
				////alert(document.getElementById(noteId).innerHTML);
             
				//var unesc=document.getElementById(noteId).innerHTML;
				if(document.getElementById(noteId).innerHTML.length>30)
				{////alert("length is >25")
				document.getElementById(noteId).innerHTML=document.getElementById(noteId).innerHTML.substring(0,29)+"...";
				}
				

				var anchId = 'anch'+i;
				////alert(noteId);
				////alert(document.getElementById(noteId).innerHTML);
				if(document.getElementById(anchId).title>250)
				{////alert("length is >250")
				document.getElementById(anchId).title = document.getElementById(anchId).title.substring(0,249);
				}

}


}
function callbackLAUNCH_TRNG(response)
{var mdiv = document.getElementById('LAUNCH_TRNG');
var mdiv1=document.getElementById('button_TRNG');
var key=getKey(response.responseText);
if(typeof key[1] != 'undefined' && key[1] != null)
	{////////alert(" key[1] != 'undefined'");
mdiv.innerHTML=key[0];
mdiv.style.height="22.1em";
mdiv1.innerHTML=key[1];
	}
 else
	{
    mdiv.innerHTML=key[0];
 mdiv1.style.display='none';
	}
}
function ajaxcallforBROWSE_WEBPAGE(commandID,img_id,td_id,fid,buttonid){
	 
	minmax(commandID,img_id,td_id,fid,buttonid);
	var nObj = document.getElementById(commandID);
if(nObj!=null&&nObj.innerHTML=='')
	 {
	progressbar(commandID,nObj);
	 Request.sendPOST('/webapp/history/fetchHistory.sp','commandID=FETCH_'+commandID+'&sectionView=true',callbackBROWSE_WEBPAGE); 
	 }
 }
 function ajaxcallforDownLoad(commandID,img_id,td_id,fid,buttonid){
minmax(commandID,img_id,td_id,fid,buttonid);
var nObj = document.getElementById(commandID);
if(nObj!=null&&nObj.innerHTML=='')
	 {
	progressbar(commandID,nObj);
Request.sendPOST('/webapp/history/fetchHistory.sp','commandID=FETCH_'+commandID+'&sectionView=true',callbackDownLoad);  
	 }
 }
 function ajaxcallforWATCH_VIDEO(commandID,img_id,td_id,fid,buttonid){
minmax(commandID,img_id,td_id,fid,buttonid);
var nObj = document.getElementById(commandID);
if(nObj!=null&&nObj.innerHTML=='')
	 {
	progressbar(commandID,nObj);
Request.sendPOST('/webapp/history/fetchHistory.sp','commandID=FETCH_'+commandID+'&sectionView=true',callbackWATCH_VIDEO);
}
 }

 function ajaxcallforWEBNOTES_HISTORY(commandID,img_id,td_id,fid,buttonid){
minmax(commandID,img_id,td_id,fid,buttonid);
var nObj = document.getElementById(commandID);
if(nObj!=null&&nObj.innerHTML=='')
	 {
	progressbar(commandID,nObj);
Request.sendPOST('/webapp/history/fetchHistory.sp','commandID=FETCH_'+commandID+'&sectionView=true',callbackWEBNOTES_HISTORY);
 }
 }
 function ajaxcallforLAUNCH_TRNG(commandID,img_id,td_id,fid,buttonid){
	 	minmax(commandID,img_id,td_id,fid,buttonid);
		var nObj = document.getElementById(commandID);
if(nObj!=null&&nObj.innerHTML=='')
	 {
	progressbar(commandID,nObj);
Request.sendPOST('/webapp/history/fetchHistory.sp','commandID=FETCH_'+commandID+'&sectionView=true',callbackLAUNCH_TRNG);
	}
 }
function minmax(div_id,img_id,td_id,fid,buttonid)
{
   if(document.getElementById(div_id).style.display=='none')
	{
	document.getElementById(img_id).src="/shared/images/minus.JPG";
        document.getElementById(td_id).setAttribute("bgColor","#535E7C");
		document.getElementById(fid).setAttribute("color","#BDCDDA");
		document.getElementById(div_id).style.display="block";
		if(document.getElementById(buttonid) != 'undefined' && document.getElementById(buttonid) != null)
		{
		document.getElementById(buttonid).style.display="block";
		}

	}
	else
	{
	 document.getElementById(img_id).src="/shared/images/plus.JPG";
	 document.getElementById(td_id).setAttribute("bgColor","#E6EBEF");
	 document.getElementById(fid).setAttribute("color","#657B90");
     document.getElementById(div_id).style.display='none';
    if(document.getElementById(buttonid) != 'undefined' && document.getElementById(buttonid) != null)
		{
	 document.getElementById(buttonid).style.display='none';
		}
	}


}

function progressbar(commandID,nObj)
{
var div_id="progressid"+commandID;
        nObj.innerHTML="<div id='"+div_id+"'></div>";
   var progressdiv=document.getElementById(div_id);
	if(typeof progressdiv != "undefined" && progressdiv != null)
	{
		//alert("progressdiv");
	progressdiv.style.visibility="visible";
	progressdiv.innerHTML=" <img style=\"padding-left:200px\" src=\"/shared/images/fs_anilogo.gif\" />";
    progressdiv.style.position="relative";
	}
}


function displayHistoryHelp(code){ 
		var url = "/webapp/shared/components/inc_collateral.jsp?code="+code;
		var window_title = "FAQ"
		var width = "550";
		var height = "300";
		historyHelpPopup=dhtmlwindow.open('HistoryHelp',url,window_title, 'width='+width+'px,height='+height+'px,left=100px,top=100px,resize=0,scrolling=1');
		if(typeof ajaxwinhistory != "undefined" && ajaxwinhistory != null)
		historyHelpPopup.style.zIndex=ajaxwinhistory.style.zIndex+2;
		return historyHelpPopup ;
}