//TOOL TIP//
$(document).ready(function() {
	$('.tooltip_top').bt({
	  fill: '#cccccc', 
	  spikeLength: 8, 
	  spikeGirth: 8, 
	  padding: 8, 
	  positions: 'top',
	  width: 250,
	  cornerRadius: 0, 
	  cssStyles: {
	    fontFamily: 'Arial', 
	    fontSize: '11px'
	  }
	});

	
});

//HOME PAGE//
function enlarge_home_image(sml, lrg){
	var img_src = $("#home_image").attr("src");
	
	if(img_src.match(lrg)){
		$("#home_image").attr("src", sml);
		$("#home_enlarge_lnk").text("Click for full screen image");
	}else{
		$("#home_image").attr("src", lrg);
		$("#home_enlarge_lnk").text("Click to reset image size");
	}
}

//ARCHIVE & WINNERS RECORD//
function change_archive_image(file, obj){
	var img_src = $("#archive_enlarge_view").attr("src");
	$("#archive_enlarge_view").attr("src", file);
	
	$(".ls a").attr("class", 'bold');
	$("#" + obj).attr("class", 'bold_red');
}

//CFE Credits Row Clone//
function creditClone(){
	var cloneObj = $("#credit_clone_0").clone().insertBefore("#credit_above");
	cloneObj.show();
	var cloneIndex = $(".credit_clone").length - 1;
	
	cloneObj.attr("id", "credit_clone_" + cloneIndex);

	
	cloneObj.find(".credit_del").attr("href",  "javascript:creditRemove('credit_clone_"+cloneIndex+"')" );
	var flData = new Array(
					new Array(".credit_name", "data[entry_credits]["+cloneIndex+"][name]", 1),
					new Array(".credit_lastname", "data[entry_credits]["+cloneIndex+"][lastname]", 1),
					new Array(".credit_title", "data[entry_credits]["+cloneIndex+"][credit_titles_id]", 1),
					new Array(".credit_id", "data[entry_credits]["+cloneIndex+"][id]", 1),
					new Array(".credit_entry_applications_id", "data[entry_credits]["+cloneIndex+"][entry_applications_id]", 0),
					new Array(".credit_optionalrow", "data[entry_credits]["+cloneIndex+"][optionalrow]", 0)
	);
	
	for(var x=0; x < flData.length; x++){
		var clO = cloneObj.find( flData[x][0] );
		clO.attr("name",  flData[x][1] );
		if(flData[x][2]){
			if(clO.attr("tagName") == "SELECT"){
				clO.val(0);	
			}else{
				clO.attr("value", "");			
			}
		}
	}
}

function creditRemove(objRow){
	var cloneObj = $("#" + objRow);
	cloneObj.hide( );
	
	var flData = new Array(
					new Array(".credit_name", 1),
					new Array(".credit_lastname", 1),
					new Array(".credit_title", 1)
	);
	for(var x=0; x < flData.length; x++){
		var clO = cloneObj.find( flData[x][0] );
		
		if(flData[x][1]){
			if(clO.attr("tagName") == "SELECT"){
//				clO.val(0);	
				clO.remove();
			}else{
				clO.removeAttr("value");
			}
		}
	}
	
}

//SEARCH//
$(document).ready(function() {
	$("#sites_search").focus(function () {
	 if($(this).val() == "SEARCH"){
	  $(this).val('');
	 }
	});
	$("#sites_search").blur(function () {
	 if($(this).val() == ""){
	  $(this).val('SEARCH');
	 }
	});
});

function linkedComboBox(val, el){
	url_ajax = "/search/ajax/?book=" + val;
	$.getJSON(url_ajax,
    	function(ajax_data){
			var init_option = $(el).find('option').attr("text");
			$(el).empty().data('options');
		
			$(el).append($('<option>').text("- - Select All Categories - -").val(""));
		
 			$.each(ajax_data, function(i) {
 				var option = ajax_data[i];
				$(el).append(
                	$('<option>').text(option.text).val(option.value)
                );
 			});
			
// 			 $(el + " option").each(function () {
// 			 	$(this).attr("selected", "selected"); 			 	
// 			 });
 			
			$(el).dropdownchecklist("destroy");
			$(el).dropdownchecklist({ firstItemChecksAll: true, maxDropHeight: 200, width: 262 });
	   	}
    );
}



