var dir = "../"
var features = "top=100,left=100,width=550,height=535,status=yes,resizable=yes,scrollbars=yes";
var features1 = "top=100,left=100,width=80,height=60,status=yes,resizable=yes,scrollbars=yes";
var imagedirectory;
var qListPopupH = new Image(); qListPopupH.src = "../images/qList/icon_downarrow_h.gif"
var qListPopupN = new Image(); qListPopupN.src = "../images/qList/icon_downarrow.gif"

var qListPopupRH = new Image(); qListPopupRH.src = "../images/qList/qList_Popup_Right_H.GIF"
var qListPopupRN = new Image(); qListPopupRN.src = "../images/qList/qList_Popup_Right_N.GIF"
var qListPopupLN = new Image(); qListPopupLN.src = "../images/qList/qList_Popup_Left_N.GIF"
var qListPopupLH = new Image(); qListPopupLH.src = "../images/qList/qList_Popup_Left_H.GIF"

function OpenFiles(URL) {
  AddComment(URL);
}

function TimeLine() {
  //-- get the selected IDS in tasks;
  var FORM = document.forms['qListForm'];
  if(!FORM) {
   window.location.href = '../tasks/timeline.asp';
   return false;
  }
  
  //-- find is any of the one record is selected
  var TaskIDs = FORM.TaskID;
  if(!TaskIDs) {
   window.location.href = '../tasks/timeline.asp';
   return false;
  }  
  
  if(!TaskIDs.length) {
   //-- if only one selected, select the one;
   TaskIDs.checked = true;
  } else {   
   var Checked = 0;
   // find the number of checked items
   for(i=0; i< TaskIDs.length; i++) {
     if(TaskIDs[i].checked) Checked++;
   }
   // if nothing is checked, select all
   if(Checked = 0)  for(i=0; i< TaskIDs.length; i++) {
     TaskIDs[i].checked = true;
   }   
  }
  
  //-- set the form action to submit to timeline.
  FORM.action = '../tasks/timeline.asp';
  FORM.submit();  
}


function AddComment(URL)
{
  switch (window.name) {
  case 'NewWin1': 
    OpenWinWith('NewWin2',URL, 30);
    break;
  case 'NewWin2':
    OpenWinWith('NewWin3',URL, 60);
    break;    
  default:
    OpenWinWith('NewWin1',URL, 0);
    break;
  }
} 

var qsParm = new Array();
function qs() {
var query = window.location.search.substring(1);
query = query.toLowerCase();
var parms = query.split('&');
for (var i=0; i<parms.length; i++) {
   var pos = parms[i].indexOf('=');
   if (pos > 0) {
      var key = parms[i].substring(0,pos);
      var val = parms[i].substring(pos+1);
      qsParm[key] = val;
      }
   }
}

function OpenWinWith(winName, URL, Padding) {
  var Features = TopLeftShift(620,428, Padding) + ',status=yes,resizable=yes,scrollbars=no,titlebar=no,fullscreen=no';  
  var Win = window.open(URL, winName , Features)    
  //Win.resizeTo(620,440);
  Win.resizeTo(800,600);
  Win.focus();
}

function OpenRFP(URL) {
  var Features = 'top=0,left=50,status=yes,resizable=yes,scrollbars=yes,titlebar=no,fullscreen=no';  
  var winName = 'NewWin'
  var Win = window.open(URL, winName , Features)    
  Win.resizeTo(900,700);
  Win.focus();
}

function OpenWindow(URL) {
  var Features = 'top=0,left=50,status=yes,resizable=yes,scrollbars=no,titlebar=no,fullscreen=no';  
  var winName = 'NewWin'
  var Win = window.open(URL, winName , Features)    
  Win.resizeTo(800,440);
  Win.focus();
}

function AddComment2(URL) {
  OpenWinWith('NewName2', URL, 60)
}
function AddComment3(URL) {
  OpenWinWith('NewName3', URL, 60);
}

function setPos(Win) {
	var TopWin = Win;
  var Top = 300;
  var Left = 200;
 	if(!TopWin.opener) return;
 	if(!TopWin.opener.opener) return;
 	
	while(TopWin.opener) {
		TopWin = TopWin.opener;
		Top+=30;
		Left+=30;
	}
	var TopWin = Win;
	while(TopWin.opener) {
		TopWin = TopWin.opener;
		if(TopWin.opener) {
			TopWin.moveTo(Top,Left);
			Top-=30;
			Left-=30;		
		}
	}
	Win.moveTo(Top-30,Left-30);
	Win.status = 'Top=' + Top + ', Left=' + Left
	
} 
 
