function closeNewsletter(popupid,transbackid){
		var transparent_bg = document.getElementById(transbackid);
		if(transparent_bg.style.display=='none') return;
		var container = document.getElementById(popupid);
		var form_container = document.getElementById('newsletterblock');
		
		form_container.innerHTML ='<form><img src="/images/newsclosebutton.gif" style="margin-left: 185px; cursor: pointer; "  onclick="javascript:closeNewsletter(\'newsletterblock\',\'ContactBlock\')" /><div style="width: 180px; margin-bottom: 7px;">Sign up for the FTHK newsletter for the latest on shows and FTHK news</div><div style="margin-bottom: 4px;">Your Name</div><div style="margin-bottom: 4px;"><input type="text" id="yourname" name="yourname" class="Newsletterflied"/></div><div style="margin-bottom: 4px;">Your E-mail address</div><div style="margin-bottom: 7px;"><input type="text" id="youremail" name="youremail" class="Newsletterflied"  /></div><div style="margin-bottom: 16px;"><input type="button" name="newsletterbtn" id="newsletterbtn" value="Sign Up"  onclick="javascript:Subscribe();"  style="width: 181px;"/></div></form>';
		transparent_bg.style.display="none";
		container.style.display ="none";
		return;	
}
function closeBlock(mod_container,mod_fromnewsletter){
	
	var mod_container = document.getElementById(mod_container);	
	var mod_fromnewsletter = document.getElementById(mod_fromnewsletter);
	if(mod_fromnewsletter) mod_fromnewsletter.innerHTML = '<form><img src="/images/newsclosebutton.gif" style="margin-left: 185px; cursor: pointer; "  onclick="javascript:closeNewsletter(\'newsletterblock\',\'ContactBlock\')" /><div style="width: 180px; margin-bottom: 7px;">Sign up for the FTHK newsletter for the latest on shows and FTHK news</div><div style="margin-bottom: 4px;">Your Name</div><div style="margin-bottom: 4px;"><input type="text" id="yourname" name="yourname" class="Newsletterflied"/></div><div style="margin-bottom: 4px;">Your E-mail address</div><div style="margin-bottom: 7px;"><input type="text" id="youremail" name="youremail" class="Newsletterflied"  /></div><div style="margin-bottom: 16px;"><input type="button" name="newsletterbtn" id="newsletterbtn" value="Sign Up"  onclick="javascript:Subscribe();"  style="width: 181px;"/></div></form>';	
		mod_container.style.display="none";	
		mod_fromnewsletter.style.display="none";
				
}

function ShowBlock(newsletterblock,ContactBlock,newsletter){
	var newsletterblock = document.getElementById(newsletterblock);	
	var newsletter = document.getElementById(newsletter);	
	var ContactBlock = document.getElementById(ContactBlock);

	var left = getAbsLeft(newsletter);
	var top = getAbsTop(newsletter);
	
	newsletterblock.style.top = top + 'px';
	newsletterblock.style.left = left + 'px';
	
	newsletterblock.style.display="block";	
	ContactBlock.style.display="block";
	
	// Set focus to the first text field
	var inputs = newsletterblock.getElementsByTagName('input');
	if(inputs && inputs.length){
		for(i=0;i<inputs.length;i++){
			if(inputs[i].type=='text'){
				inputs[i].focus();
				break;
			}
		}
	}
}

function Subscribe(){
	var form_container = document.getElementById('newsletterblock');
	var name = document.getElementById('yourname').value;
	var email = document.getElementById('youremail').value;
	
	var Msg ='';
	if(name=='') Msg = 'Please enter your name name\n\r';
	if(email=='') Msg += 'Please enter your email address\r\n';
	else if(email.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) == -1) Msg +='Please enter a correct email address.\r\n';
	if(Msg==''){
		form_container.innerHTML='<div style="width: 180px; margin-bottom: 7px;">Sending request...</div>';
		var res =agent.call('/ajax/CMBase.ajax.php','addSubscription','',name,email);
		if(res == 0) return form_container.innerHTML='<img src="/images/newsclosebutton.gif" style="margin-left: 185px; cursor: pointer; "  onclick="javascript:closeNewsletter(\'newsletterblock\',\'ContactBlock\')" /><div style="width: 180px; margin-bottom: 7px;">Thank you for subscribing to the Africa!Ignite newsletter. An email has been sent to you to confirm your subscription.</div>';
		else return form_container.innerHTML= res+'\nTo report this error please click <a href="mailto:info@fthk.co.za?subject=Newsletter+sign-up+error">here</a>.';
	}else return alert(Msg);

}


function hidePopup(popupid,transbackid){
	var popup = document.getElementById(popupid);
	var transback = document.getElementById(transbackid);
	if(popup){
		transback.style.display = 'none';
		popup.style.display = 'none';
	}
}
