// JavaScript Document
<!--
window.onload = initAll;

function showForm(ajaxURL, boxWidth){
	var width = document.documentElement.clientWidth + document.documentElement.scrollLeft;
	
    var layer = document.createElement('div');
    layer.style.zIndex = 2;
    layer.id = 'layer';
    layer.style.position = 'absolute';
    layer.style.top = '0px';
    layer.style.left = '0px';
    layer.style.height = document.documentElement.scrollHeight + 'px';
    layer.style.width = width + 'px';
    layer.style.backgroundColor = 'black';
    layer.style.opacity = '.8';
    layer.style.filter += ("progid:DXImageTransform.Microsoft.Alpha(opacity=60)");
    document.body.appendChild(layer);
	
	var div = document.createElement('div');
    div.style.zIndex = 3;
    div.id = 'box';
    div.style.position = (navigator.userAgent.indexOf('MSIE 6') > -1) ? 'absolute' : 'fixed';
    div.style.top = '70px';
    div.style.left = (width / 2) - (boxWidth / 2) + 'px'; 
    //div.style.height = '500px';
    div.style.width = boxWidth + 'px';
    div.style.backgroundColor = '#FFFFFF';
    div.style.border = '2px solid #999999';
    div.style.padding = '20px';
    div.style.opacity = '0';

	document.body.appendChild(div);
	appear($('box'), {
		afterFinish: function(){
			buildForm(ajaxURL);
			}
		});
	
	function buildForm(ajaxURL){
		var p = document.createElement('div');
		var ajaxCall = new Request({url: ajaxURL,
								    method: 'get',
									onSuccess: function(responseText){
													p.innerHTML = responseText;
												}
								   }
								  ).send();
		
		
		p.style.fontWeight = 'bold';
		p.style.fontFamily = 'geneva, arial';
 		div.appendChild(p);
		
    	var a = document.createElement('a');
	    a.innerHTML = '<img src=images/closelabel.gif>';
		a.style.fontWeight = 'bold';
		a.style.fontFamily = 'geneva, arial';
    	a.href = 'javascript:void(0)';
	    a.onclick = function() 
    	{
			document.body.removeChild(document.getElementById('layer'));
			document.body.removeChild(document.getElementById('box'));
		};
      
    	div.appendChild(a);
	}	
}

function sendRegister(form){
	if(checkForm(form)){	
		var params = 'wedding_email=' + form.wedding_email.value +
					'&passwd=' + form.passwd.value +
					'&brides_surname=' + form.brides_surname.value +
					'&brides_firstname=' + form.brides_firstname.value +
					'&grooms_surname=' + form.grooms_surname.value +
					'&grooms_firstname=' + form.grooms_firstname.value;
					
		var ajaxCall = new Request({url: 'include/ajax.register.php',
								    method: 'get',
									onRequest: function(){
													$('ajaxResponse').className = 'ajaxWarning';
													$('ajaxResponse').innerHTML = '<img src=images/ajax-loaderBAR.gif>';
												},
									onSuccess: function(responseText){
													if(responseText == '1'){
														clearForm(form);
														$('ajaxResponse').className = 'accepted';
														$('ajaxResponse').innerHTML = '<img src=images/accept.png align=absmiddle> Registration sucessful. Check your email for activation link.';
													}else{
														$('ajaxResponse').className = 'ajaxWarning';
														$('ajaxResponse').innerHTML = '<img src=images/denied.png align=absmiddle> Registration failed. Is your email already registered?';
													}
												}
								   }
								  ).send(params);
	}
}

function initAll(){
		var ajaxCall = new Request({url: 'getGiftZone.php',
								    method: 'get',
									onRequest: function(){
													$('giftZone').innerHTML = "<p>&nbsp;</p><p align='center'><img src='images/ajax-loader.gif'><p>";
											},
									onSuccess: function(responseText){
													$('giftZone').innerHTML = responseText;
												}
								   }
								  ).send();
		initAll.delay(10 * 1000);
}

function checkForm(form)
{
  for(var i = 0; i < form.elements.length - 1; i++){
	if(form.elements[i].value == ""){
		form.elements[i].style.backgroundColor='#f68081';
		var x = 1;
	}else{
		form.elements[i].style.backgroundColor='#FFFFFF';
	}
  }
  
  if(x == 1){
  	return false;
  }
  
  return true;
}

function clearForm(form){
	for(var i = 0; i < form.elements.length - 1; i++){
		form.elements[i].value = "";
	  }
}

function checkDetails(form, fields)
{
  for(var i = 0; i < fields; i++){
	if(form.elements[i].value == ""){
		form.elements[i].style.backgroundColor='#f68081';
		var x = 1;
	}else{
		form.elements[i].style.backgroundColor='#FFFFFF';
	}
  }
  
  if(x == 1){
  	return false;
  }
  
  return true;
}

function hideGiftZone()
{
	blindUp('giftZone');	
	blindUp('giftZoneTitle');
	var a = document.getElementById('toggleGiftZone');
	a.innerHTML = '<a href="#" onclick="showGiftZone()">Show random gifts</a>';
}

function showGiftZone()
{
	blindDown('giftZone');	
	blindDown('giftZoneTitle');
	var a = document.getElementById('toggleGiftZone');
	a.innerHTML = '<a href="#" onclick="hideGiftZone()">Hide random gifts</a>';
}
//-->