function TopLeft(Width, Height) {
  return TopLeftShift(Width, Height, 0)
}

function TopLeftShift(Width, Height, ShiftOf) {
  var winWidth, winHeight;
  winWidth  = (screen.availwidth ? screen.availwidth : screen.availWidth )
  winHeight = (screen.availheight ? screen.availheight : screen.availHeight)
  winWidth  =  (winWidth - Width)/2
  winHeight =  (winHeight - Height)/2

  var T =  "top=" + (winHeight+ShiftOf) + ",left=" + (winWidth+ShiftOf) + 
  ",width=" + Width + ",height=" + Height;
  return T;
}


var M_Array;
function setActiveMenu(MenuID)
{
  M_Array = eval('M_Array' + MenuID);
}

//--Delete Conformation
function ConfirmDel(NavURL) {
  if(window.confirm("You are about to delete the selected record permenently\n\n"+
  "Are you Sure?"))
    window.location.href = NavURL;
  return false;
}
function ConfirmDelTree(NavURL) {
  if(window.confirm("You are about to delete the selected record and its sub records permenently\n\n"+
  "Are you Sure?"))
    window.location.href = NavURL;
  return false;
}
//--Delete Conformation
function ConfirmRemove(NavURL) {
  if(window.confirm("You are about to Remove the record\n\n"+
  "Are you Sure?"))
    window.location.href = NavURL;
  return false;
}

function HM_f_PopUp(){return false};
function HM_f_PopDown(){return false};
popUp = HM_f_PopUp;
popDown = HM_f_PopDown;


function ShowMenu(HM_MenuID, Menu_ID) {
  var MyURL = M_Array[Menu_ID];
  var jScript = /^JavaScript:/i
  if(MyURL.search(jScript) >= 0 ) {
    eval(MyURL)
  } else {
    document.location.href = MyURL;
  }
}

var xpos = 0;
var ypos = 0;

//---------------------------------------------------------------------
//Setting up the X location of
//---------------------------------------------------------------------
function setX(Item) {
  if (document.all) {
    xpos = getOffsetLeftX(document.images[Item]);
  } else {
       xpos = document.images[Item].x;
  }
  xpos = xpos + 7 ;//'+ 35;
}

//---------------------------------------------------------------------
// Setting up Y location
//---------------------------------------------------------------------
function setY(Item) {
  if (document.all) {
    ypos = getOffsetTopX(document.images[Item]) ;
  } else {
    ypos = document.images[Item].y;
  }
  ypos = ypos + document.images[Item].height;
}

//---------------------------------------------------------------------
// Reading the X Position
//---------------------------------------------------------------------
function getX() {
  return  xpos;
}

//---------------------------------------------------------------------
// Reading the Y Position
//---------------------------------------------------------------------
function getY() {
  return ypos;
}

//---------------------------------------------------------------------
//Brower setup for Netscape
//---------------------------------------------------------------------
function getOffsetLeftX (el) {
    var ol = el.offsetLeft;
    while ((el = el.offsetParent) != null)
        ol += el.offsetLeft;
    return ol;
}
function getOffsetTopX (el) {
    var ot = el.offsetTop;
    while((el = el.offsetParent) != null)
        ot += el.offsetTop;
    return ot;
}

function ShowHide(IDName) {
try { 
  var TR = eval(IDName);
  var Img = eval('document.images["' + IDName +'_img"]');

  if (!TR) return;

  var Style = TR.style.display;
  if (Style == "block" || Style == "table-row") {
    Style = "none"
    if (Img) Img.src = '../images/icon_maximize.gif'
  } else {
    Style = document.all ? "block" : "table-row";
    if (Img) Img.src = '../images/icon_minimize.gif'    
  }
  TR.style.display = Style;
} 
catch (e) {}  
}





function ViewClose(IDName) {
try { 
  if (!document.all) return;
  var TR = eval(IDName);
  var Img = eval('document.images["' + IDName +'_img"]');

  if (!TR) return;

  var Style = TR.style.display;
  if (Style == "none") {
    Style = "block"
    if (Img) Img.src = '../images/icon_del.gif'
  } else {
    Style = "none"
    if (Img) Img.src = '../images/blank.gif'
  }
  TR.style.display = Style;
} 
catch (e) {}  
}

function ViewAll(IDName) {
try { 
  if (!document.all) return;
  var TR = eval(IDName);
  var Img = eval('document.images["' + IDName +'_img"]');

  if (!TR) return;

  var Style = TR.style.display;
  if (Img) Img.src = '../images/icon_minimize.gif'
  TR.style.display = 'block';
} 
catch (e) {}  
}

