function displayEmailWarning () {
	alert("Valley Capital Bank asks that you do not send any sensitive banking or personal information in your correspondence with VCBNA staff. \n\n Thank You.");
}

function configureValidations(){
	var forms = document.getElementsByTagName('form');
	for (var i=0; i < forms.length; i++) {
		if (forms[i].className.indexOf("required") > -1) {
			new Validation(forms[i].id);
		};
	};
}

// This function will hide all lists with a class of child_list
function hideChildren(){
	
	var children = document.getElementsByTagName('ul');
	for (var i=0; i < children.length; i++) {
		if (children[i].className == "child_list" ) {
			children[i].style.cssText = "display:none;";
		};
	};
}

// This function will hide OTHER lists that don't belong to the parent that was just clicked
function hideOthers(parent){

	var children = document.getElementsByTagName('ul');
	for (var i=0; i < children.length; i++) {
		if (children[i].className == "child_list" && children[i].id != parent + "_child") {
			Element.toggle(children[i].id);
		};
	};
}
	
// This function will display the child_list and hide others
function showChildren(parent){
	hideOthers(parent);
	var child_list = $(parent + '_child'); // The $('') method is a prototype method that's the same as document.getElementById()
	Element.toggle(child_list.id); // Scriptaculous effect to show the child list
}

// show or hide elements onclick
function showHide(id) {
	var element = $(id)
	/*
	if (element.style.display == "none") {
		new Effect.BlindDown(element.id);
	} else {
		new Effect.BlindUp(element.id);
	}
	*/
	Element.toggle(id)
}

// hide all divs with a class of "solo"
function hideSolos(){

	var divs = document.getElementsByTagName('div');
	for (var i=0; i < divs.length; i++) {
		if (divs[i].className == "solo") {
			divs[i].style.display = "none";
			//new Effect.BlindUp(divs[i].id);
		};
	};
}

// alternate table row class (background color)
function alternateRows(){

	var rows = document.getElementsByTagName('tr');
	for (var i=0; i < rows.length; i++) {
		if (i % 2) {
					rows[i].className = "odd";
				} else {
					rows[i].className = "even";
				};
	};
}

// show or hide elements one at a time
function showHideSolo(id){
	if (id != "") {
		hideSolos();
		//new Effect.BlindDown(id);
		Element.toggle(id);
		document.getElementById('media_type_select').value = id;
	};
}

// popup window for guarantee
var newwindow;
function popwindow(url){
	newwindow=window.open(url,'name','height=600,width=800,scrollbars=1');
	if (window.focus) {newwindow.focus()}
}

// Form Validation
function validateForm(id){
	var validator = new Validation(id, {useTitles : true});
	return validator.validate();
}

// Check for Dupe E-Mail
function emailCheck(email){
	var update = "email_check";
	var url =  base_url + "/bin/check_dupe_email.php";
	var params = "email=" + email;

	var aUpdater = new Ajax.Updater(update, url, {method: "post", parameters: params, onComplete: function(transport){
		if (transport.responseText != "") {
			Element.toggle(update.id)
			return false;
		}else{
			return true;
		};
	}});

}

function isUSA(value, type){
	if (value == "United States") {
		$(type + '_province').disabled = true;
		$(type + '_state').disabled = false;
	}else{
		$(type + '_province').disabled = false;
		$(type + '_state').disabled = true;
	};
}

function checkSpelling(id){
	var area = $(id);
	var speller = new spellChecker(area);
	speller.openChecker();
	return false;
}

// show active link
function showActiveLink(){
	var a = document.getElementsByTagName('a');
	var url = location.href;
	
	for (var i=0; i < a.length; i++) {
		if (a[i].href == location.href) {
			a[i].style.cssText = "font-weight:bold;color:#000;text-decoration:none;";
		};	
	};
}

