document.write('<style type="text/css">');
document.write('#innerpopup_iframe{');
document.write('	overflow:hidden;');
document.write('	z-index:500;');
document.write('	position:absolute;');
document.write('	top:0; left:0; border:0;');
document.write('}');
document.write('#innerpopup_background{');
document.write('	z-index:498;');
document.write('	position:absolute;');
document.write('	top:0; left:0;');
document.write('	background:#000;');
document.write('	filter:alpha(opacity=70);');
document.write('	opacity:.7;');
document.write('}');
document.write('</style>');
document.write('<div id="innerpopup" style="visibility:hidden;">');
document.write('	<div id="innerpopup_background">&nbsp;</div>');

document.write('	<iframe id="innerpopup_iframe" frameborder="0" scrolling="no" src="about:blank" style="width:5px;height:5px"></iframe>');
document.write('</div>');


var newLeft = newTop = 0;
//close button
document.write('<a href="javascript: closePopup()" style="width:26px; height:24px; position:absolute; z-index:2000; background-image:url(bgimage); display:none; left: '+newLeft+'px; top: '+newTop+'px; " id="popCloseBtn"><span style="display:none;">Close</span></a>'); 
//NEW popup Close btn
document.write('<a href="javascript: closePopup()" style="width:54px; height:33px; position:absolute; z-index:2000; background-image:url(bgimage); display:none; left: '+newLeft+'px; top: '+newTop+'px; " id="popCloseBtnNEW"><span style="display:none;">Close</span></a>'); 
//already a subscr. button
document.write('<a href="javascript: openLogin()" style="width:205px; height:58px; position:absolute; z-index:2000; background-image:url(bgimage); display:none; left: '+newLeft+'px; top: '+newTop+'px; " id="popLoginBtn"><span style="display:none;">Close</span></a>'); 
//lost pass btn
document.write('<a href="javascript: openLostPass()" style="width:60px; height:20px; position:absolute; z-index:2000; background-image:url(bgimage); display:none; left: '+newLeft+'px; top: '+newTop+'px; " id="popPassBtn"><span style="display:none;">Close</span></a>'); 
//request pass btn
document.write('<a href="javascript: submitReqPassForm()" style="width:175px; height:32px; position:absolute; z-index:2000; background-image:url(bgimage); display:none; left: '+newLeft+'px; top: '+newTop+'px; " id="popReqPassBtn"><span style="display:none;">Close</span></a>');
//email text input
document.write('<input type="text" style="width:174px; height:24px; position:absolute; z-index:200000; background-image:url(bgimage); display:none; left: '+newLeft+'px; top: '+newTop+'px; border: 1px solid #6A7A8A; " id="popEmailInput"><span style="display:none;">Close</span></a>'); 


if (typeof domain == 'undefined') var domain = 'mykodial.com';
if (typeof tracker == 'undefined') var tracker = '';
if(tracker == '') tracker = 'deftrack';
tracker+="_mykodcdsub";

if(typeof autorun != 'undefined' && autorun == 1){
	autorun = true;
}
else autorun = false;

var Param = {
	'width':1,'height':1,'autorun':autorun,'opacity':7,
	'url':'about:blank'
};
var DHTMLpop = initDHTMLpop(Param);	


//debug
debug_pop_subscr = 0;
if(typeof debug_pop_subscr != 'undefined' && debug_pop_subscr == 1){
	//test ver
	var main_site_url = "http://svn.carpediem.fr/devs/lovesh/mykodial/www/index.php";
}
else{
	//live ver
	if(typeof alias == 'undefined') alias = "www";
	var main_site_url = "http://"+alias+"."+domain+"/index.php";
}


if(typeof popUpURL != 'undefined' && popUpURL.length > 0){
	main_site_url = popUpURL;
	DHTMLpop.width = 380;
	DHTMLpop.height = 380;
	window.onresize = runPopUp; 
}


//normal+debug -> ? / else &
var glue = main_site_url.indexOf('?') == -1 ? '?' : '&';
main_site_url += glue;