function HideAll(IDName) {
try { 
  if (!document.all) return;
  var TR = eval(IDName);
  var Img = eval('document.images["' + IDName +'_img"]');

  if (!TR) return;

  var Style = TR.style.display;
  if (Img) Img.src = '../images/icon_maximize.gif'
  TR.style.display = 'none';
} 
catch (e) {}  
}

function Wizard(URL) {
  var Features = TopLeft(760,550) + ',status=yes,scrollbars=no,titlebar=no,fullscreen=no,resizable=yes';  
  var winName = 'NewWin'
  var Win = window.open(URL, winName , Features)    
  Win.resizeTo(760,550);
  Win.focus();
}

function Wizard_ImageSet(URL) {
  var Features = TopLeft(550,550) + ',status=yes,scrollbars=no,titlebar=no,fullscreen=no';  
  var winName = 'NewWin'
  var Win = window.open(URL, winName , Features)    
  Win.resizeTo(730,550);
  Win.focus();
}


function DoCheck(Item, Checked) {
	var FORM = document.forms['qListForm'];
	if(!FORM) return '';
	//var UserIDs = FORM.item(Item);
	var UserIDs = eval('FORM.' + Item);
	if(!UserIDs) return '';
    if(UserIDs.length) 
      for(var i=0; i < UserIDs.length; i++) {
        UserIDs[i].checked = Checked;
      }   
}

var IsShowMsg = true;
var Action_ItemValue = '';
function getIDs(Item, IsMulti, TypeOfRecord, ForceRedirect ) {
  if(Action_ItemValue != '') {
  	return Action_ItemValue;
 	} 
 	var FORM = document.forms['qListForm'];
	if(!FORM) return '';
	//var UserIDs = FORM.item(Item);
	 var UserIDs = eval('FORM.' + Item);
	if(!UserIDs) return '';	
	var IDs = '';	
	if(UserIDs.length) {
		for(var i = 0; i < UserIDs.length; i++) {
			if(UserIDs[i].checked) {
				if(IDs != '') {
					if(IsMulti) {
						IDs  = IDs  + ',';
					} else {
						window.alert('Please select one ' + TypeOfRecord + ' for this action');
						return '';
					}
				}
				IDs = IDs  + UserIDs[i].value;
			}
		}
	} else {
		if(UserIDs.checked) IDs = UserIDs.value;
	}
	if( ForceRedirect == null) { ForceRedirect = false;}
	if(IDs == '' && !ForceRedirect) {
		if(IsShowMsg) window.alert('Please select a ' + TypeOfRecord + ' for action');
	}
	return IDs;
}
function ReadQuery(Action_Column) {
  qs();
  IDs = qsParm[Action_Column.toLowerCase()] + '';

  if (IDs == 'undefined') IDs = '';

  return IDs;
}


function getGroups(Item, IsMulti, TypeOfRecord, ForceRedirect) {
	var FORM = document.forms['qListFormG'];
	if(!FORM) return '';
	//var UserIDs = FORM.item(Item);
	var UserIDs = eval('FORM.' + Item);
	if(!UserIDs) return '';
	var IDs = '';
	if(UserIDs.length) {
		for(var i = 0; i < UserIDs.length; i++) {
			if(UserIDs[i].checked) {
				if(IDs != '') {
					if(IsMulti) {
						IDs  = IDs  + ',';
					} else {
						window.alert('Please select one ' + TypeOfRecord + ' for this action');
						return '';
					}
				}
				IDs = IDs  + UserIDs[i].value;
			}
		}
	} else {
		if(UserIDs.checked) IDs = UserIDs.value;
	}
	if( ForceRedirect == null) { ForceRedirect = false;}
	if(IDs == '' && !ForceRedirect) {
		if(IsShowMsg) window.alert('Please select a ' + TypeOfRecord + ' for action');
	}
	return IDs;
}


function getIDsByForm(FORM, Item, TypeOfRecord) {
	//var UserIDs = FORM.item(Item);
	var UserIDs = eval('FORM.' + Item);
	if(!UserIDs) return '';
	var IDs = '';
	if(UserIDs.length) {
		for(var i = 0; i < UserIDs.length; i++) {
			if(UserIDs[i].checked) {
				if(IDs != '') {
						window.alert('Please select one ' + TypeOfRecord + ' for this action');
						return '';
				}
				IDs = IDs  + UserIDs[i].value;
			}
		}
	} else {
		if(UserIDs.checked) IDs = UserIDs.value;
	}
	if(IDs == '') {
		if (IsShowMsg) window.alert('Please select a ' + TypeOfRecord + ' for action');
	}
	return IDs;
}
//window.alert('Loaded New Version');

