// JavaScript Document

function load_dialog(field_obj_id, selector, errorContainer, targetDiv)
{
	$( '#'+targetDiv ).dialog({
		modal: true,
		width: 350,
		buttons: {
			"Save": function() {
				if($.trim($('#'+field_obj_id).val()) == '')
				{
					$('#'+errorContainer).html('Name is required.').addClass('ui-state-error');
				} else { 
					$.post('action.php?dynamic', 
						{ command: field_obj_id, value: $('#'+field_obj_id).val() }, 
						function(data) { 
							$('#'+selector).append('<option value="'+$.trim(data)+'" selected="selected">'+$('#'+field_obj_id).val()+'</option>');
							$( '#'+targetDiv ).dialog( "close" );
							$( '#'+errorContainer ).html( "" );
							$( '#'+field_obj_id ).val( "" );
						}
					); 
				}
			},
			Cancel: function() {
				$( this ).dialog( "close" );
				$( '#'+errorContainer ).html( "" );
				$( '#'+field_obj_id ).val( "" );
			}
		}
	});
}

//used only for content module to generate content code
function generate_content_code()
{
	var PageTitle = $.trim($('#title').val());
	var PageTitle = PageTitle.replace(/ /g, "-");
	re = /\$|,|@|#|~|`|\%|\*|\/|\^|\&|\(|\)|\+|\=|\[|\;|\_|\]|\[|\}|\--|\{|\;|\:|\'|\"|\<|\>|\?|\||\\|\!|\$|\./g;
	var PageTitle = PageTitle.replace(re, "");
	$('#content_code').val(PageTitle.toLowerCase());
}

$(document).ready(function() {
	if(document.getElementById('info_panel') && document.getElementById('info_panel').style.display == '')
	{
		$('#info_panel').fadeIn().delay(6000).slideUp('slow');
	}
});

function confirm_box()
{
	var cmd = confirm('Are you sure you want to cancel? There is no undo/redo?');
	if(cmd)
	{
		//javascript:history.back(1);
		window.location = 'index.php';
	} else { return false; }
}

function reset1(n, v){
	if (n.value == v) {
	n.value = "";	
	}
}

function reset2(n, v){
	if (n.value == "") {
	n.value = v;	
	}
}


$(window).load(function() {
	$('#slider').nivoSlider({
	directionNav:false,
	controlNav:false			
	});
});

function validate_h()
{
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	if($.trim($('#name').val()) == '' || $.trim($('#name').val()) == 'Name') {
		alert("Name is required.");
		return false;
	}
	else if($.trim($('#email').val()) == '' || $.trim($('#email').val()) == 'Email') {
		alert("Email is required.");
		return false;
	}
	else if(!filter.test($('#email').val()) && !filter.test($('#email').val())) {
		alert("Please input a valid email address!");
		return false;
	}
	else if($.trim($('#phone').val()) == '' || $.trim($('#phone').val()) == 'Phone') {
		alert("Phone is required.");
		return false;
	}
	else {
		$temp = new Date().getTime(); 
		$.post('includes/root/controller.php?'+$temp, { cmd: 'h_form', name:$('#name').val(), email:$('#email').val(), phone:$('#phone').val() }, function(response) {
			document.getElementById('contact_form').reset();
			eval(response);
		});
		return false;
	} 
}
