//===============================================================================
//
//	 JScript library
// 
//	
//
//===============================================================================
//
// Copyright (C) 2000 Microsoft Corporation
// All rights reserved.
//
// This source code is intended only as a supplement to Microsoft
// Development Tools and/or on-line documentation. See these other
// materials for detailed information regarding Microsoft code samples.
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY 
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT 
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR 
// FITNESS FOR A PARTICULAR PURPOSE.
//
//===============================================================================

window.onload=window_onload_runalways;
try 
{
	var oPopup = window.createPopup();
}
 catch(e)
{
}

//-------------------------------------------------------------------------------
//
// Purpose:	global page load function for aspx pages
//-------------------------------------------------------------------------------

function window_onload_runalways()
	{
	if ( top.document.all )
		{
		var title = top.document.all("title");
	
		if (title != null)
			{
			title.filters[0].Apply(); 
			title.innerHTML = document.title; 
			title.filters[0].Play(); 
			}
		}
		
	startclock();
	}
	
//-------------------------------------------------------------------------------
//
// Purpose:	manage customized tooltips
//
//-------------------------------------------------------------------------------
// Create the popup object. For predictable results, always create
// a global popup object.

 
// Used By Feedback Form
function openPopupold(sTitle)
{
 try {
    var src = window.event.srcElement;
    var td  = getTDCell(src);
    var tip = getTipCell(td); 
    
    var popupBody = oPopup.document.body;
    var bgcolor = '#eeeea0';
    
    // The following HTML that populates the popup object with a string.
    popupBody.innerHTML = "<DIV unselectable='on' align='center' style='width: 170px; padding: 5px;font: 8pt tahoma;color:black;cursor: default;background-color:" + bgcolor + "'>" + sTitle + "</DIV>"
        
    oPopup.show(0, 0, 0, 0);
        
    var realHeight = popupBody.scrollHeight;
    var realWidth  = popupBody.scrollWidth;
        
    oPopup.hide();
    
    var nLeft = tip.offsetLeft;
    if(document.body.clientWidth < tip.offsetLeft) nLeft = document.body.clientWidth;
    oPopup.show(nLeft - 5, tip.offsetTop, realWidth, realHeight, tip.offsetParent);

    window.event.cancelBubble = true;

    return;
  }
  catch(e){ return; }
}

function openHelpTextold(sHelpText)
{
 
  try {
    var src = window.event.srcElement;
    var td  = getTDCell(src);
    var tip = getHelpCell(td); 
   
    var e = window.event
    var popupBody = oPopup.document.body;
    
    // The following HTML that populates the popup object with a string.
    popupBody.innerHTML = "<DIV unselectable='on' style='width: 490px;padding: 5px;font: 8pt tahoma;color:black;cursor: default;background-color:#eeeea0;'>" + sHelpText + "</DIV>"
        
    oPopup.show(0, 0, 0, 0);
        
    var realHeight = popupBody.scrollHeight;
    var realWidth  = popupBody.scrollWidth;
        
    oPopup.hide();

	var nLeft = tip.offsetLeft;
    if(document.body.clientWidth < tip.offsetLeft) nLeft = document.body.clientWidth;
    oPopup.show(nLeft, tip.offsetTop, realWidth, realHeight, tip.offsetParent);

    //oPopup.show(e.x + 15, e.y - 15, realWidth, realHeight, document.body);

    window.event.cancelBubble = true;

    return;
  }
  catch(e){ return; }
  
}


function closePopupold()
{
  try {
    oPopup.hide();
    window.event.cancelBubble = true;
    return;
  }
  catch(e){ return; }
}

function getTDCell(e)
{
  
  while (e != null)
  {
    if (e.tagName.toUpperCase() == 'TD')
      break;
    e = e.parentElement;
  }
  
  return e;
}


function getTipCell(e)
{
  // get the table cell we will use as the parent element for tool tip popup
  var i;
  var tip = document.body;
 
  while (e != null)
  {
    if (e.tagName.toUpperCase() == 'TR') 
    {
      tip = e.cells("toolTip");
      break;
    }
    e = e.parentElement;
  } 
  
  return tip;
  
}

function getHelpCell(e)
{
  // get the table cell we will use as the parent element for tool tip popup
  var i;
  var tip = document.body;
 
  while (e != null)
  {
    if (e.tagName.toUpperCase() == 'TR') 
    {
      tip = e.cells("helpArea");
      break;
    }
    e = e.parentElement;
  } 
  
  return tip;
  
}

// Real time clock
var timerID = null;
var timerRunning = false;

function stopclock ()
{
	if (timerRunning) clearTimeout(timerID);
	timerRunning = false;
}

