﻿function openLookup()
	{
	strUrl = arguments[0];
	strReturnScript = arguments[1];
	strReturnScriptMultiple = arguments[2];
	strFilterParameter = arguments[3];
	if (strReturnScript != null) 
	
	{
				if (strUrl.indexOf('?')<=0) {
				strUrl += '?returnscript=' + strReturnScript ;
			}
			else {
				strUrl += '&returnscript=' + strReturnScript ;
			}
	}
	if (strReturnScriptMultiple != null)
	{
			if (strUrl.indexOf('?')<=0) {
				strUrl += '?returnscriptmultiple=' + strReturnScriptMultiple ;
			}
			else {
				strUrl += '&returnscriptmultiple=' + strReturnScriptMultiple ;
			}
	}
	if (strFilterParameter != null)
	{
			if (strUrl.indexOf('?')<=0) {
				strUrl += '?filterparameter=' + strFilterParameter ;
			}
			else {
				strUrl += '&filterparameter=' + strFilterParameter ;
			}
	}
	
	window.open(strUrl,'LookUp','status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes,width=750px,height=500px');

	}
	
	
	function openLookup2()
	{
	strUrl = arguments[0];
	strReturnScript = arguments[1];
	strReturnStartDate = arguments[2];
	strReturnEndDate = arguments[3];
	strReturnStartHour = arguments[4];
	strReturnEndHour = arguments[5];
	strReturnStartMinute = arguments[6];
	strReturnEndMinute = arguments[7];
	strReturnFloor = arguments[8];
	strReturnCapacity = arguments[9];
		
	var startDate;
	var startDate2;
	var d = new Date();
	var currDate = d.getDate();
	if (strReturnStartDate=='')
	    startDate = new Date();
	else
	    startDate = new Date(formatDate(strReturnStartDate));
	
	startDate2 = new Date(startDate.getFullYear(),startDate.getMonth(),startDate.getDate(),strReturnStartHour,strReturnStartMinute);
	
	var endDate;
	var endDate2;
	if (strReturnEndDate=='')
	    endDate = new Date();
	else
	    endDate = new Date(formatDate(strReturnEndDate));
	
	endDate2 = new Date(endDate.getFullYear(),endDate.getMonth(),endDate.getDate(),strReturnEndHour,strReturnEndMinute);
	
	if (strReturnScript != null) 
	
	{
				if (strUrl.indexOf('?')<=0) {
				strUrl += '?returnscript=' + strReturnScript ;
			}
			else {
				strUrl += '&returnscript=' + strReturnScript ;
			}
	}
	if (strReturnStartDate != null)
	{
			if (strUrl.indexOf('?')<=0) {
				strUrl += '?returnstartdate=' + strReturnStartDate ;
			}
			else {
				strUrl += '&returnstartdate=' + strReturnStartDate ;
			}
	}
	if (strReturnEndDate != null)
	{
			if (strUrl.indexOf('?')<=0) {
				strUrl += '?returnenddate=' + strReturnEndDate ;
			}
			else {
				strUrl += '&returnenddate=' + strReturnEndDate ;
			}
	}
	if (strReturnStartHour != null)
	{
			if (strUrl.indexOf('?')<=0) {
				strUrl += '?returnstarthour=' + strReturnStartHour ;
			}
			else {
				strUrl += '&returnstarthour=' + strReturnStartHour ;
			}
	}
	if (strReturnEndHour != null)
	{
			if (strUrl.indexOf('?')<=0) {
				strUrl += '?returnendhour=' + strReturnEndHour ;
			}
			else {
				strUrl += '&returnendhour=' + strReturnEndHour ;
			}
	}
	if (strReturnStartMinute != null)
	{
			if (strUrl.indexOf('?')<=0) {
				strUrl += '?returnstartminute=' + strReturnStartMinute ;
			}
			else {
				strUrl += '&returnstartminute=' + strReturnStartMinute ;
			}
	}
	if (strReturnEndMinute != null)
	{
			if (strUrl.indexOf('?')<=0) {
				strUrl += '?returnendminute=' + strReturnEndMinute ;
			}
			else {
				strUrl += '&returnendminute=' + strReturnEndMinute ;
			}
	}
	if (strReturnFloor != null)
	{
			if (strUrl.indexOf('?')<=0) {
				strUrl += '?returnfloor=' + strReturnFloor;
			}
			else {
				strUrl += '&returnfloor=' + strReturnFloor;
			}
	}
	if (strReturnCapacity != null)
	{
			if (strUrl.indexOf('?')<=0) {
				strUrl += '?returncapacity=' + strReturnCapacity;
			}
			else {
				strUrl += '&returncapacity=' + strReturnCapacity;
			}
	}
//		alert(endDate2);
//		alert(startDate2);
		if (endDate2 > startDate2)
		{
			window.open(strUrl,'LookUp','status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes,width=750px,height=500px');
		}
//		else if(endDate=startDate)
//		{
//			if(strReturnStartHour < strReturnEndHour)
//			{
//				window.open(strUrl,'LookUp','status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes,width=750px,height=500px');
//			}
//			else if(strReturnStartHour = strReturnEndHour)
//			{
//				if(strReturnStartMinute < strReturnEndMinute)
//				{
//					window.open(strUrl,'LookUp','status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes,width=750px,height=500px');
//				}
//				else
//				{
//					alert('End date should bigger than start date !');			
//				}
//			}
//			else
//			{
//				alert('End date should bigger than start date !');			
//			}
//		}
		else
		{
			if ((startDate.getFullYear() == endDate.getFullYear())&&(startDate.getMonth()==endDate.getMonth())&&(startDate.getDate()==endDate.getDate()))
			{
				if(strReturnStartHour < strReturnEndHour)
				{
					window.open(strUrl,'LookUp','status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes,width=750px,height=500px');
				}
				else
				{
					if(strReturnStartHour == strReturnEndHour)
					{
						if(strReturnStartMinute < strReturnEndMinute)
						{
							window.open(strUrl,'LookUp','status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes,width=750px,height=500px');
						}
						else
						{
							alert('End Time Cannot Be Earlier Than Start Time !');					
						}
					}
					else
					{
						alert('End Time Cannot Be Earlier Than Start Time !');
					}
				}
			}
			else
			{
				alert('End Date Cannot Be Earlier Than Start Date !');
			}
		}
}
	
	
	function openDocViewer()
	{
	strUrl = arguments[0];
	
	window.open(strUrl,'DocViewer','status=yes,toolbar=yes,menubar=no,location=no,resizable=yes,scrollbars=yes,width=800px,height=600px');

	}
	
	function openDocViewerMeetingRoom()
	{
	strUrl = arguments[0];
	
	window.open(strUrl,'DocViewer1','status=yes,toolbar=no,menubar=no,location=no,resizable=yes,scrollbars=yes,width=500px,height=500px');
	
	}
	
	function openDocViewerLocationMap()
	{
	strUrl = arguments[0];
	
	window.open(strUrl,'DocViewer2','status=yes,toolbar=no,menubar=no,location=no,resizable=yes,scrollbars=yes,width=600px,height=600px');
	
	}
	
	function openDocViewerMeetingRoomDetail()
	{
	strUrl = arguments[0];
	
	window.open(strUrl,'DocViewer3','status=yes,toolbar=no,menubar=no,location=no,resizable=yes,scrollbars=yes,width=600px,height=350px');
	
	}
	
	function openNewBrowser()
	{
	strUrl = arguments[0];
	
	window.open(strUrl,'NewWindow','','');

	}
		
