
// Bookmark Us Link
function bookmark_us(url, title){
	try {
		if (window.sidebar) { // firefox 
			window.sidebar.addPanel(title, url, "");
		} else if (window.opera && window.print) { // opera
			alert('Press CTRL+T to bookmark this page.');
		} else if (document.all) { // ie
			window.external.AddFavorite(url, title);
		} else {
			alert('Press CTRL+D to bookmark this page.');
		}
	} catch(e) {}
		
}

// Email this page
function email_this_page(url, title) {
	try {
		
		e_url = escape(url);
		link = '/email.php?q=' + e_url;
		oEmail = window.open(link, '_blank', 
			'top=40,left=180,width=520,height=560,location=no,resizable=no,scrollbars=no,status=no,toolbar=no,menubar=no');
		oEmail.focus();
		
	} catch(e) {}
}

// Product Page: Select Color
function prod_pick_color( obj_link, id_radio, name_links ) {
	try {
		// Get radio object
		obj_radio = document.getElementById(id_radio);
		if (obj_radio != null) {
			// Select radio
			obj_radio.checked = true;
			if (obj_radio.checked) {
				// Clear other radio objects
				obj_links = document.getElementsByName(name_links);
				for (var i=0; i < obj_links.length; i++) {
					obj_links[i].className = "";
				}
				// select link
				obj_link.className = "selected";
			}
		}
	} catch(e) {}
}

// enforce numeric value for product quantity
// - obj_text: text input object
// - id_hidden: hidden field to support enforcing numeric value
// - id_min: hidden field containing the minimum allowed quantity
// - id_max: hidden field containing the maximum allowed quantity
// - chk_integer: true => check for integer, false => check for float
function valid_number( obj_text, id_hidden, id_min, id_max, chk_integer ) {
	try {
		obj_hidden = document.getElementById(id_hidden);
		obj_min = document.getElementById(id_min);
		obj_max = document.getElementById(id_max);
		value = obj_text.value;
		value = trim(value);
		
		if (!isNaN(value)) {
			//------------------
			// It is a number!
			//------------------
			// write to hidden field
			out_range = false;
			
			is_number = (value.length > 0) && is_numeric(value);
			
			// force it into integer if chk_integer is true
			if (is_number) {
				if (chk_integer == true) {
					value = parseInt(value);
				}
			}
			
			// See if value is within range if it is a number
			if (is_number) {
				n_value = parseInt(value);
				min = parseInt(obj_min.value);
				max = parseInt(obj_max.value);
				if ((n_value < min) || (n_value > max)) {
					out_range = true;
				}
			}
			// decide to write or not.
			if ((value.length <= 0) || (out_range == false)) {
				// if it is within range then write text
				obj_text.value = value;
				obj_hidden.value = value;
			} else {
				// if it fails, overwrite text from hidden field
				obj_text.value = obj_hidden.value;
			}
		}
		else {
			
			// overwrite text from hidden field
			obj_text.value = obj_hidden.value;
		}
	} catch(e) {}
}

function is_numeric(sText) {
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
}

// Clear search box on focus
function search_onfocus( obj_text ) {
	try {
		value = obj_text.value;
		if (value == 'Search') {
			// clear textbox
			obj_text.value = '';
		} 
	} catch (e) {}
}

// Add help text when search box is off focus
function search_onblur( obj_text ) {
	try {
		value = obj_text.value;
		if (trim(value) == '') {
			// clear textbox
			obj_text.value = 'Search';
		} 
	} catch (e) {}
}

// Submit quick search form
function quick_search_select( obj_sel ) {
	try {
		
		if ((obj_sel.value != '-1') && (obj_sel.value != '-2')) {
			// get form
			form = document.getElementById('form_quick_search');
			form.submit();
		} else {
			return false;
		}			
		
	} catch (e) {}	
}

function search_submit() {
	text = document.getElementById('txt_search');
	text_value = trim(text.value);
	if ((text_value != 'Search') && (text_value != '')) {
		form = document.getElementById('form_search');
		form.submit();
	}
}

// trim text
function trim(s)
{
    var l=0; var r=s.length -1;
    while(l < s.length && s[l] == ' ')
    {     l++; }
    while(r > l && s[r] == ' ')
    {     r-=1;     }
    return s.substring(l, r+1);
} 

// order contact form countries
function order_countries_change ( obj_countries, id_states ) {
	try {
		obj_states = document.getElementById(id_states);
		if (obj_countries.value == 'Canada') {
			obj_states.value = '-2';
		}
		else 
			if (obj_countries.value == 'United States') {
				obj_states.value = '-1';
			}
	} catch(e) {}
}

// order contact form states
function order_states_change ( obj_states, id_countries ) {
	try {
		obj_countries = document.getElementById(id_countries);
		state_value = obj_states.value;
		// change country ddl only if a state is selected
		if ((state_value != '-1') &&
			(state_value != '-2') &&
			(state_value != '-3')) {
			a_temp = state_value.split(':');
			state_type = a_temp[0];
			if (state_type == 'State') {
				obj_countries.value = 'United States';
			} else if (state_type == 'Province') {
				obj_countries.value = 'Canada';
			}
		}
	} catch(e) {}
}