function showtime () 
{
	var now = new Date();
	var hours = now.getHours();
	var minutes = now.getMinutes();
	var seconds = now.getSeconds()
	var timeValue = now.getHours(); 

	timeValue += ((minutes < 10) ? ":0" : ":") + minutes
	timeValue += ((seconds < 10) ? ":0" : ":") + seconds
	document.frmMain.clock.value = "Kuwait time: " + timeValue;
	timerID = setTimeout("showtime()",1000);
	timerRunning = true;
}

function showtimediff (endDate) 
{
	var now = new Date();	
	var timeValue=""; 
	var days;
	var hours;
	var minutes;
	var seconds;
	var later;
	
	//later = new Date("Sept 25 2002 15:00:00");
		
	later = new Date(endDate); 
	
	days = (later - now) / 1000 / 60 / 60 / 24;
	days = Math.floor(parseInt(days));
	
	hours = (later - now) / 1000 / 60 / 60 - (24 * parseInt(days));
	hours = Math.floor(parseInt(hours));
	
	minutes = (later - now) / 1000 /60 - (24 * 60 * parseInt(days)) - (60 * parseInt(hours));
	minutes = Math.floor(parseInt(minutes));
	
	seconds = (later - now) / 1000 - (24 * 60 * 60 * parseInt(days)) - (60 * 60 * parseInt(hours)) - (60 * parseInt(minutes));
	seconds = Math.round(parseInt(seconds));
	
	if (parseInt(days) < 3) { 
	timeValue =  ((eval(parseInt(hours) + (parseInt(days) * 24)) < 10) ? "  0" : "") + eval(parseInt(hours) + (parseInt(days) * 24));
	//timeValue =  ((parseInt(days) < 10) ? "0" : "") + parseInt(days);
	//timeValue = timeValue + ((parseInt(hours) < 10) ? "  0" : ":") + parseInt(hours);
	timeValue = timeValue + ((parseInt(minutes) < 10) ? ":0" : ":") + parseInt(minutes);
	timeValue = timeValue + ((parseInt(seconds) < 10) ? ":0" : ":") + parseInt(seconds);
	
	document.frmMain.clockdiff.value = "Total Hours Left for Tender closing -  " +  timeValue;
	}
		
	setTimeout("showtimediff('" + endDate + "')",1000);
	//timerID = setTimeout("showtimediff(endDate)",1000);
	//timerRunning = true;
}


function startclock() 
{
	stopclock();
	showtime();
	//showtimediff () ;
}
function openHelpText(sHelpText)
{
 try {
   var eP = window.event.srcElement;
	var dF = document.getElementById('divToolTip');
	
	var eL = 0;
	var eT = 0;
	for(var p=eP; p&&p.tagName!='BODY'; p=p.offsetParent)
	{
		eL += p.offsetLeft;
		eT += p.offsetTop;
	}
	
	var eW = parseInt(dF.width);
	var eH = parseInt(dF.height);
	
	if(eL+eW>=document.body.clientWidth)
		dF.style.left=eL-eW;
	else
		dF.style.left= eL-500;
	
	if(eT+12+eH >= document.body.clientHeight)
      dF.style.top=(eT-eH-5);
    else
      dF.style.top=eT+13; 
            
        // The following HTML that populates the popup object with a string.
    var bgcolor = '#eeeea0';
    dF.innerHTML = "<DIV unselectable='on' style='width: 490px;padding: 5px;font: 8pt tahoma;color:black;cursor: default;background-color:#eeeea0;'>" + sHelpText + "</DIV>"
    
    dF.style.display="block"; 
    
    window.event.cancelBubble = true;

    return;
  }
  catch(e){ return; }
  
}
function openPopup(sTitle)
{
	var eP = window.event.srcElement;
	var dF = document.getElementById('divToolTip');
	
	var eL = 0;
	var eT = 0;
	for(var p=eP; p&&p.tagName!='BODY'; p=p.offsetParent)
	{
		eL += p.offsetLeft;
		eT += p.offsetTop;
	}
	
	var eW = parseInt(dF.width);
	var eH = parseInt(dF.height);
	
	if(eL+eW>=document.body.clientWidth)
		dF.style.left=eL-eW;
	else
		dF.style.left=eL-180;
	
	if(eT+12+eH >= document.body.clientHeight)
      dF.style.top=(eT-eH-5);
    else
      dF.style.top=eT+13; 
            
        // The following HTML that populates the popup object with a string.
      var bgcolor = '#eeeea0';
      dF.innerHTML = "<DIV unselectable='on' align='center' style='width: 170px; padding: 5px;font: 8pt tahoma;color:black;cursor: default;background-color:" + bgcolor + "'>" + sTitle + "</DIV>"
	        
      dF.style.display="block";
      
      window.event.cancelBubble = true;
	
}
function closePopup()
{
	var dF = document.getElementById('divToolTip');
	dF.style.display = "none"
}
