// JavaScript Document

var popupPath = '/shared/popup/';
var tncPath = '/tnc/';
var faqPath = '/faq/';
var alertPath = '/shared/popup/';

var allowClose = true;
var onClose = false; 

function checkURL(s) {
	var subSection = s.substring(7,0).toLowerCase();
	var answer = (subSection == "http://");
	return answer;
}

function showPopupScreen(url, n, h) { 
	var hh = 500;
	
	var urlStr = '';
	if(window.IsDOS) {
		if(checkURL(url)) {
			urlStr = url;
		} else {
			urlStr = 'http://www.digi.com.my' + popupPath + url;
		}
		
		var lefter = Math.round( ($(window).width() - 700) * 0.5 );
		var topper = 150;
		myPopup = window.open(urlStr, "myPopup", "location=1,status=1,scrollbars=1,width=700,height=500");
		myPopup.moveTo(lefter, topper);
	} else {
		if(n != undefined) $('.p3_popupContent').css('width', n+'px');
		if(h != undefined) {
			hh = h;
			$('#p3_loader').css('max-height', hh+'px');
		}
		$('#p3_loader').html('');

		if(checkURL(url)) {
			$('#p3_loader').html('<iframe src="' + url + '" frameborder="0" style="border:0px solid #FFF; height:' + hh + 'px; width:100%;"></iframe>');
		} else {
			$('#p3_loader').html('<iframe src="' + popupPath + url + '" frameborder="0" style="border:0px solid #FFF; height:' + hh + 'px; width:100%;"></iframe>');
		}

		$('#p3_popupScreen').fadeIn(200);
	}

}

function showYTPopupScreen(yid) { 
	$('.p3_popupContent').css('width', '480px');
	$('#p3_loader').html('');
	$('#p3_loader').html('<div class="ytPreloader"><object width="480" height="385"><param name="movie" value="http://www.youtube.com/v/' + yid + '?fs=1&amp;hl=en_US&amp;color1=0x3a3a3a&amp;color2=0x999999"></param><param name="wmode" value="opaque"><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/' + yid + '?fs=1&amp;hl=en_US&amp;color1=0x3a3a3a&amp;color2=0x999999" type="application/x-shockwave-flash" allowscriptaccess="always" wmode="opaque" allowfullscreen="true" width="480" height="385"></embed></object></div>');
	$('#p3_popupScreen').fadeIn(200);
}

function showAlertPopupScreen() { 
	var urlStr = '';
	if(window.IsDOS) {
		urlStr = 'http://www.digi.com.my' + popupPath + 'pop_alert.html';
		
		var lefter = Math.round( ($(window).width() - 700) * 0.5 );
		var topper = 150;
		myPopup = window.open(urlStr, "myPopup", "location=1,status=1,scrollbars=1,width=700,height=500");
		myPopup.moveTo(lefter, topper);
	} else {
		$('#p3_loader').html('');
		$('#p3_loader').html('<iframe src="' + popupPath + 'pop_alert.html" frameborder="0" style="border:0px solid #FFF; height:500px; width:100%;"></iframe>');

		$('#p3_popupScreen').fadeIn(200);
	}
}

function showTnCPopupScreen(url, n, u) { 
	if(n != undefined && n != '') $('.p3_popupContent').css('width', n+'px');
	
	$('#p3_loader').html('');
	$('#p3_loader').html('<iframe src="' + tncPath + url + '" frameborder="0" style="border:0px solid #FFF; height:500px; width:100%;"></iframe>');
	if(u != undefined && u != '') {
		$('#p3_loader').prepend('<div class="blackButton" style="position:absolute; top:20px; right:40px;" onclick="showPopupScreen( \'' + u + '\')"><div class="left"></div><div class="center">Back</div><div class="right"></div></div>');
	}

	$('#p3_popupScreen').fadeIn(200);
}

function showFAQPopupScreen(url, n, i) { 
	var urlStr = '';
	if(window.IsDOS == 1) {
		if(checkURL(url)) {
			urlStr = url;
		} else {
			urlStr = 'http://www.digi.com.my' + faqPath + url;
		}
		
		var lefter = Math.round( ($(window).width() - 700) * 0.5 );
		var topper = 150;
		myPopup = window.open(urlStr, "myPopup", "location=1,status=1,scrollbars=1,width=700,height=500");
		myPopup.moveTo(lefter, topper);
	} else {		
		
		if(i != undefined && i != '') faqPath = 'faq/';
		if(n != undefined && n != '') $('.p3_popupContent').css('width', n+'px');

		$('#p3_loader').html('');
		if(checkURL(url)) {
			$('#p3_loader').html('<iframe src="' + url + '" frameborder="0" style="border:0px solid #FFF; height:500px; width:100%;"></iframe>');
		} else {
			$('#p3_loader').html('<iframe src="' + faqPath + url + '" frameborder="0" style="border:0px solid #FFF; height:500px; width:100%;"></iframe>');
		}
		if(i != undefined && i != '') {
			if(pos != undefined && pos !='') {
				if(pos=='popscreen') {
					$('#p3_loader').prepend('<div class="blackButton" style="position:absolute; top:20px; right:40px;" onclick="showPopupScreen( \'' + i + '\')"><div class="left"></div><div class="center">Back</div><div class="right"></div></div>');
				}
			} else {
				$('#p3_loader').prepend('<div class="blackButton" style="position:absolute; top:20px; right:40px;" onclick="javascript:showFAQPopupScreen( \'' + i + '\')"><div class="left"></div><div class="center">Back</div><div class="right"></div></div>');
			}
		}
		$('#p3_popupScreen').fadeIn(200);
	}
}

function onPopupScreen() { allowClose = false; }
function outPopupScreen() { allowClose = true; }

function hidePopupScreen() { if(allowClose) $('#p3_popupScreen').hide(); }

$(document).ready(function() {
	$('.p3_header').before('<div id="p3_popupScreen"><div class="p3_popupBG"></div><table class="p3_popupTable" border="0" cellspacing="0" cellpadding="0"><tr><td align="center" valign="middle" onclick="hidePopupScreen()"><div class="p3_popupContent"><a class="p3_popupClose" href="javascript:hidePopupScreen()"></a><div id="p3_loader"></div></div></td></tr></table></div>');
	$('.p3_popupClose').mouseenter(function() { onClose = true; }).mouseleave(function() { onClose = false; });
	$('.p3_popupContent').mouseenter(function() { 
		if(!onClose) {	onPopupScreen(); }
	}).mouseleave(function() { outPopupScreen(); });
	$('.p3_popupContent').show();
});
