/**
 *   set focus on selected form element
 */

function appSetFocus(el_id){
    if(document.getElementById(el_id)){
        document.getElementById(el_id).focus();
    }    
}

/**
 *   Change location (go to another page)
 */
function appGoTo(page, params){
	params = (params != null) ? params : "";
    document.location.href = 'index.php?'+page + params;
}

/**
 *   Open popup window
 */
function appOpenPopup(page){
	new_window = window.open(page,  "", "location=1,status=1,scrollbars=1,width=400,height=300");
    new_window.moveTo(100,100);
}

/**
 *   set cookie
 */
function appSetCookie(name, value, days) {
    if (days){
        var date = new Date();
        date.setTime(date.getTime()+(days*24*60*60*1000));
        var expires = '; expires='+date.toGMTString();
    }
    else var expires = '';
    document.cookie = name+'='+value+expires+'; path=/';
}

/**
 *   get cookie
 */
function appGetCookie(name) {
	if (document.cookie.length > 0){
		start_c = document.cookie.indexOf(name + "=");
		if(start_c != -1){
			start_c += (name.length + 1);
			end_c = document.cookie.indexOf(";", start_c);
			if(end_c == -1) end_c = document.cookie.length;
			return unescape(document.cookie.substring(start_c,end_c));
		}
	}	
	return "";
}

/**
 *   get menu status
 */
function appGetMenuStatus(ind){
	var status = document.getElementById("side_box_content_"+ind).style.display;
	if(status == "none"){			
		return "none";
	}else{
		return "";
	}
}

/**
 *   toggle rss
 */
function appToggleRss(val){
	if(val == 1){
		if(document.getElementById("rss_feed_type")){
			document.getElementById("rss_feed_type").disabled = false;
		}
	}else{
		if(document.getElementById("rss_feed_type")){
			document.getElementById("rss_feed_type").disabled = true;
		}
	}
}

/**
 *   email validation
 */
function appIsEmail(str){
	var at="@";
	var dot=".";
	var lat=str.indexOf(at);
	var lstr=str.length;
	var ldot=str.indexOf(dot);
	if (str.indexOf(at)==-1) return false; 

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr) return false;
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr) return false;
	if (str.indexOf(at,(lat+1))!=-1) return false;
	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot) return false;
	if (str.indexOf(dot,(lat+2))==-1) return false;
	if (str.indexOf(" ")!=-1) return false;

 	return true;
}

/**
 *  submit logout 
 */
function frmLogout_Submit(){
	if(document.getElementById('frmLogout')){
		document.getElementById('frmLogout').submit();					
	}									
}								


/**
 *  submit site search
 */
function appPerformSearch(page){
	document.forms['frmQuickSearch'].p.value = page;
	document.forms['frmQuickSearch'].submit();
}



