/*** this file defines js functions the application
	 *** @modified: Friday, November 28th 2008
	 *** @author:   www.pixelsonpoint.com
	 --------------------------------------------------------------*/

	// shortcut for dom getelementbyid
	function get_id (str_el) { return document.getElementById(str_el); }
	
	// show element.. change display
	function show_element ( str_el ) {
		str_el	=	get_id(str_el);		
		if( str_el ) str_el.className = str_el.className.replace('hidden', '');;		
	}
	
	// hide element.. change display
	function hide_element ( str_el ) {
		str_el	=	get_id(str_el);
		str_el.className.replace('hidden', '');
		str_el.className = (str_el.className == '') ? 'hidden' : str_el.className+' hidden';		
	}
		// toggle between show n hide
	function show_hide_element(str_el) {
		strEl	=	get_id(str_el);
		if (strEl.className.indexOf('hidden') == -1 ) {
			hide_element(str_el);
		} else {
			show_element(str_el);
		}
	}
	function display_message ( str_msg, str_typ )	{
		msg_box	=	get_id('msg-box');
		msg_box.className = str_typ;
		msg_box.innerHTML = str_msg;
		show_element(get_id('msg-box'));
		clear_info_bar('');
	}
	
	// hide info bar if its being displayed
	function clear_info_bar(mode) {
		tmr_info = setTimeout("clear_info_bar('yes')", 5000)
		if (mode == 'yes') {
			if (get_id('msg-box').className != "hidden") {
				hide_element('msg-box');
				clearTimeout(tmr_info);
			}
		}
	}
	
	function confirm_action(msg, action) {
		if (confirm(msg)) {
			if (action != '') {
	  	location.href = action;
	  }else{
			return true;
		}
		} else {
			 return false;			
		}
	}
  
	function validate(str_els, display_where) {
		arr_els = str_els.split(",");
		for (i=0; i < arr_els.length; i++ ) {
			strEl = arr_els[i];
			objEl = get_id(strEl);
			if (objEl.value == '') {
				objEl.className = 'error-field';
				if(objEl.alt) { msg = objEl.alt; } else { msg = "Please enter some text here"; }
				get_id('status-message').innerHTML = msg;
				show_element(display_where);
				objEl.focus();
				return false;
			} else {
				if (objEl.value != '' && objEl.id.indexOf('email') != -1 ) {
					if (!check_email(strEl)) {
						objEl.className = 'error-field';
						if(objEl.alt) { msg = objEl.alt; } else { msg = "Please enter some text here"; }
						get_id('status-message').innerHTML = msg;
						show_element(display_where);
						objEl.focus();
						return false;
					} else {
						objEl.className = '';
						get_id(display_where).className = 'hidden';
					}
				} else {
					objEl.className = '';
					get_id(display_where).className = 'hidden';
				}
			}
		}
	}
	
    function do_toggling(el) {
        current = get_id('toggler');
        if (current.value != '') {
			el2 = current.value.replace("dv-","pdv-");
            hide_element(current.value);
			get_id(el2).className = get_id(el2).className.replace("minus","plus");
        }   show_element(el);
            current.value = el;
			el2 = el.replace("dv-","pdv-");
			get_id(el2).className = get_id(el2).className.replace("plus","minus");
    }
    
    function check_email(fld) {
        if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(get_id(fld).value)) {	return (true); }
		else { return (false); }
    }
	
	function MM_openBrWindow(theURL,winName,features) { //v2.0
	  window.open(theURL,winName,features);
	}
    
	function bookmarksite(title,url){
	    if (window.sidebar) // firefox
	        window.sidebar.addPanel(title, url, "");
	    else if(window.opera && window.print){ // opera
	        var elem = document.createElement('a');
	        elem.setAttribute('href',url);
	        elem.setAttribute('title',title);
	        elem.setAttribute('rel','sidebar');
	        elem.click();
	    } 
	    else if(document.all) { // ie
	        window.external.AddFavorite(url, title);
	    }
	}
	
	function set_active_tab(el) {
		tbl_tabs = document.getElementById('tabheaders');
		el2  = document.getElementById(el);
		el2c = document.getElementById(el+'-content');
		document.getElementById(seltab).className = "tab-inactive";
		document.getElementById(seltab_content).className = "hidden";
		el2.className = "tab-active";
		el2c.className = '';
		seltab = el; 
		seltab_content = el+"-content";
	}
	
	function validate_search() {
		error_fld = get_id('search-error');
		search_fld = get_id('search');
		search_val = search_fld.value;
		if (search_val == '') { error_fld.innerHTML = 'Please enter something to search for'; return false; }
		if ( search_val.length < 4) { error_fld.innerHTML = 'Oops! your keyword is a little too short'; return false; }
	}

	
	function SetAllCheckBoxes(FormName, FieldName, CheckValue)
{
	if(!document.forms[FormName])
		return;
	var objCheckBoxes = document.forms[FormName].elements[FieldName];
	if(!objCheckBoxes)
		return;
	var countCheckBoxes = objCheckBoxes.length;
	if(!countCheckBoxes)
		objCheckBoxes.checked = CheckValue;
	else
		// set the check value for all check boxes
		for(var i = 0; i < countCheckBoxes; i++)
			objCheckBoxes[i].checked = CheckValue;
}

function ajaxRequest()
		{
		try
		{
		var request = new XMLHttpRequest()
		}
		catch(e1)
		{
		try
		{
		request = new ActiveXObject("Msxml2.XMLHTTP")
		}
		catch(e2)
		{
		try
		{
		request = new ActiveXObject("Microsoft.XMLHTTP")
		}
		catch(e3)
		{
		request = false
		}
		}
		}
		return request
		}