//body background fix
//document.body.style.background ='transparent';

function closePopup(){
	showHideInnerPopUp();
	showhideCloseBtn_Login();
	showhide_PassForm();
	showhideCloseBtn();//hide the close btn last
	show_hide_objects('visible');
}

function showhideCloseBtn(){//+Login Btn
	var popCloseBtn = document.getElementById('popCloseBtn');
	if(popCloseBtn.style.display == 'none'){
		popCloseBtn.style.display = 'block';
	}
	else{
		popCloseBtn.style.display = 'none';
	}
	
	//new POPup close btn
	if(typeof popUpURL != 'undefined' && popUpURL.length > 0){
		var popCloseBtnNEW = document.getElementById('popCloseBtnNEW');
		popCloseBtnNEW.style.display = popCloseBtn.style.display; 
	}
	
}

function showSubscribeForm(){
	//close btn
	posObj('popCloseBtn',584,2);//id; left, top offsets
	//new close btn
	//check if header logo is present, if not -82px
	var newclosetop = 320;
	if(typeof popUpURL != 'undefined' && popUpURL.match(/logo=-1/)) newclosetop -= 82;
	posObj('popCloseBtnNEW',10,newclosetop);
	//login
	posObj('popLoginBtn',401,33);
	var popCloseBtn = document.getElementById('popCloseBtn');
	var popLoginBtn = document.getElementById('popLoginBtn');
	popLoginBtn.style.width = "205px";
	popLoginBtn.href = "javascript:openLogin();";
	popLoginBtn.onclick = "openLogin()";
	//display 'em
	popCloseBtn.style.display = 'block';
	popLoginBtn.style.display = 'block';
}


function runPopUp(){
	var popCloseBtn = document.getElementById('popCloseBtn');
	if(popCloseBtn.style.display == 'block'){
		closePopup();
		runPopUp();
	}
	else{
		show_hide_objects('hidden');
		if(typeof popUpURL == 'undefined'){//no custom size set
			//default subscribe popup size
			DHTMLpop.width = 650;
			DHTMLpop.height = 400;
		}
		DHTMLpop.url = main_site_url+'module=guest_mykodial_subscribe&webmaster=1&origin=webmaster&lostPsd=&action=inscription&id='+id+'&tracker='+tracker+'&param=&langue='+lg;
		showHideInnerPopUp();
		showhideCloseBtn();
		showSubscribeForm();
	}
}

function openLogin(){
	showHideInnerPopUp();//hide other pop
	DHTMLpop.width = 734;
	DHTMLpop.height = 357;
	DHTMLpop.url = main_site_url+'module=guest_mykodial_subscribe&action=accueil&webmaster=1&origin=webmaster&lostPsd=&id='+id+'&tracker='+tracker+'&param=&langue='+lg;
	showHideInnerPopUp();//show login pop
	showhideCloseBtn();//hide
	showhideCloseBtn_Login();//move the boxes to the right places for the login pop
}

function openLostPass(){
	showHideInnerPopUp();//hide other pop
	DHTMLpop.width = 736;
	DHTMLpop.height = 357;
	DHTMLpop.url = main_site_url+'module=guest_mykodial_subscribe&action=accueil&webmaster=1&origin=webmaster&lostPsd=1&id='+id+'&tracker='+tracker+'&param=&langue='+lg;
	showHideInnerPopUp();//show login pop
	showhideCloseBtn();
	showhide_PassForm();//move the boxes to the right places for the login pop
}


function submitReqPassForm(){
	closePopup();//hide other pop
	DHTMLpop.width = 511;
	DHTMLpop.height = 350;
	//get the email from the new input and send it as GET var
	var email = document.getElementById('popEmailInput').value;
	DHTMLpop.url = main_site_url+'module=guest_mykodial_subscribe&action=lostPassword&webmaster=1&origin=webmaster&lostPsd=1&id='+id+'&tracker='+tracker+'&param=&langue='+lg;
	DHTMLpop.url += '&emailAccount=' + email;
	showHideInnerPopUp();//show reqpass response pop
	showhide_ReqPassResponse();
}