function getIDsOnForm(formname, Item, IsMulti, TypeOfRecord, ForceRedirect) {
	var FORM = formname;
	if(!FORM) return '';
	//var UserIDs = FORM.item(Item);
	var UserIDs = eval('FORM.'+Item);
	if(!UserIDs) return '';
	var IDs = '';
	if(UserIDs.length) {
		for(var i = 0; i < UserIDs.length; i++) {
			if(UserIDs[i].checked) {
				if(IDs != '') {
					if(IsMulti) {
						IDs  = IDs  + ',';
					} else {
						window.alert('Please select one ' + TypeOfRecord + ' for this action');
						return '';
					}
				}
				IDs = IDs  + UserIDs[i].value;
			}
		}
	} else {
		if(UserIDs.checked) IDs = UserIDs.value;
	}
	if( ForceRedirect == null) { ForceRedirect = false;}
	if(IDs == '' && !ForceRedirect) {
		if(IsShowMsg) window.alert('Please select a ' + TypeOfRecord + ' for action');
	}
	return IDs;
}

function getMultiIDsByForm(FORM, Item, TypeOfRecord) {
	//var UserIDs = FORM.item(Item);
	var UserIDs = eval('FORM.'+Item);
	if(!UserIDs) return '';
	var IDs = '';
	if(UserIDs.length) {
		for(var i = 0; i < UserIDs.length; i++) {
			if(UserIDs[i].checked) {
			  if (IDs == '') 
			  IDs = UserIDs[i].value;
			  else			  
				IDs = IDs  + ',' + UserIDs[i].value;
			}
		}
	} else {
		if(UserIDs.checked) IDs = UserIDs.value;
	}
	if(IDs == '') {
		if(IsShowMsg) window.alert('Please select a ' + TypeOfRecord + ' for action');
	}
	return IDs;
}

function ShowToolTip(ToolTipID, e) {
  var ToolTip = document.getElementById(ToolTipID);
//  window.alert(window.screenTop.aa.dd);
  if(ToolTip) {
    var x = e.x + 16;
    if(!document.all) {x = e.clientX + 5;}
    if(x > screen.width - 280) x = screen.width - 280;
    ToolTip.style.top = ((document.all)?e.y + 16 + document.body.scrollTop:e.clientY+10) + 'px';
    ToolTip.style.left = x + 'px';
    ToolTip.style.display = 'block'
  }
}

function HideToolTip(ToolTipID, e) {
  var ToolTip = document.getElementById(ToolTipID);
  if(ToolTip) {
    ToolTip.style.display = 'none'
  }
}

function OpenWindowView(URL, Width, Height) {
  var ImageView = window.open(URL, 'ImageView', TopLeft(Width, Height) + ",status=yes,resizable=yes,scrollbars=yes");
  if(ImageView) ImageView.focus();
}

function Img(image) {
	return '<img width="16" height="16" src="../images/' + imagedirectory + image + '">';
}

var LastItemClicked = 0;
var LastSectionUsed = '';

function ShowHideAll(IDName, ImgName, ID_ToShow, MaxIDs, MoreSections) {
  var iID = parseInt(ID_ToShow);
  var iMax = parseInt(MaxIDs);

  if (isNaN(iID)) iID = 1;
  if (isNaN(iMax)) iMax = 40; //--maximum in a page
  if (LastSectionUsed != IDName) LastItemClicked = 0;
  if (LastItemClicked == iID) iID = 0;

  LastItemClicked = iID;
  LastSectionUsed = IDName;

  for (var i = 1; i <= MaxIDs; i++) {
    var TheRow = document.getElementById(IDName + i);
    var TheImage = document.images[ImgName + i];
    var BlockName = (document.all ? 'block' : (TheRow.tagName == 'TR' ? 'table-row' :'block'))
    if (TheRow) TheRow.style.display = iID == i ? BlockName  : 'none';
    if (TheImage) TheImage.src = (iID == i) ? '../images/icon_minimize.gif' : '../images/icon_maximize.gif'
  }

  //If if there are more items to be hidden/shown set it here.
  //items are passed by comma
  if (! MoreSections) return;

  for (var i = 1; i <= MaxIDs; i++) {
    var aItems = MoreSections.split(',')
    for (x = 0; x < aItems.length; x++) {
      var theItem = document.getElementById(aItems[x] + i);
      var BlockName = (document.all ? 'block' : (theItem.tagName == 'TR' ? 'table-row' :'block'))      
      if (theItem) theItem.style.display = iID == i ? BlockName : 'none';
    } //for x
  }   //for i
}