var lichtkrant

function $(id)
{
	return document.getElementById(id);
}

function init()
{
	lichtkrant = document.getElementById('lichtkrant');
	
	if(lichtkrant!=null)
	{
		lichtkrant.width = lichtkrant.offsetWidth;
		lichtkrant.left = 475;
		setInterval('startLichtkrant()', 20);
	}
	
	document.execCommand("BackgroundImageCache", false, true);
} 

function cl(url)
{
	window.location = url;
}

function createAlert(inhoud)
{
	var inhoud = "<h1>Validatie Fouten</h1>" + inhoud + "<p><a href='javascript:deleteAlert();' class='BUT'>OK</a></p>"
	hideChild('popup');
	createChild('alert', inhoud);
}

function createBestelEnBel()
{
	var inhoud ="<h1>Bestel en Bel</h1>";
	inhoud += "<form class='FRM' id='frm-callmenow' method='post' action='/contact.php'>"
	inhoud += "<p><label for='naam'>Naam</label><input type='text' class='TB' name='naam' id='naam' /></p>";
	inhoud += "<p><label for='actie'>Actiecode</label><input type='text' class='TB' name='actie' id='actie' /></p>";
	inhoud += "<p><label for='actie'>Aantal</label><input type='text' class='TB' name='aantal' id='aantal' /></p>";
	inhoud += "<p><label for='telefoon'>Telefoonnummer</label><input type='text' class='TB' name='telefoon' id='telefoon' /></p>";
	inhoud += "<p><a href='javascript:doBestelEnBel();' class='BUT'>Verder</a><a href='javascript:deletePopup();' class='BUT'>Sluiten</a></p>";
	inhoud += "</form>";

	createPopup('popup', inhoud);
}

function createCallMeNow()
{
	var inhoud ="<h1>Call Me Now</h1>";
	inhoud += "<form class='FRM' id='frm-callmenow' method='post' action='/contact.php'>"
	inhoud += "<p><label for='naam'>Naam</label><input type='text' class='TB' name='naam' id='naam' /></p>";
	inhoud += "<p><label for='telefoon'>Telefoonnummer</label><input type='text' class='TB' name='telefoon' id='telefoon' /></p>";
	inhoud += "<p><a href='javascript:doCallMeNow();' class='BUT'>Verder</a><a href='javascript:deletePopup();' class='BUT'>Sluiten</a></p>";
	inhoud += "</form>";

	createPopup('popup', inhoud);
}

function createChild(id, inhoud)
{
	var obj = document.createElement('div');
	obj.setAttribute('id', id);
	obj.style.visibility = 'hidden';
	
	document.getElementsByTagName('body')[0].appendChild(obj);
	
	obj.innerHTML += inhoud;
	obj.style.left = (document.documentElement.clientWidth - obj.clientWidth)/2 + 'px';
	obj.style.top = (document.documentElement.clientHeight - obj.clientHeight)/2 + 'px';
	obj.style.visibility = 'visible';
	
	return obj
}

function createLoader()
{
	var inhoud ="<h1>Uw opdracht wordt verzonden</h1><p id='p-loader'><img src='/img/ajax-loader.gif' /></p>";
	hideChild('popup');
	createChild('loader', inhoud);
}

function createLogin()
{
	var inhoud ="<h1>Klantportal</h1>";
	inhoud += "<form class='FRM' id='frm-login' method='post' action='/contact.php'>"
	inhoud += "<p><label for='naam'>Gebruikersnaam</label><input type='text' class='TB' name='gebruikersnaam' id='gebruikersnaam' /></p>";
	inhoud += "<p><label for='wachtwoord'>Wachtwoord</label><input type='password' class='TB' name='wachtwoord' id='wachtwoord' /></p>";
	inhoud += "<p><a href='javascript:deletePopup();' class='BUT'>Login</a><a href='javascript:deletePopup();' class='BUT'>Annuleren</a></p>";
	inhoud += "</form>";

	createPopup('popup', inhoud);
}

function createPopup(id, inhoud)
{	
	createTransp()
	createChild(id, inhoud);
	return false
}

function createTransp()
{
	var transH = document.getElementById('container').offsetHeight;
	var transp = document.createElement('div');
	transp.setAttribute('id','transp');
	transp.style.height = transH + 'px';
	
	document.getElementsByTagName('body')[0].appendChild(transp);
}

function deleteAlert()
{
	deleteChild('alert');
	showChild('popup');
}

function deleteChild(id)
{
	document.getElementsByTagName('body')[0].removeChild($(id));
}

function deletePopup()
{
	deleteChild('popup');
	deleteChild('transp');
}

function doCallMeNow()
{
	if(arguments.length!=0)
	{
		deleteChild('loader');
		deletePopup();	
		return;
	}
	
	var naam = $('naam').value;
	var telefoon = $('telefoon').value;
	var strVal = '';

	if(naam==''){strVal+='<li>Naam: Verplicht</li>';}
	if(telefoon==''){strVal+='<li>Telefoon: Verplicht</li>';}
	
	if(strVal!='')
	{
		createAlert('<ul>' + strVal + '</ul>');
		return;
	}

	var url = 'http://www.mobiele-zaken.nl/ajaxForm.php';
	var args = 'type=CallMeNow&naam=' + naam + '&telefoon=' +  telefoon;
	
	createLoader();
	
	httpRequest('POST', url, true, doCallMeNow, args);
}

function doBestelEnBel()
{
	if(arguments.length!=0)
	{
		deleteChild('loader');
		deletePopup();	
		return;
	}
	
	var naam = $('naam').value;
	var actie = $('actie').value;
	var aantal = $('aantal').value;
	var telefoon = $('telefoon').value;
	var strVal = '';

	if(naam==''){strVal+='<li>Naam: Verplicht</li>';}
	if(actie==''){strVal+='<li>Actiecode: Verplicht</li>';}
	if(aantal==''){strVal+='<li>Aantal: Verplicht</li>';}
	if(telefoon==''){strVal+='<li>Telefoon: Verplicht</li>';}
	
	if(strVal!='')
	{
		createAlert('<ul>' + strVal + '</ul>');
		return;
	}

	var url = 'http://www.mobiele-zaken.nl/ajaxForm.php';
	var args = 'type=BestelEnBel&naam=' + naam + '&actie=' +  actie + '&aantal=' + aantal + '&telefoon=' +  telefoon;
	
	createLoader();
	
	httpRequest('POST', url, true, doBestelEnBel, args);
}

function hideChild(id)
{
	$(id).style.display = 'none';
}


function respHandler(xmlhttp)
{
	var resp = xmlhttp.responseText;
	deleteChild('loader');
	deletePopup();
}

function showChild(id)
{
	$(id).style.display = 'block';
}

function startLichtkrant()
{  
  	lichtkrant.left -= 1;
  	
  	if(lichtkrant.left < -lichtkrant.width)
  	{
  		lichtkrant.left = 475;
  	}
  	lichtkrant.style.left = (lichtkrant.left + 'px');
}