// JavaScript Document

$(window).resize(function() {
  resizeWin();
});


function clickToCall(){
	if( !awxc_title )var awxc_title = '';
	if( !awxc_intro )var awxc_intro = '';
	if( !awxc_button )var awxc_button = '';
	if( !awxc_working )var awxc_working = '';
	if( !awxc_problem )var awxc_problem = '';
	if( !awxc_success )var awxc_success = '';
	if( !awxc_again )var awxc_again = '';
	if( !awxc_csssource )var awxc_csssource = '';
	if( !awxc_style )var awxc_style = '';
	if( !awxc_badphone )var awxc_badphone = '';
	if( !awxc_greeting )var awxc_greeting = '';
	if( !awxc_bghex )var awxc_bghex = '';
	if( !awxc_widget )var awxc_widget = '';

	if( !awxc_w )var awxc_w = 400;
	if( !awxc_h )var awxc_h = 200;
	if( !awxc_id )var awxc_id = 'click2callframe';
	var html = '<iframe frameborder="0" style="margin:0;padding:0;" ALLOWTRANSPARENCY="true" id="' + awxc_id + '" src="http://hosted.appworx.intelepeer.net/widgets/w/c/index.php?p=1000915.144%20.0.207&intro=' + awxc_intro + '&button=' + awxc_button + '&working=' + awxc_working + '&problem=' + awxc_problem + '&success=' + awxc_success + '&style=' + awxc_style + '&greeting=' + awxc_greeting + '&badphone=' + awxc_badphone + '&bghex=' + awxc_bghex + '&csssource=' + awxc_csssource + '&title=' + awxc_title + '&again=' + awxc_again + '&widget=' + awxc_widget + '" style="width: ' + awxc_w + 'px; height: ' + awxc_h + 'px;"></iframe>';
	//document.write(html);
	displayPopup(html);
}

function displayPopup(content){
	if ($("#frame").length == 0){
		$('body').append('<div id="frame"><div id="closeButton"><a href="javascript:closePop();"><img src="/images/GenisysGlobal/assets/images/misc/closebox.png" width="30" height="30" alt="Close" /></a></div><div id="frameContent"></div></div><a href="javascript:closePop();" id="coverLink"><div id="cover" class="blackout"> </div></a>');
		
		if(content == null){
			content = "";	
		}
		$("#frameContent").html(content);
		
		$("#cover").width($(window).width()).height($(window).height());
		$("#cover").show();
		
		
		
		centerDiv("frame");

	}
	
	
}

function centerDiv(myDiv){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#"+myDiv).height();
	var popupWidth = $("#"+myDiv).width();
	var popupLeft = windowWidth/2-popupWidth/2;
	if(popupLeft<0){ popupLeft = 0; }
	//centering
	$("#"+myDiv).css({
		"position": "absolute",
		"left": popupLeft
	});
	
}

function resizeWin(){
	if ($("#frame").length > 0){
		centerDiv("frame");
		$("#cover").width($(window).width()).height($(window).height());
	}
}
  
function closePop(){
	$("#frame").remove();
	$("#cover").remove();
	$("#coverLink").remove();
}