//STORE//
function addToBasket(objCheck){
	var objC = $("." + objCheck+":checked");

	for(var x=0; x < objC.length; x++){
		var objCVal = objC[0].value;
	}
	if(objCVal == undefined){
		alert("Please select an product you would like to purchase");
		return false;
	}else if(objC.attr("id") == "prod_ln-sub"){
		window.location = "/store/?p="+objCVal+"&action=standing_add";
	}else{
		window.location = "/store/?action=add&p=" + objCVal;
	}

}

function checkOut(message){
	if($("#priority_code").attr("value") != ""){
		submitForm(document.items, '?action=update&checkout=1')	;
	}else{
		if(confirm(message)){
			submitForm(document.items, '?action=update&checkout=1');
		}
	}
}


function addToBasketAward(objID){
	jQuery.facebox({ ajax: '/store_awards_ajax/?product_item_id='+objID })	
}

//PROFILES//
$(document).ready(function() {
	$(function(){
		$('.wide p').addClass("dontsplit");
		$('.wide').columnize({columns:2});
		
		$('.wide_account').columnize({columns:2});
		
		$('.wideclub p').addClass("dontsplit");
		$('.wideclub').columnize({columns:4});
	});
	
});


function addSectors(d_profile_id, d_constituant_agency_type_id, d_seleted){
	$(document).ready(function() {
		var urlGET = "/get/profile/checkbox/";
	
		$('#focus_div').fadeTo("slow", 0.2, function () {
			$.ajax({
			  type: 'GET',
			  url: urlGET,
			  dataType: 'html',
			  data: { profile_id: d_profile_id, constituant_agency_type_id: d_constituant_agency_type_id, seleted: d_seleted},
			  success: function(data){
				$('#focus_div').replaceWith(data);
			  },
			  error: function(){
				alert("An error has occurred while trying to retrieve more portfolio pieces. Please try again.");
			  },
			  complete: function() {				  
				goUp('#focus_div');
			  }
			  
			});
			  
			return false;		
						
		});
		
		function goUp(who) {		
			$(who).fadeIn("fast");		
		}
	});
}

function ifPhotoGraphy(selected_id){
	$(document).ready(function() {
		if(selected_id == 17){
			$('#photography_selected').show();
		}else{
			$('#photography_selected').hide();
		}
	});
}

function htmlFieldsClone(pre_class, exclude_clean, btn_obj){
	if(exclude_clean != ""){
		var excludeArr = exclude_clean.split(",");
	}else{
		var excludeArr = new Array ();
	}
	var mainTable = "";
	
	if(btn_obj){
		mainTable = btn_obj.closest("table").attr("id");
	}
	
	if(mainTable != ""){
		var cloneObj = $("#" + mainTable + " ." + pre_class + "_0").clone().insertBefore("#" + mainTable + " ." + pre_class+"_end");
		cloneObj.removeClass(pre_class + "_0");
		cloneObj.show();
		var cloneIndex = $("#" + mainTable + " ." + pre_class + "_cl").length - 1;
	}else{
		var cloneObj = $("#"+pre_class+"_0").clone().insertBefore("#"+pre_class+"_end");
		cloneObj.show();
		var cloneIndex = $("." + pre_class + "_cl").length - 1;
		cloneObj.attr("id", pre_class + "_" + cloneIndex);
	}
	
	var strtest = cloneObj.find("input").each(function (){
		var allowClean = true;
		$(this).attr('name', $(this).attr('name').replace("[0]", "[" + cloneIndex + "]"));
		
		if($(this).attr('name').indexOf("[optionalrow]") != "-1"){
			allowClean = false;			
		}
		
		if(excludeArr.length > 0){
			for(x = 0; x < excludeArr.length; x++){
				if(allowClean == true){
					if($(this).attr('name').indexOf("["+excludeArr[x]+"]") != "-1"){
						allowClean = false;
					}
				}
			}
		}
		
		if(allowClean){
			$(this).attr("value", "");
		}
		
	});
}

function dupProfileAwardName(val, rwcls, txt_obj){
	var mainTable = "";
	if(txt_obj){
		mainTable = "#" + txt_obj.closest("table").attr("id") + " ";
	}
	
	$(mainTable + "." + rwcls + " .club_award_name").each(function (){
		$(this).attr("value", val);
	});	
}

