/*** 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'));
		opacity('msg-box', 0, 100, 700);
		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") {
				opacity('msg-box', 100, 0, 700);
				//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) {
		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 = 'title error-field';
				if(objEl.alt) { msg = objEl.alt; } else { msg = "Please enter some text here"; }
				display_message(msg, 'error');
				//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 = 'title error-field';
						if(objEl.alt) { msg = objEl.alt; } else { msg = "Please enter a valid email"; }
						display_message(msg, 'error');
//						get_id('status-message').innerHTML = msg;
//						show_element(display_where);
						objEl.focus();
						return false;
					} else {
						objEl.className = 'title';
						//get_id(display_where).className = 'hidden';
					}
				} else {
					objEl.className = 'title';
					//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 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 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 opacity(id, opacStart, opacEnd, millisec) {
		//speed for each frame
		var speed = Math.round(millisec / 100);
		var timer = 0;
		
		//determine the direction for the blending, if start and end are the same nothing happens
		if(opacStart > opacEnd) {
			for(i = opacStart; i >= opacEnd; i--) {
				setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
				timer++;
			}
		} else if(opacStart < opacEnd) {
			for(i = opacStart; i <= opacEnd; i++) {
				setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
				timer++;
			}
		}
	}
	
	//change the opacity for different browsers
	function changeOpac(opacity, id) {
		var object = document.getElementById(id).style;
		object.opacity = (opacity / 100);
		object.MozOpacity = (opacity / 100);
		object.KhtmlOpacity = (opacity / 100);
		object.filter = "alpha(opacity=" + opacity + ")";
	}
