function getLink(id) {
	if(id != "" && id != 0) {
		
		$('loading').style.visibility = 'visible'
		
		new Ajax.Request('/ch/php/getLink.php',
		{
			method:'post',
			onSuccess: function(transport) {

				var response = transport.responseText || "empty";

				if(response == 0) {
					
					$('link').innerHTML = "<span style=\"color:red\">Program description not yet available.</span>";
					
				} else {
					
					//$('link').innerHTML = "<a href=\""+response+"\" target=\"_blank\">Program Description</a>";
					Element.hide($('hider'));
					
					$('hider').style.zIndex = 500;
					$('hider').style.visibility = 'visible';
					temp = $('body').clientHeight+100+"px";
					$('hider').style.height = temp;

					new Effect.Appear($('hider'), {duration: 1.0, to: 0.8});
										
					$('frame_c').style.display = 'block'					
					
					$('prog').src = response;
					$('prog').style.display = '';
					$('prog').style.height = '550px';
					$('prog').style.border = '1px solid #999999';
				}
				
			},
			onFailure: function(){
				alert('There was a problem getting program description link.');
				$('loading').style.visibility = 'hidden'
			},
			parameters: {programID: id}
		});
	}
}

function closeLight() {
	$('frame_c').style.display = 'none';
	$('prog').style.display = 'none';
	
	new Effect.Fade($('hider'), {duration: 1.0});
	
	$('loading').style.visibility = 'hidden';
	$('prog').src = '';
}


$LOGIN = 0;

function init() {
	new Effect.Fade($('login'), { duration: 0.1 });
	
	$('login').style.visibility = 'visible';
	
	settings = {
	      tl: { radius: 10 },
	      tr: { radius: 10 },
	      bl: { radius: 10 },
	      br: { radius: 10 },
	      antiAlias: true,
	      autoPad: true
	  }

	  /*
	  Usage:

	  newCornersObj = new curvyCorners(settingsObj, classNameStr);
	  newCornersObj = new curvyCorners(settingsObj, divObj1[, divObj2[, divObj3[, . . . [, divObjN]]]]);
	  */
	  var myBoxObject = new curvyCorners(settings, "answer");
	  myBoxObject.applyCornersToAll();
	
	settings = {
	      tl: { radius: 10 },
	      tr: { radius: 10 },
	      bl: { radius: 10 },
	      br: { radius: 10 },
	      antiAlias: true,
	      autoPad: true
	  }

	  /*
	  Usage:

	  newCornersObj = new curvyCorners(settingsObj, classNameStr);
	  newCornersObj = new curvyCorners(settingsObj, divObj1[, divObj2[, divObj3[, . . . [, divObjN]]]]);
	  */
	  var myBoxObject = new curvyCorners(settings, "question");
	  myBoxObject.applyCornersToAll();
	
	  var myBoxObject = new curvyCorners(settings, "reason");
	  myBoxObject.applyCornersToAll();
}

function checkEnter(e) {
	
	var characterCode;
	
	if(e && e.which){ 
		e = e;
		characterCode = e.which;
	} else {
		characterCode = e.keyCode
	}
		
	if(characterCode == 13){
		login();
	} else {
		
	}
}

function showLogin() {
	
	if($LOGIN == 0) {
		new Effect.Appear($('login'), { duration: 1.0, to: 0.8 });
		$LOGIN = 1;
	} else {
		new Effect.Fade($('login'), { duration: 1.0 });
		$LOGIN = 0;
	}
	
	//check login first
	new Ajax.Request('/ch/php/login.php',
	{
		method:'post',
		onSuccess: function(transport) {

			var response = transport.responseText || "empty";
			
			if(response == 0) {
				
			} else if (response == 1) {
				window.location  = '/ch/admin/';
			}
		},
		onFailure: function(){
			alert('There was a problem checking login.')
		},
		parameters: {user: "", pass: ""}
	});	
}

function login() {
	
	$('loader1').style.visibility = 'visible';
	
	$('message').innerHTML = '';
	pass_encoded = hex_md5($('pass').value);
	
	new Ajax.Request('ch/php/login.php',
	{
		method:'post',
		onSuccess: function(transport) {

			var response = transport.responseText || "empty";

			response = eval('(' + response + ')');
			
			$('loader1').style.visibility = 'hidden';
			
			if(response[0] == 0) {
				$('message').innerHTML = response[1];
			} else if(response[0] == 1) {
				window.location = "/ch/admin/"+response[1];
			}
		},
		onFailure: function(){
			alert('There was a problem logging in.')
		},
		parameters: {user: $('user').value, pass: pass_encoded}
	});
}

function send() {
	
	if($('organization').value != '' && $('contact').value != '' && $('email').value != '' && $('web').value != '') {
		
		organization = $('organization').value;
		contact = $('contact').value;
		email = $('email').value;
		web = $('web').value;
		
		new Ajax.Request('ch/php/sendForm.php',
		{
			method:'post',
			onSuccess: function(transport) {

				var response = transport.responseText || "empty";

				alert("Your message has been send. One of our employees will contact you within 12 hours.")
			},
			onFailure: function(){
				alert('There was a problem sending the form.')
			},
			parameters: {organization: organization, contact: contact, email: email, web: web}
		});
		
	} else {
		alert('Please complete the form.')
	}
}