function htmlFieldsCloneAwards(pre_class, btn_obj){
	var excludeArr = new Array ("optionalrow","award_type");
	
	var cloneTAfterIndex = $(".clubothawards_main_cl").length - 1;
	var cloneObj = $("#"+pre_class+"_0").clone().insertAfter("#"+pre_class+"_" + cloneTAfterIndex);
	cloneObj.show();
	
	var cloneTIndex = $(".clubothawards_main_cl").length - 1;
	cloneObj.attr("id", pre_class + "_" + cloneTIndex);
	
	var cloneIndex = $(".clubothawards_main_cl").length + 1;
	var strtest = cloneObj.find("input").each(function (){
		if($(this).attr('type') != "button"){
			$(this).attr('name', $(this).attr('name').replace("data[constituant_portfolio_clubawards][2]", "data[constituant_portfolio_clubawards][" + cloneIndex + "]"));
			var allowClean = true;
			
			for(x = 0; x < excludeArr.length; x++){
				if(allowClean == true){
					if($(this).attr('name').indexOf("["+excludeArr[x]+"]") != "-1"){
						allowClean = false;
					}
				}
			}
			if(allowClean){
				$(this).attr("value", "");
			}
		}
	});
}

//PORTFOLIOS//
$(document).ready(function() {
	$('.more_lnk').click(function(){
		var urlLink = "/profiles/ajax/";
		 
		$(this).css("cursor","pointer");
		$(this).css("cursor","hand");						  
							  
		var i = ($(this).attr('id'));
		
		$('#loading'+i).css("display","inline");		
		if( $(this).children("img").attr("class") == "portfolio"){
			urlLink = "/portfolios/ajax/";
		}else if( $(this).children("img").attr("class") == "archive"){
			urlLink = "/archive/winners/ajax/";
		}else if( $(this).children("img").attr("class") == "whoswho"){
			urlLink = "/portfolios/ajax/?whoswho=1";
		}else if( $(this).children("img").attr("class") == "whoswho-profile"){
			urlLink = "/profiles/ajax/?whoswho=1";
		}
//		alert(urlLink + " " + i);
		
		$('#ajaxResults'+i).fadeTo("slow", 0.2, function () {
						
			$.ajax({
			  type: 'POST',
			  url: urlLink, // /portfolios/ajax/ /profiles/ajax/
			  dataType: 'html',
			  data: { id: i },
			  success: function(data){
				$('#ajaxResults'+i).replaceWith(data);
			  },
			  error: function(){
				//alert("An error has occurred while trying to retrieve more portfolio pieces. Please try again.");
			  },
			  complete: function() {				  
				$('#loading'+i).css("display","none");
				goUp('#ajaxResults'+i);
			  }
			  
			});
			  
			return false;			
						
		});					  
			
	 });
	
	$('.more_lnk').mouseover(function(){								  
		$(this).css("cursor","pointer");
		$(this).css("cursor","hand");	
	});
	
	function goUp(who) {		
		$(who).fadeIn("fast");		
	}

});


//ANNUAL REPORTS//
function setSubMenuOn(onmenu){
	$(document).ready(function() { 
		$(".subnav").children("a").removeClass("submenuOn");
		
		$("#" + onmenu).addClass("submenuOn");
	});
}


//OLD JAVASCRIPT//
function browser(){
	this.dom = (document.getElementById) ? true : false;
	this.ns4 = (document.layers) ? true : false;
	this.ie = (document.all) ? true : false;
	this.ns6 = this.dom && !this.ie
	this.ie4 = this.ie && !this.dom;
	this.opera = (navigator.userAgent.indexOf("Opera") != -1);
	this.mac = (navigator.appVersion.indexOf("Mac") != -1);
	this.macie4 = this.ie4 || this.mac;
	this.dhtml = (this.dom || this.ns4 || this.ie || this.ie4 || this.opera || !this.mac) ? true : false;
	this.dhtml = (this.mac)?false:true;
	return this;
}

var bw = new browser();

function toggleTable(el,st) {
	var myelement = document.getElementById(el);

	if(st == 1){
		if(bw.ie){
			myelement.style.display = "inline"
		}else{
			myelement.style.display = "table-cell"
		}
	}else{
		myelement.style.display = "none"
	}
}


//for renew screen
function show_hide_join_code(e1,st,req){

	theform = document.register;

	if(st != 1){
		//when hide, clear values
		theform.elements["data[link_constituants_constituant_type][0][join_code]"].value = "";
		theform.elements["data[link_constituants_constituant_type][0][join_user_id]"].value = "";
	}else{
		if(req != 1){
			document.getElementById("join_code_man").innerHTML = "<b class='mandatory'>*</b>";
			document.getElementById("join_user_id_man").innerHTML = "<b class='mandatory'>*</b>";
		}else{
			document.getElementById("join_code_man").innerHTML = "";
			document.getElementById("join_user_id_man").innerHTML = "";
		}
	}

	toggleTable(e1,st);
}


