var dir = "../"
var features = "top=100,left=100,width=550,height=560,status=yes,resizable=yes,scrollbars=yes";
var features1 = "top=100,left=100,width=80,height=60,status=yes,resizable=yes,scrollbars=yes";
var qListPopupH = new Image(); qListPopupH.src = "../images/qList/icon_downarrow_h.gif"
var qListPopupN = new Image(); qListPopupN.src = "../images/qList/icon_downarrow.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,scrollbars=no,titlebar=no,fullscreen=no';  
  var Win = window.open(URL, winName , Features)    
  Win.resizeTo(620,428);
  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) {
  if (!document.all) return;
  var TR = eval(IDName);
  if (!TR) return;

  var Style = TR.style.display;
  if (Style == "block") {
    Style = "none"
  } else {
    Style = "block"
  }
  TR.style.display = Style;
}
*/
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 Wizard(URL) {
  var Features = TopLeft(730,500) + ',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 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);
	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 getGroups(Item, IsMulti, TypeOfRecord, ForceRedirect) {
	var FORM = document.forms['qListFormG'];
	if(!FORM) return '';
	var UserIDs = FORM.item(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);
	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 == '') {
		window.alert('Please select a ' + TypeOfRecord + ' for action');
	}
	return IDs;
}

function Img(image) {
	return '<img width="16" height="16" src="../images/' + image + '">';
}

//window.alert('Loaded New Version');

