
 // AUTOSIZING TEXT AREAS

function checkRows(textArea){
if (navigator.appName.indexOf("Microsoft Internet Explorer") == 0)
{
textArea.style.overflow = 'visible';
return;
}

while (
textArea.rows > 1 &&
textArea.scrollHeight < textArea.offsetHeight
){
textArea.rows--;
}

while (textArea.scrollHeight > textArea.offsetHeight)
{
textArea.rows++;
}



return;
}

jQuery(document).ready(function(){


jQuery("textarea.edit").each(function(){
	checkRows(this);
});//ensures textareas are the right height on page load

jQuery("textarea.edit").live("keyup", function(){
	checkRows(this);
});


});

// 'OTHER' SHOW INPUT FOR DROPDOWN MENUS

function otherInput(select){
	if(jQuery(select).val() == 'other'){
		jQuery("#other_input").fadeIn();
	}
}

// CHANGE STYLE CLASS ON STOCK AVAILABLE FIELD BASED ON CONTENT
function checkNumber(fld) {
	if (fld.value=="0") {
		fld.className="stock_unavailable";  
		f(fld);
	} else {
		fld.className = "stock_available";
		f(fld);
	}
}

// RESTRICT INPUT TO NUMERIC CHARACTERS
function f(o){
  o.value=o.value.toUpperCase().replace(/([^0-9])/g,"");
}

function g(o){
  if(/[^0-9]/.test(o.value)){
    o.value=o.value.toUpperCase().replace(/([^0-9])/g,"");
  }
}

// SHOW/HIDE CONSIGNED OUT FORM INPUTS

function toggleConsignedForm(){
	if(document.getElementById("consignment_details").style.display != 'none'){
		document.getElementById("consignment_details").style.display = 'none';
	}
	else{
		document.getElementById("consignment_details").style.display = '';
	}
}

// SHOW/HIDE CONSIGNED OUT FORM INPUTS

function toggleRecommended(){
	if(document.getElementById("recommended_text").style.display != 'none'){
		document.getElementById("recommended_text").style.display = 'none';
	}
	else{
		document.getElementById("recommended_text").style.display = '';
	}
}

//UPDATE FIELDS

function updateText(id, field) {
	var text = document.getElementById(id);
	text.innerHTML = field.value; 
}

//UPDATE FIELDS 2

function updateField(id, field) {
	var text = document.getElementById(id);
	text.value = field.value; 
}


//SELECT ALL CHECKBOXES

function selectall(clicked, theclass){
	var allcheckboxes = new Array();
	
	var allcheckboxes = document.getElementsByTagName("input");
	if(clicked.checked == true){
		for (i=0; i<allcheckboxes.length; i++) {
			if (allcheckboxes[i].type == 'checkbox' && allcheckboxes[i].className == theclass){
				allcheckboxes[i].checked = true;
			}
		}
	}
	else{
		for (i=0; i<allcheckboxes.length; i++) {
			if (allcheckboxes[i].type == 'checkbox' && allcheckboxes[i].className == theclass){
				allcheckboxes[i].checked = false;
			}
		}
	}
}

//JUMP TO URL ON SELECT CHANGE

function MM_jumpMenu(targ,selObj,restore){ //v3.0
eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
if (restore) selObj.selectedIndex=0;
}



//SELECT LIST POPULATION FUNCTION


function changeListType(){
	if(jQuery("#type").val() == "list"){
		jQuery("select#tag_lists").html(list_options);
	}
	else{
		jQuery("select#tag_lists").html(project_options);
	}
}
	
	
//DELETE LIST

function removeList(list_id,type){
	jQuery.get("../delete_list.php", {list_id: list_id, type: type}, function(){
		window.location	= "browseuserlists.php?type="+type;
	});
}



//TOGGLE VISIBILITY BASED ON WORK_STATUS

jQuery("input.status_checkbox").live("change", function(){
	jQuery("form#status_form").submit();
});


//SHOW ALL ARTIST/CATEGORY ITEMS IN LIST

function showAllCatPrefs(link){
	jQuery(".cat_pref").show();
	jQuery("#showallcats").hide();
}

function showAllArtistPrefs(){
	jQuery(".artist_pref").show();
	jQuery("#showallartists").hide();
}

function showAllDefinitions(link){
	jQuery(".definition").show();
	jQuery("#showalldefs").hide();
}

//DELETE COMMENT

function deleteComment(id, type){
	jQuery.post("deleteComment.php", {id: id, type: type}, function(){
		jQuery("#comment_" + id).remove();
	});
	
}

jQuery(".deleteinvcomment").live("click", function(){deleteComment(jQuery(this).attr("id"), "inventory_comments")});

jQuery(".deletemlcomment").live("click", function(){deleteComment(jQuery(this).attr("id"), "ml_comments")});

jQuery(".deletepubcomment").live("click", function(){deleteComment(jQuery(this).attr("id"), "publication_comments")});

jQuery(".deleterolcomment").live("click", function(){deleteComment(jQuery(this).attr("id"), "rolodex_comments")});


//CHECK ML EMAIL ADDRESS

jQuery("#newemail").blur(function(){
	var email = jQuery(this).val();
	checkMlEmail(email);
});



function checkMlEmail(email){
	//load some vars into the hizzay
	var loading = "<img src=\"img/ajax-loader-grey.gif\" alt=\"loading\" />";
	var valid = "<img src=\"img/tick.png\" alt=\"valid\" />";
	var invalid = "<img src=\"img/invalid.png\" alt=\"invalid\" />";
	
	jQuery("#newmlemail_feedback").html(loading);//loading gif
	
	var emailRegEx = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;
	
	if(email.search(emailRegEx) != -1){//regex check
		
		jQuery.post("checkMlEmail.php", {email:email}, function(d){//ajax to check if email is taken
			if(d > 0){
				jQuery("#newmlemail_feedback").html(invalid);
			}
			else{
				jQuery("#newmlemail_feedback").html(valid);
			}
		});
	}
	else{
		jQuery("#newmlemail_feedback").html(invalid);
	}
}

function validateSearch(){
	if(jQuery("#keyword_search").val() == ""){
		jQuery("#keyword_search_submit").attr("disabled", true);
	}
	else{
		jQuery("#keyword_search_submit").removeAttr("disabled");		
	}
}


//DELETE CARD


function deleteCard(id, type, nexturl){
	var dialog = "<p id=\"deleteconfirm\">Are you sure you wish to delete this record?</p>";//message to display
    jQuery(dialog).dialog({buttons: { "Yes": function(){ jQuery.post("deleteCard.php", {id: id, type: type}, function(){ window.location.replace(nexturl);}); }, "No": function() { jQuery(this).dialog("close"); } },  title: 'Confirm deletion' });    
}