//register screen
function how_hear_text(id){

	theform = document.register;

	if(id == "Other"){
		toggleTable('type_1',1);
		toggleTable('type_2',0);
		theform.elements["data[constituants][0][how_hear]"].value = "";
		theform.elements["data[constituants][0][referal]"].value = "";
	}else if(id == "From an ADC member"){
		toggleTable('type_1',0);
		toggleTable('type_2',1);

		theform.elements["data[constituants][0][how_hear]"].value = id;
		theform.elements["data[constituants][0][referal]"].value = "";
	}else{
		toggleTable('type_1',0);
		toggleTable('type_2',0);
		theform.elements["data[constituants][0][how_hear]"].value = id;
		theform.elements["data[constituants][0][referal]"].value = "";
	}
}

function constituant_industry_text(id){

	theform = document.register;

	if(id == "Other"){
		toggleTable('constituant_industry_type_1',1);
		theform.elements["data[constituants][0][constituant_industry]"].value = "";
	}else{
		toggleTable('constituant_industry_type_1',0);
		theform.elements["data[constituants][0][constituant_industry]"].value = id;
	}
}



function mandatory_zip(obj_id,value) {

	if(value == 840 || value == 124){
   		document.getElementById(obj_id).innerHTML = "<b class='mandatory'>*</b>";
	}else{
		document.getElementById(obj_id).innerHTML = "";
	}
}

function set_state(theform,str,the_element){
	theform.elements[the_element].value = str;
}

function country_states(id, theform, the_element, prefix,clear){

	if(id == 840){
		toggleTable(prefix+'_el_1',1);
		toggleTable(prefix+'_el_2',0);
		toggleTable(prefix+'_el_3',0);

		toggleTable(prefix+'_el_not_man',0);
		toggleTable(prefix+'_el_man',1);

		theform.elements[prefix+"_state_province"][0].selected = true;

	}else if(id == 124){
		toggleTable(prefix+'_el_1',0);
		toggleTable(prefix+'_el_2',1);
		toggleTable(prefix+'_el_3',0);

		toggleTable(prefix+'_el_not_man',0);
		toggleTable(prefix+'_el_man',1);

		theform.elements[prefix+"_canada_province"][0].selected = true;
	}else{
		toggleTable(prefix+'_el_1',0);
		toggleTable(prefix+'_el_2',0);
		toggleTable(prefix+'_el_3',1);

		toggleTable(prefix+'_el_not_man',1);
		toggleTable(prefix+'_el_man',0);

		if(clear)
		theform.elements[the_element].value = "";
	}
}

function populate(thisform){

	if(thisform.elements["asabove"].checked){

		thisform.elements["data[constituants][0][del_addr_01]"].value = thisform.elements["data[constituants][0][phy_addr_01]"].value;
		thisform.elements["data[constituants][0][del_addr_02]"].value = thisform.elements["data[constituants][0][phy_addr_02]"].value;
		thisform.elements["data[constituants][0][del_city]"].value = thisform.elements["data[constituants][0][phy_city]"].value;
		thisform.elements["data[constituants][0][del_state]"].value = thisform.elements["data[constituants][0][phy_state]"].value;
		thisform.elements["data[constituants][0][del_code]"].value = thisform.elements["data[constituants][0][phy_code]"].value;
		thisform.elements["data[constituants][0][del_country_id]"].value = thisform.elements["data[constituants][0][phy_country_id]"].value;

		id = thisform.elements["data[constituants][0][phy_country_id]"].value;
		country_states(id,thisform,'data[constituants][0][del_state]','del',0);


		if(id == 840 || id == 124){
	   		document.getElementById('del_zip').innerHTML = "<b class='mandatory'>*</b>";
		}else{
			document.getElementById('del_zip').innerHTML = "";
		}


		thisform.elements["del_state_province"].value = thisform.elements["data[constituants][0][phy_state]"].value;
		thisform.elements["del_canada_province"].value = thisform.elements["data[constituants][0][phy_state]"].value;

	}else{
		thisform.elements["data[constituants][0][del_addr_01]"].value = "";
		thisform.elements["data[constituants][0][del_addr_02]"].value = "";
		thisform.elements["data[constituants][0][del_city]"].value = "";
		thisform.elements["data[constituants][0][del_state]"].value = "";
		thisform.elements["data[constituants][0][del_code]"].value = "";
		thisform.elements["data[constituants][0][del_country_id]"].value = "-1";

		country_states(1,thisform,'data[constituants][0][del_state]','del',1);

		// hidden because warehouse needs this field to be required for all countries
		document.getElementById('del_zip').innerHTML = "";
	}
}

