// global functions

// opens the popupwindow for forgotten password
function openForgotPassword(){
	window.open(base_url+"auth/forgot_password/", "forgot_password", "width=425,height=325,location=0,status=0,menubar=0,scrollbars=0,resizable=1,toolbar=0");	
}

// use this as an onclick for <a> for search form
function submitSearch(){
	$("#search_form").submit();
}

// part detail page from unescaped string (from DB)
function gotoPart(partNumber){
	document.location = base_url+"parts/detail/"+makeFriendly(partNumber)+"/";
}

// closes all open calendars on the page
function closeCalendars(){
	jQuery(".calwrapper").hide();
}

// encode string for urls (modified)
function makeFriendly(str) {
	var spacer = "_";
    str = str.toLowerCase(); //change everything to lowercase
    str = str.replace(/^s+|s+$/g, ""); //trim leading and trailing spaces
    str = str.replace(/[s]+/g, spacer); //change all spaces and underscores to spacer
    str = str.replace(/[^a-z0-9_-]+/g, ""); //remove all non-alphanumeric characters except spacer
    str = str.replace(/[_]+/g, spacer); //replace multiple instances of the spacer with a single instance
    str = str.replace(/^_+|_+$/g, ""); //trim leading and trailing spacers
 
    return str;
}

// encode a string for url (exact)
function urlEncode(str){
	var encoded=escape(str);
	encoded=encoded.replace("+", "%2B");
	encoded=encoded.replace("/", "%2F");
	return encoded;
}


// open window to contact representative about a part
function openContact(partNumber){
	$("#contact_form #part_1").val(partNumber);
	$("#contact_form").submit();	
}