function showhideCloseBtn_Login(){//+Login Btn
	var popCloseBtn = document.getElementById('popCloseBtn');
	var popLoginBtn = document.getElementById('popLoginBtn');
	var popPassBtn = document.getElementById('popPassBtn');
	if(popCloseBtn.style.display == 'none'){
		//place it above the real close button
		//close btn
		posObj('popCloseBtn',708,2);
		//login btn
		posObj('popLoginBtn',60,251);
		popLoginBtn.style.width = "278px";
		popLoginBtn.href = "javascript:runPopUp();";
		popLoginBtn.onclick = "runPopUp()";
		//pass btn
		posObj('popPassBtn',650,290);
		//display 'em
		popCloseBtn.style.display = 'block';
		popLoginBtn.style.display = 'block';
		popPassBtn.style.display = 'block';
	}
	else{
		popLoginBtn.style.display = 'none';
		popPassBtn.style.display = 'none';
	}
}

function showhide_PassForm(){
	var popCloseBtn = document.getElementById('popCloseBtn');
	var popLoginBtn = document.getElementById('popLoginBtn');
	var popPassBtn = document.getElementById('popPassBtn');
	var popReqPassBtn = document.getElementById('popReqPassBtn');
	var popEmailInput = document.getElementById('popEmailInput');
/*	var iframe = window.parent.frames['innerpopup_iframe'];
	var oldEmailInput = iframe.document.getElementById('emailAccount');
	oldEmailInput.style.display = 'none';*/
	if(popCloseBtn.style.display == 'none'){
		//close btn
		posObj('popCloseBtn',708,2);
		//login btn
		posObj('popLoginBtn',61,243);
		popLoginBtn.style.width = "278px";
		popLoginBtn.href = "javascript:runPopUp();";
		popLoginBtn.onclick = "runPopUp()";
		//reqpass btn
		posObj('popReqPassBtn',540,304);
		//new email input
		posObj('popEmailInput',521,257);
		//display 'em
		popCloseBtn.style.display = 'block';
		popLoginBtn.style.display = 'block';
		popReqPassBtn.style.display = 'block';
		popEmailInput.style.display = 'block';
		popPassBtn.style.display = 'none';
		
		popEmailInput.focus();
	}
	else{
		popReqPassBtn.style.display = 'none';
		popEmailInput.style.display = 'none';
	}
}


function showhide_ReqPassResponse(){
	posObj('popCloseBtn',483,2);
	showhideCloseBtn();
}

function posObj(obj_id,left_offset, top_offset){
	if(typeof obj_id == 'undefined') return false;
	if(typeof left_offset == 'undefined') left_offset = 0;
	if(typeof top_offset == 'undefined') top_offset = 0;
	//place it above the real close button
	//close btn
	var d 		= dimension_detect();
	var DHTMLTop 	= (d.viewH-DHTMLpop.height)/2 ;
	var DHTMLLeft = (d.viewW-DHTMLpop.width)/2; 
	newLeft = DHTMLLeft + left_offset;
	newTop = DHTMLTop + top_offset;
	var obj = document.getElementById(obj_id);
	if(typeof obj == 'undefined') return false;
	obj.style.left = newLeft + 'px';
	obj.style.top = newTop + 'px';
	return true;
}


function show_hide_objects(objstatus){
	if(typeof objstatus == 'undefined') objstatus = 'visible';
	
	var os=document.getElementsByTagName('select');
	for (var i=0,o;o=os[i];i++) o.parentNode.style.visibility = objstatus;

	var os=document.getElementsByTagName('object');
	for (var i=0,o;o=os[i];i++) 
	{
		if (o.id == 'iie')	
		{
			continue;
		}

		o.parentNode.style.visibility = objstatus;
	}

	if (!document.all)
	{
		var os=document.getElementsByTagName('embed');
		for (var i=0,o;o=os[i];i++) o.parentNode.style.visibility = objstatus;
	}
}