//shop
function empty_basket(type){

	if(type != 'wishlist'){
		type == 'cart';
	}

	if(confirm("Do you really want to empty your "+type+"?")){
		if(type == 'wishlist'){
			window.location = "/store/?action=wish_empty";
		}else{
			window.location = "/store/?action=empty";
		}
	}
}

function remove_from_basket(item,item_id,type){

	if(type != 'wishlist'){
		type == 'cart';
	}

	if(confirm("Do you really want to remove "+item+" from your "+type+"?")){

		if(type == 'wishlist'){
			window.location = "/store/?p="+item_id+"&action=wish_remove";
		}else{
			window.location = "/store/?b="+item_id+"&action=remove";
		}
	}
}

function delete_basket_Form(basketform, theaction){
	if(confirm("Do you really want to remove selected items?")){
		basketform.action = theaction;
		basketform.submit();
	}
}


//porfolios
function editFormEntry(theform, theaction, allShow, actType){
	edit_count = 0;
//	theform = eval('document.members');

	if(theform.elements[allShow+"_id[]"].checked == true){
		entry_id = theform.elements[allShow+"_id[]"].value;
		edit_count = 1;
	}

	for(x = 0;x < theform.elements[allShow+"_id[]"].length; x++){
		if(theform.elements[allShow+"_id[]"][x].checked == true){
			entry_id = theform.elements[allShow+"_id[]"][x].value;
			edit_count ++;
			if(edit_count > 1){
				break;
			}
		};
	}

	if(edit_count == 0){
		alert("Please select an entry you want to "+actType+".");
	}else if(edit_count > 1){
		alert("Please only select a single entry you want to "+actType+".");
	}else{
		if(theaction.indexOf("?") != "-1"){
			window.location = theaction +"&id=" + entry_id;
		}else{
			window.location = theaction +"?id=" + entry_id;
		}
	}
}


//misc
function disable_button(id){
	document.getElementById(id).disabled = true;
}

function checkGeneric(allItem, entry_form){
	allItem = entry_form.elements[allItem];

	if(allItem.checked == false){
		setFlag = false;
	}else{
		setFlag = true;
	}

	entry_form.elements[allItem.name + "_id[]"].checked = setFlag;

	for(x = 0;x < entry_form.elements[allItem.name + "_id[]"].length; x++){
		entry_form.elements[allItem.name + "_id[]"][x].checked = setFlag;
	}

}

function checkSetGeneric(allItem, entry_form){

	if(entry_form.elements[allItem].checked == false){
		entry_form.elements[allItem].checked = true;
	}else{
		entry_form.elements[allItem].checked = false;
	}

	checkGeneric(allItem, entry_form);
}

function checkSearchAll(allItem, theForm, seriesName){

	entry_form = eval("document." + theForm);

	allItem = entry_form.elements[allItem];

	if(allItem.checked == false){
		setFlag = false;
	}else{
		setFlag = true;
	}

	entry_form.elements[seriesName + "[]"].checked = setFlag;

	for(x = 0;x < entry_form.elements[seriesName + "[]"].length; x++){
		entry_form.elements[seriesName + "[]"][x].checked = setFlag;
	}
}

function statusSetter(str) {
   window.defaultStatus = str;
   window.status = str;
}

function pop(url, name, w, h, rs, sb, mn, st, oth) {
var resize = ((rs) ? "resizable="+rs+"," : "");
var scroll = ((sb) ? "scrollbars="+sb+"," : "");
var menu = ((mn) ? "toolbar="+mn+",location="+mn+",menubar="+mn+"," : "");
var sts = ((st) ? "status="+st+"," : "");

     var popupWin = window.open(url, name, resize + scroll + menu + sts + "width=" + w + ",height=" + h + " " + oth);
     if (document.layers) {
          popupWin.focus();
     }
}

function submitEnter(myfield,e){
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;

	if (keycode == 13)
	   {
	   myfield.form.submit();
	   return false;
	   }
	else
	   return true;
}