function showActiveAdminLink(){
	// var a = document.getElementsByTagName('a');
	// var url = location.href;
	// 
	// for (var i=0; i < a.length; i++) {
	// 	if (a[i].href == url) {
	// 
	// 		switch(a[i].className){
	// 			case('nav_link'):
	// 				a[i].className = 'active_nav_link';
	// 				break
	// 			case('pager_link'):
	// 				a[i].className = 'active_pager_link';
	// 				break
	// 			case('image'):
	// 				// do nothing
	// 				break
	// 			default:
	// 				a[i].className = 'active_generic_link';
	// 		}
	// 	}
	// 	else if (url.search('/admin-message/') != '-1') {
	// 		$('nav_admin_message').className = 'active_nav_link';
	// 	}
	// 	else if (url.search('/user/') != '-1') {
	// 		$('nav_user').className = 'active_nav_link';
	// 	}
	// 	else if (url.search('/admin-user/') != '-1') {
	// 		$('nav_admin_user').className = 'active_nav_link';
	// 	}
	// 	
	// };
}

function insertAfter(newElement, targetElement){
	var parent = targetElement.parentNode;
	if (parent.lastChild == targetElement) {
		parent.appendChild(newElement);
	}else{
		parent.insertBefore(newElement, targetElement.nextSibling);
	};
}

/**
 *
 * Some Functions for the custom actions on this site.
 *
 **/

function	addPhotoField(target, type){
	
	var targetElement = $(target);
	para = document.createElement("p");
	
	input = document.createElement("input");
	input.setAttribute("name", "images[]");
	input.setAttribute("type", "file");
	
	targetElement.appendChild(para)
	para.appendChild(input);
	
	return false;
	
}

function addBlogCommentField(target){
	
}

function approveComment(id, toggle){
	params = "id=" + id;
	url = base_url + '/bin/approve_blog_comment.php';
	new Ajax.Request(url, {method:"post", parameters:params});
	$(toggle).className = "comment_box";
	Element.toggle($(toggle).id);
	return false;
}

function deleteObject(class_name, id, toggle){
	params = "class=" + class_name + "&id=" + id;
	url = base_url + "/bin/delete_object.php";
	new Ajax.Request(url, {method:"post", parameters:params});
	Element.toggle($(toggle).id);
}

function deleteComment(class_name, id, toggle){
	if (confirm("Are You Sure?")) {
		deleteObject(class_name, id, toggle);
	};
	return false;
}

function deleteGalleryImage(objectClass, id){
	var cell = objectClass + "_" + id;
	params = "class="+objectClass+"&id="+id
	url = base_url + "/bin/delete_gallery_image.php";
	new Ajax.Request(url, {method:"post", parameters:params});
	$(cell).toggle();
	return false;
}

function swapImage(dest, source){
	var dest_image = $(dest);
	var source_image = $(source);
	
	var source_src = $(source).src.replace("_thumb", "_small");
	
	dest_image.src = source_src;
	return false;
}

function showAnswer (id) {
	Element.toggle(id.replace("num_","answer_"));
	return false;
}

// Ajax sign guestbook
function remote_signGuestBook(form){
	var serialized = $(form).serialize();
	$('remote_sign_guest_book').removeChild($(form));
	new Ajax.Updater('remote_sign_guest_book', base_url + '/index.php?controller=guest-book&action=add_visitor_entry', {method:'post', parameters:serialized} );
	return false;
}

// Sort Photos
function startSortPhotos(){
	$('start_sort_photos').toggle();
	$('finish_sort_photos').toggle();
	
	$('gallery_container').childElements().each(
	    function(li){
	        li.childElements().each(
	            function(e){
	               if( ($w(e.className).indexOf('delete') > -1) ){
	                e.toggle();
	               }
	            }
	        )
			if (($w(li.className).indexOf('divider') > -1)) {
				li.toggle();
			}else{
				li.addClassName('draggable');
			};
	        
	    }
	);

	Sortable.create('gallery_container',{tag:'li', constraint:'none'});
	return false;
}

function finishSortPhotos (object_class) {
	var serializedGallery = Sortable.serialize('gallery_container');
	serializedGallery += "&type="+object_class
	new Ajax.Request(base_url + '/bin/sort_photos.php', {parameters:serializedGallery, onComplete:updateGallery()});
}

function updateGallery () {
	$('finish_sort_photos').toggle();	
	$('start_sort_photos').toggle();
	
	$('gallery_container').childElements().each(
	    function(li){
	        li.childElements().each(
	            function(e){
	               if( ($w(e.className).indexOf('delete') > -1) ){
	                e.toggle();
	               }
	            }
	        )
	        li.removeClassName('draggable');
	    }
	);
}