// Add an event to the obj given
// event_name refers to the event trigger, without the "on", like click or mouseover
// func_name refers to the function callback when event is triggered
function addEvent(obj,event_name,func_name){
	if (obj.attachEvent){
		obj.attachEvent("on"+event_name, func_name);
	}else if(obj.addEventListener){
		obj.addEventListener(event_name,func_name,true);
	}else{
		obj["on"+event_name] = func_name;
	}
}

// Removes an event from the object
function removeEvent(obj,event_name,func_name){
	if (obj.detachEvent){
		obj.detachEvent("on"+event_name,func_name);
	}else if(obj.removeEventListener){
		obj.removeEventListener(event_name,func_name,true);
	}else{
		obj["on"+event_name] = null;
	}
}

// Stop an event from bubbling up the event DOM
function stopEvent(evt){
	evt || window.event;
	if (evt.stopPropagation){
		evt.stopPropagation();
		evt.preventDefault();
	}else if(typeof evt.cancelBubble != "undefined"){
		evt.cancelBubble = true;
		evt.returnValue = false;
	}
	return false;
}

function showError()
	{
		var strValue = '';
		if (document.getElementById('strErrorMessage')!= null)
		{
		 strValue = document.getElementById('strErrorMessage').value;
		}
		else
		{
		alert(' Could not find "strErrorMessage" HTMLInputHidden control,\n Application Error Information will not be Availabe')
		}
		 
		if(strValue != '')
		{
		alert(strValue);
		}
	}
	
	function displayhrefTooltip(src,strDisplay){
    src.title=strDisplay;
    return;
   }