function submitForm(theform, theaction){

	theform.action = theaction;
	theform.submit();
}

function deleteForm(theform, theaction, allShow){
	var item_selected = 0;

	if(theform.elements[allShow + "_id[]"].checked == true){
		item_selected = 1;
	}

	for(x = 0;x < theform.elements[allShow + "_id[]"].length; x++){
		if(theform.elements[allShow + "_id[]"][x].checked == true){
			item_selected = 1;
			break;
		};
	}

	if(item_selected == 1){
		if(confirm("Do you really want to delete selected entries?")){
			theform.action = theaction;
			theform.submit();
		}
	}else{
		alert("Please select entries you want to delete.");
	}
}

function formatCurrency(num) {
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
		num = "0";

	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();

	if(cents<10)
		cents = "0" + cents;

	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
		num = num.substring(0,num.length-(4*i+3))+','+num.substring(num.length-(4*i+3));

	return (((sign)?'':'-') + '$' + num + '.' + cents);
}



/*entry system*/
function statusSetter(str) {
   window.defaultStatus = str;
   window.status = str;
}

function submitForm(theform, theaction){
	theform.action = theaction;
	theform.submit();
}

function submitFinal(theform){
	confirm_final = theform.elements["data[entry_applications][0][update_locked]"][0].checked;

	if(confirm_final == true){
		if(confirm("Are you sure you'd like to proceed? By selecting 'YES' you understand that the system will not allow you to change your credits under any circumstances. Only proceed if your credits have been approved and are confirmed for publication.")){
			theform.submit();
		}
	}else{
		theform.submit();
	}
}

function submitUpload(theform){
	confirm_final = theform.elements["upload_locked"][0].checked;

	if(confirm_final == true){
		if(confirm("Are you sure you'd like to proceed? By selecting 'YES' you understand that the system will not allow you to upload or replace additional files under any circumstances. Only proceed if your files have been confirmed and meet the publication standards outlined in the Preparation section.")){
			theform.submit();
		}
	}else{
		theform.submit();
	}
}

function submitOffline(theform, theaction){
	if(confirm("PLEASE NOTE:\nYou will NOT be able to add/delete entries to this entry group.\nYou will be able change credit information in the Entry history under My Account.")){
		theform.action = theaction;
		theform.submit();
	}
}

function deleteForm(theform, theaction, allShow){
	var item_selected = 0;

	if(theform.elements[allShow + "_id[]"].checked == true){
		item_selected = 1;
	}

	for(x = 0;x < theform.elements[allShow + "_id[]"].length; x++){
		if(theform.elements[allShow + "_id[]"][x].checked == true){
			item_selected = 1;
			break;
		};
	}

	if(item_selected == 1){
		if(confirm("Do you really want to delete selected entries?")){
			theform.action = theaction;
			theform.submit();
		}
	}else{
		alert("Please select entries you want to delete.");
	}
}

function printLabels(theform, theaction, allShow){
	var print_selected = 0;
	var qry = "";

	if(theform.elements[allShow + "_id[]"].checked == true){
		if(theform.elements[allShow + "_id[]"].value != undefined){
			qry = theform.elements[allShow + "_id[]"].value
			print_selected = 1;
		}
	}


	for(x = 0;x < theform.elements[allShow + "_id[]"].length; x++){
		if(theform.elements[allShow + "_id[]"][x].checked == true){
			if(print_selected == 0){
				qry = theform.elements[allShow + "_id[]"][x].value
			}else{
				qry += "," + theform.elements[allShow + "_id[]"][x].value
			}
			print_selected = 1;

		};
	}


	if(print_selected == 1){
		window.open(theaction + qry);
	}else{
		alert("Please select entries you want to print.");
	}



}


function editEntry(allShow, fType){
	edit_count = 0;
	theform = eval('document.entries_' + allShow);

	if(theform.elements[allShow + "_id[]"].checked == true){
		entry_id = theform.elements[allShow + "_id[]"].value;
		edit_count = 1;
	}

	for(x = 0;x < theform.elements[allShow + "_id[]"].length; x++){
		if(theform.elements[allShow + "_id[]"][x].checked == true){
			entry_id = theform.elements[allShow + "_id[]"][x].value;
			edit_count ++;
			if(edit_count > 1){
				break;
			}
		};
	}

	if(edit_count == 0){
		alert("Please select an entry you want to "+fType+".");
	}else if(edit_count > 1){
		alert("Please only select a single entry you want to "+fType+".");
	}else{
		if(fType == "edit"){
			window.location = "/cfe/enter/edit/?id=" + entry_id;
		}else if(fType == "duplicate"){
			window.location = "/cfe/enter/clone/?id=" + entry_id;
		}else if(fType == "edit_credits"){
			window.location = "/cfe/history/edit/?id=" + entry_id;
		}else if(fType == "upload_files"){
			//window.location = "/finalists/upload/?id=" + entry_id;
		}else if(fType == "upload_artwork"){
			window.location = "/cfe/enter/upload/?id=" + entry_id;
		}else if(fType == "update"){
			//window.location = "/finalists/edit/?id=" + entry_id;
		}

	}


}


