﻿
function openBookingInfoWindow(guid, printMode) {
    uri = "BookingInfo.aspx?GUID=" + guid; 
    if (printMode) {
        uri += "&Perform=Print";
    }
    
    bookingInfoWindow = window.open(uri,"bookingInfoWindow","menubar=no,toolbar=no,status=no,location=no,favorite=no,scrollbars=yes,resizable=yes,width=750");
    bookingInfoWindow.focus();
}



function openTripBookingInfoWindow(guid, printMode) {
    uri = "TripBookingInfo.aspx?GUID=" + guid; 
    if (printMode) {
        uri += "&Perform=Print";
    }
    
    bookingTripInfoWindow = window.open(uri,"bookingTripInfoWindow","menubar=no,toolbar=no,status=no,location=no,favorite=no,scrollbars=yes,resizable=yes,width=750");
    bookingTripInfoWindow.focus();
}

function openConfirmationInfoWindow(guid, printMode) {
    uri = "ConfirmationInfo.aspx?GUID=" + guid; 
    bookingInfoWindow = window.open(uri,"bookingInfoWindow","menubar=no,toolbar=no,status=no,location=no,favorite=no,scrollbars=yes,resizable=yes,width=750");
    bookingInfoWindow.focus();
}

function openTripConfirmationInfoWindow(guid, printMode) {
    uri = "TripConfirmationInfo.aspx?GUID=" + guid; 
    bookingInfoWindow = window.open(uri,"bookingInfoWindow","menubar=no,toolbar=no,status=no,location=no,favorite=no,scrollbars=yes,resizable=yes,width=750");
    bookingInfoWindow.focus();
}

function openImageWindow(imagePath) {
    imageWindow = window.open("ImageViewer.aspx?File=" + imagePath, "imageWindow", "menubar=no,toolbar=no,status=no,location=no,favorite=no,scrollbars=auto,resizable=no");
    imageWindow.focus();
}


function isDate(sDate) {
   var re = /^\d{1,2}\/\d{1,2}\/\d{4}$/
   if (re.test(sDate)) {
      var dArr = sDate.split("/");
      var d = new Date(sDate);
      return d.getMonth() + 1 == dArr[0] && d.getDate() == dArr[1] && d.getFullYear() == dArr[2];
   }
   else {
      return false;
   }
}

function performRemoteMethod(perform, guid, value) {
    var dummyImage = new Image();
    var performUrl = "PerformRemoteMethods.aspx?Perform=" + perform + "&GUID=" + guid + "&Value=" + escape(value) + "&Dummy=" + (new Date()).getTime();
    
    dummyImage.onerror = function() {
        document.location = performUrl;
    }  
    
    dummyImage.src = performUrl;
    
}


function toCurrencyFormat(amount) {
    var i = parseFloat(amount);
    if(isNaN(i)) { i = 0.00; }
    var minus = '';
    if(i < 0) { minus = '-'; }
    i = Math.abs(i);
    i = parseInt((i + .005) * 100);
    i = i / 100;
    s = new String(i);
    if(s.indexOf('.') < 0) { s += '.00'; }
    if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
    s = minus + s;
    return s;
}

function toCurrencyFormatWithComma(amount) {
	var delimiter = ","; // replace comma if desired
	var a = amount.split('.',2)
	var d = a[1];
	var i = parseInt(a[0]);
	if(isNaN(i)) { return ''; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	var n = new String(i);
	var a = [];
	while(n.length > 3)	{
		var nn = n.substr(n.length-3);
		a.unshift(nn);
		n = n.substr(0,n.length-3);
	}
	if(n.length > 0) { a.unshift(n); }
	n = a.join(delimiter);
	if(d.length < 1) { amount = n; }
	else { amount = n + '.' + d; }
	amount = minus + amount;
	return amount;
}


function printDiv(divId) {
    var printContent = document.getElementById(divId);
    var printWindow = window.open('','printWindow','left=0,top=0,width=750,height=650,toolbar=0,scrollbars=0,status=0');
    printWindow.document.write("<html><head><title>Print Document</title><link rel='stylesheet' type='text/css' href='StyleSheet.css'/></head><body>");
    printWindow.document.write(printContent.innerHTML);
    printWindow.document.write("</body></html>");
    printWindow.document.close();
    printWindow.focus();
    printWindow.print();
    printWindow.close();

}

function copyToClipboard(s) {
	if( window.clipboardData && clipboardData.setData )	{
		clipboardData.setData("Text", s);
	}
	else {
		// You have to sign the code to enable this or allow the action in about:config by changing
		user_pref("signed.applets.codebase_principal_support", true);
		netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');

		var clip = Components.classes['@mozilla.org/widget/clipboard;[[[[1]]]]'].createInstance(Components.interfaces.nsIClipboard);
		if (!clip) return;

		// create a transferable
		var trans = Components.classes['@mozilla.org/widget/transferable;[[[[1]]]]'].createInstance(Components.interfaces.nsITransferable);
		if (!trans) return;

		// specify the data we wish to handle. Plaintext in this case.
		trans.addDataFlavor('text/unicode');

		// To get the data from the transferable we need two new objects
		var str = new Object();
		var len = new Object();

		var str = Components.classes["@mozilla.org/supports-string;[[[[1]]]]"].createInstance(Components.interfaces.nsISupportsString);

		var copytext=meintext;

		str.data=copytext;

		trans.setTransferData("text/unicode",str,copytext.length*[[[[2]]]]);

		var clipid=Components.interfaces.nsIClipboard;

		if (!clip) return false;

		clip.setData(trans,null,clipid.kGlobalClipboard);	   
	}
}