function formatCurrency(number){
	var num = number.toString().replace(/\,/g,'');
	if(!isNaN(num)){
		if(num.indexOf('.')> -1){
			num = num.split('.')
			num[0] = num[0].toString().split('').reverse().join('').replace(/(?=\d*\.?)(\d{3})/g,'$1').split('').reverse().join('').replace(/^[\,]/,'');
			if(num[1].length > 2){
				
			}
		}else{
				number = num.toString().split('').reverse().join('').replace(/(?=\d*\.?)(\d{3})/g,'$1,').split('').reverse().join('').replace(/^[\,]/,'');
		}
		
	}
	return number;
}

   function RemoveFinancialFormat(Num)
{
    var rx = /\ /g;
    Num = Num.replace(rx, "");

    if (Num == "")
        return "0";
        
    rx = /\./g;
    
    Num = Num.replace(rx, "");

    if (Num == "")
        return "0";
   
   return Num; 
}

function FormatNumericTxt(oObj)
{
    oObj.value = FormatNumeric(oObj.value);
}

function FormatNumericTxtComma(oObj)
{
    oObj.value = FormatNumericComma(oObj.value);
}


function FormatNumeric(Num)
{
    var rx = /\ /g;
    Num = Num.replace(rx, "");

    if (Num == "")
        return "";
        
    rx = /\./g;
    
    var newNum = "";
    var newNum2 = "";
    var count = 0;

    Num = Num.replace(rx, "");
    //Num = Num.replace(",", "")

    //check for decimal number
    if (Num.indexOf(',') != -1)
    { //number ends with a decimal point
        if (Num.indexOf(',') == Num.length-1)
        {
            Num += "00";
        }
        
        if (Num.indexOf(',') == Num.length-2)
        { //number ends with a single digit
            Num += "0";
        }

        var a = Num.split(","); 
        Num = a[0]; //the part we will commify
        var end = a[1] //the decimal place we will ignore and add back later
    }
    else 
    {
        var end = "00";
    } 

    //this loop actually adds the commas 
    for (var k = Num.length-1; k >= 0; k--)
    {
        var oneChar = Num.charAt(k);
        
        if (count == 3)
        {
            newNum += ".";
            newNum += oneChar;
            count = 1;
            continue;
        }
        else 
        {
            newNum += oneChar;
            count ++;
        }
    } //but now the string is reversed!

    //re-reverse the string
    for (var k = newNum.length-1; k >= 0; k--)
    {
        var oneChar = newNum.charAt(k);
        newNum2 += oneChar;
    }

    // add dollar sign and decimal ending from above
   
    if (newNum2 != "") 
        newNum2 =  newNum2;// + "," + end;
   
    return newNum2; 
}

function FormatNumericComma(Num)
{
    var rx = /\ /g;
    Num = Num.replace(rx, "");

    if (Num == "")
        return "";
        
    rx = /\,/g;
    
    var newNum = "";
    var newNum2 = "";
    var count = 0;

    Num = Num.replace(rx, "");
    //Num = Num.replace(".", "")

    //check for decimal number
    if (Num.indexOf('.') != -1)
    { //number ends with a decimal point
        if (Num.indexOf('.') == Num.length-1)
        {
            Num += "00";
        }
        
        if (Num.indexOf('.') == Num.length-2)
        { //number ends with a single digit
            Num += "0";
        }

        var a = Num.split("."); 
        Num = a[0]; //the part we will commify
        var end = a[1] //the decimal place we will ignore and add back later
    }
    else 
    {
        var end = "00";
    } 

    //this loop actually adds the commas 
    for (var k = Num.length-1; k >= 0; k--)
    {
        var oneChar = Num.charAt(k);
        
        if (count == 3)
        {
            newNum += ",";
            newNum += oneChar;
            count = 1;
            continue;
        }
        else 
        {
            newNum += oneChar;
            count ++;
        }
    } //but now the string is reversed!

    //re-reverse the string
    for (var k = newNum.length-1; k >= 0; k--)
    {
        var oneChar = newNum.charAt(k);
        newNum2 += oneChar;
    }

    // add dollar sign and decimal ending from above
   
    if (newNum2 != "") 
        newNum2 =  newNum2;// + "." + end;
   
    return newNum2; 
}

function formatDate(value)
{
	var day;
	var month;
	var year;
	
	day = value.substr(0, 2);
	month = value.substr(3, 3);
	year = value.substr(7, 4);
	
	switch (month) 
	{ 
   case "Jan" : 
      month = "01"; 
      break; 
   case "Feb" : 
      month = "02";
      break; 
   case "Mar" : 
      month = "03"; 
      break; 
   case "Apr" : 
      month = "04";
      break; 
   case "May" : 
      month = "05"; 
      break; 
   case "Jun" : 
      month = "06";
      break; 
   case "Jul" : 
      month = "07"; 
      break; 
   case "Aug" : 
      month = "08";
      break;
   case "Sep" : 
      month = "09"; 
      break; 
   case "Oct" : 
      month = "10";
      break; 
   case "Nov" : 
      month = "11"; 
      break; 
   case "Dec" : 
      month = "12";
      break;
	}
	//alert(month);
	//alert(day + "-" + month + "-" + year);
	//return(month + "-" + day + "-" + year);
}