function prefill_entry(show_name, show_id, category_name, category_id, group_id){
	fillCategoryDropDown(show_name, category_name);
	fillSubCategoryDropDown(category_id, group_id);
}



function fillCategoryDropDown(val, select){
	show_name = val;

	document.entries.CategoryType.focus();

	document.entries.CategoryType.length = 1;
	document.entries.CategoryType.options[0] = new Option("-- Choose Category --");
   	document.entries.CategoryType.options[0].value = '0';
	document.entries.CategoryType.options[0].selected = true;

	document.entries.SubCategoryType.length = 1;
	document.entries.SubCategoryType.options[0].selected = true;

	newOptions = eval(val+'Category');

	for(var i= 0; i < newOptions.length; i++) {
		document.entries.CategoryType.length=i+1;
		thisEntry = newOptions[i][1];
		newOption = new Option( thisEntry );
		newOption.value = newOptions[i][0];
		document.entries.CategoryType.options[i+1] = newOption;

		if (thisEntry == select && select != '' ){
			document.entries.CategoryType.options[i+1].selected = true;
		}
	}
}


function fillSubCategoryDropDown(val, select){

	document.entries.SubCategoryType.focus();

	document.entries.SubCategoryType.length = 1;
	document.entries.SubCategoryType.options[0] = new Option("-- Choose Sub-Category --");
   	document.entries.SubCategoryType.options[0].value = '0';
	document.entries.SubCategoryType.options[0].selected = true;


	OptionShow = eval(show_name+'Category');
	for(var i= 0; i < OptionShow.length; i++) {
		if(OptionShow[i][0] == val){
			category = i;
			break;
		}
	}

	newOptions = eval(show_name+'Category[' + category + '][2]');

	for(var i= 0; i < newOptions.length; i++) {
		document.entries.SubCategoryType.length=i+1;
		thisEntry = newOptions[i][1];
		newOption = new Option( thisEntry );
		newOption.value = newOptions[i][0];
		document.entries.SubCategoryType.options[i+1] = newOption;

		if (newOptions[i][0] == select && select != '' ){
			document.entries.SubCategoryType.options[i+1].selected = true;
		}

	}
}

function reset_contacts(){
	document.entries.elements["data[entry_applications][0][adhoc_name]"].disabled = false;
	document.entries.elements["data[entry_applications][0][adhoc_lastname]"].disabled = false;
	document.entries.elements["data[entry_applications][0][adhoc_phone]"].disabled = false;
	document.entries.elements["data[entry_applications][0][adhoc_email]"].disabled = false;
}


function populate_contacts(selectItem){
	if(selectItem != 0){
		id = Contacts[selectItem][0];
		firstname = Contacts[selectItem][1];
		lastname = Contacts[selectItem][2];
		phone = Contacts[selectItem][3];
		email = Contacts[selectItem][4];

		dis = true;
	}else{
		id = "";
		firstname = "";
		lastname = "";
		phone = "";
		email = "";

		dis = false;
	}

	document.entries.elements["data[entry_applications][0][constituant_contact_id]"].value = id;
	document.entries.elements["data[entry_applications][0][adhoc_name]"].value = firstname;
	document.entries.elements["data[entry_applications][0][adhoc_lastname]"].value = lastname;
	document.entries.elements["data[entry_applications][0][adhoc_phone]"].value = phone;
	document.entries.elements["data[entry_applications][0][adhoc_email]"].value = email;

	document.entries.elements["data[entry_applications][0][adhoc_name]"].disabled = dis;
	document.entries.elements["data[entry_applications][0][adhoc_lastname]"].disabled = dis;
	document.entries.elements["data[entry_applications][0][adhoc_phone]"].disabled = dis;
	document.entries.elements["data[entry_applications][0][adhoc_email]"].disabled = dis;
}

