var path = (webContextPath) ? (webContextPath + "/web-resources/") : ("../");

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-19639674-1']);
_gaq.push(['_trackPageview']);

(function() {
  var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
  ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
  var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})(); 

var g = {
	openModeInfo: function(mode) {
		if (mode == 'EBID')
			dhtmlwindow.open("mode", "ajax", path + "pages/AA19PModeE.html", "Place2Lease.com", "width=450px,height=400px,center=1,resize=1,scrolling=0");
		else if (mode == 'QBID')
			dhtmlwindow.open("mode", "ajax", path + "pages/AA19PModeQ.html", "Place2Lease.com", "width=450px,height=380px,center=1,resize=1,scrolling=0");
		else
			dhtmlwindow.open("mode", "ajax", path + "pages/AA19PModeG.html", "Place2Lease.com", "width=450px,height=260px,center=1,resize=1,scrolling=0");
	},
	openDisplayInfo: function() {
		dhtmlwindow.open("display", "ajax", path + "pages/AA19PDisplayInfo.html", "Place2Lease.com", "width=640px,height=180px,center=1,resize=1,scrolling=0");
	},
	openHistory: function(postId, selective) {
		if (selective == true)
			dhtmlwindow.open("history", "ajax", webappContextPath + "/p2l/neutral/history/selective.jspa?post=" + postId, "Unit Bid History (Selective)", "width=640px,height=400px,center=1,resize=1,scrolling=1");
		else
			dhtmlwindow.open("history", "ajax", webappContextPath + "/p2l/neutral/history/index.jspa?post=" + postId, "Unit Bid History", "width=640px,height=400px,center=1,resize=1,scrolling=1");
	},
	openTerm: function(orgCode) {
		if (orgCode == null || orgCode == undefined || orgCode.length == 0 || orgCode.toLowerCase() == 'main')
			dhtmlwindow.open("select", "ajax", path + "pages/AA19PTermSelect.html", "Place2Lease.com", "width=500px,height=220px,center=1,resize=1,scrolling=1");
		else
			dhtmlwindow.open("term", "ajax", path + "pages/AA19PTerm" + orgCode.toUpperCase() + ".html", "Place2Lease.com", "width=640px,height=520px,center=1,resize=1,scrolling=1");
	},
	openPrivacy: function() {
		dhtmlwindow.open("privacy", "ajax", path + "pages/AA19PPrivacy.html", "Place2Lease.com", "width=540px,height=560px,center=1,resize=1,scrolling=1");
	},
	openAgreement: function() {
		dhtmlwindow.open("agreement", "ajax", path + "pages/AA19PUserAgreement.html", "Place2Lease.com", "width=640px,height=520px,center=1,resize=1,scrolling=1");
		$.get(path + 'sitedesign/style-print.css', function(data) {
			$('.drag-contentarea').prepend('<style>' + data + '</style>');
		});
	},
	openVideo: function() {
		dhtmlwindow.open("video", "ajax", path + "pages/AA19PVideo.html", "Place2Lease.com", "width=540px,height=440px,center=1,resize=1,scrolling=1");
	},
	openAwards: function() {
		dhtmlwindow.open("awards", "ajax", path + "pages/AA19PAwards.html", "Place2Lease.com", "width=540px,height=320px,center=1,resize=1,scrolling=1");
	},
	openAbout: function() {
		dhtmlwindow.open("about", "ajax", path + "pages/AA19PAbout.html", "Place2Lease.com", "width=450px,height=420px,center=1,resize=1,scrolling=1");
	},
	refreshWindow: function() {
		var window = dhtmlwindow.lastactivet;
		dhtmlwindow.ajax_connect(window.source, window);
		return false;
	},
	closeWindow: function() {
		dhtmlwindow.close(dhtmlwindow.lastactivet);
		return false;
	},
	printWindow: function() {
		var win = window.open();
		win.document.open();
		win.document.write($('.drag-contentarea').html());
		win.document.close();
		win.print();
		win.close();
		return false;
	},
	rateWebsite: function() {
		window.open('http://www.hdb.gov.sg/be06/be06020p.nsf/BE06M06AgtRateEService?OpenAgent&EServiceID=E030051', '_blank','top=0, left=0, scrollbars=yes, menubar=no, toolbar=no, height=600, width=600, resizable=yes');
		return false;
	},
	rateEService: function() {
		window.open('http://www.hdb.gov.sg/be06/be06020p.nsf/BE06M06AgtRateEService?OpenAgent&EServiceID=E030013', '_blank','top=0, left=0, scrollbars=yes, menubar=no, toolbar=no, height=600, width=600, resizable=yes');
		return false;
	},
	downloadVideo: function() {
		window.open(path + 'video/p2l_email_03_01.wmv', '_blank');
		return false;
	},
	currentDateTime: function() {
		var now = new Date();
		return now.getDate() + '/' + (now.getMonth() + 1) + '/' + now.getFullYear() + ' ' + now.getHours() + ':' + now.getMinutes() + ':' + now.getSeconds();
	},
	filterKeypress: function(e) {
		if (e.which !== 0 && e.charCode !== 0) {
        	var expression = /^\d*$/gi;
        	var code = String.fromCharCode(e.keyCode|e.charCode);
        	
        	if (code.match(expression))
				return true;
			else
				return false;
        }
	},
	limitMaxLength: function(e, comp, max) {
		if (e.which !== 0 && e.charCode !== 0) {
			var length = comp.value.length;
			
			if (length < max)
				return true;
			else
				return false;
		}
	}
};