function setAllRow(theRow){
	if (navigator.appName.indexOf('Netscape') != -1){
		tableMain = theRow.parentNode; //mozilla
	}else{
		tableMain = theRow.parentElement; //ie & safari
	}

	theRows = tableMain.getElementsByTagName('tr');

	//alert(navigator.appName)
	///alert(theRows[4].getAttribute('bgcolor'))
}

function checkAllSet(allItem, allShow){
	entry_form = eval("document.entries_" + allShow);


	if(entry_form.elements[allItem].checked == false){
		entry_form.elements[allItem].checked = true;
	}else{
		entry_form.elements[allItem].checked = false;
	}

	checkAll(allItem, allShow);
}

function checkAll(allItem, allShow){
	entry_form = eval("document.entries_" + allShow);

	allItem = entry_form.elements[allItem];

	if(allItem.checked == false){
		setFlag = false;
		setOver = "out";
	}else{
		setFlag = true;
		setOver = "over";
	}



	entry_form.elements[allShow + "_id[]"].checked = setFlag;

	for(x = 0;x < entry_form.elements[allShow + "_id[]"].length; x++){
		entry_form.elements[allShow + "_id[]"][x].checked = setFlag;
	}

	for(x = 0;x < theRows.length; x++){
		setPointer(theRows[x], 0, setOver, '#999999', '#CCCCCC', '#C9E2FF');
	}

}

function setRow(theRow){
	theRowOver = theRow;
}

function CH(checkItem){
	if(checkItem.checked == true){
//		setPointer(theRowOver, 0, 'over', '#999999', '#CCCCCC', '#C9E2FF');
		setPointer(theRowOver, 0, 'over', '#ffffff', '#CCCCCC', '#C9E2FF');
	}else{
//		setPointer(theRowOver, 0, 'out', '#999999', '#CCCCCC', '#C9E2FF');
		setPointer(theRowOver, 0, 'out', '#ffffff', '#CCCCCC', '#C9E2FF');
	}
}

function setPointer(theRow, theRowNum, theAction, theDefaultColor, thePointerColor, theMarkColor)
{

    var theCells = null;
	var marked_row = "";
    // 1. Pointer and mark feature are disabled or the browser can't get the
    //    row -> exits
    if ((thePointerColor == '' && theMarkColor == '')
        || typeof(theRow.style) == 'undefined') {
        return false;
    }

    // 2. Gets the current row and exits if the browser can't get it
    if (typeof(document.getElementsByTagName) != 'undefined') {
        theCells = theRow.getElementsByTagName('td');
    }
    else if (typeof(theRow.cells) != 'undefined') {
        theCells = theRow.cells;
    }
    else {
        return false;
    }

    // 3. Gets the current color...
    var rowCellsCnt  = theCells.length;
    var domDetect    = null;
    var currentColor = null;
    var newColor     = null;
    // 3.1 ... with DOM compatible browsers except Opera that does not return
    //         valid values with "getAttribute"
    if (typeof(window.opera) == 'undefined'
        && typeof(theCells[0].getAttribute) != 'undefined') {
        currentColor = theCells[0].getAttribute('bgcolor');
        domDetect    = true;
    }
    // 3.2 ... with other browsers
    else {
        currentColor = theCells[0].style.backgroundColor;
        domDetect    = false;
    } // end 3

    // 4. Defines the new color
    // 4.1 Current color is the default one
    if (currentColor == '' || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
        if (theAction == 'over' && thePointerColor != '') {
            newColor              = thePointerColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
        }
    }
    // 4.1.2 Current color is the pointer one
    else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()
             && (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) {
        if (theAction == 'out') {
            newColor              = theDefaultColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
        }
    }
    // 4.1.3 Current color is the marker one
    else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
        if (theAction == 'click') {
            newColor              = (thePointerColor != '')
                                  ? thePointerColor
                                  : theDefaultColor;
            marked_row[theRowNum] = (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])
                                  ? true
                                  : null;
        }
    } // end 4

    // 5. Sets the new color...
    if (newColor) {
        var c = null;
        // 5.1 ... with DOM compatible browsers except Opera
        if (domDetect) {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].setAttribute('bgcolor', newColor, 0);
            } // end for
        }
        // 5.2 ... with other browsers
        else {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].style.backgroundColor = newColor;
            }
        }
    } // end 5

    return true;
} // end of the 'setPointer()' function