﻿function __textBoxPostBack(e, id) { 
	var keynum; 
	if(window.event) { 
		keynum = e.keyCode; 
	} else if(e.which) { 
		keynum = e.which; 
	}
	if (keynum == 13) {
		__doPostBack(id, ''); 
		return false;
	} 
}
function __postBackOnEnter(o, e) {
	if(e.get_domEvent().keyCode == 13) {
		// document.forms[0].submit();
	}
}
function clientClick(e, id) {
    var keynum;
    if (window.event) {
        keynum = e.keyCode;
    } else if (e.which) {
        keynum = e.which;
    }
    if (keynum == 13) {
        document.getElementById(id).click();
    }
}
function GetRadWindow()
{
   var oWindow = null;
   if (window.radWindow) oWindow = window.radWindow; //Will work in Moz in all cases, including clasic dialog
   else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow;//IE (and Moz az well)
   return oWindow;
}
function resetRadWindow(){
//    var window = GetRadWindow();
//    window.reload();
//    document.location.reload()
}

var timeout;
function timed_show_options(clientId){
	document.getElementById(clientId).style.display = "block";
	timeout = setTimeout("display('" + clientId + "', false)",3000);
}
function show_options(clientId){
	document.getElementById(clientId).style.display = "block";
	clearTimeout(timeout);
}
function check_searchbar(searchbar, isFocused, searchWord){
	if(isFocused){
		if(	searchbar.value == searchWord){
			searchbar.value = ''; 
		}
	}else{
		if(	searchbar.value == ''){
			searchbar.value = searchWord; 
		}	
	}
}
function ajaxsearch(searchpanelId, searchvaluelength, btnId, display) {
    clearTimeout(timeout);
	if(display && (searchvaluelength > 1)){
	    document.getElementById(searchpanelId).style.display = "block";
	    timeout = setTimeout("ajaxsearchgo('" + btnId + "')", 80);
	}else{
    	document.getElementById(searchpanelId).style.display = "none";
	    clearTimeout(timeout);
    }    
}
function ajaxsearchgo(btnId) {
    document.getElementById(btnId).click();
}
function submit_add_item_search(e, text, searchBtnId) {
    clearTimeout(timeout);
    if(text.length > 0){
    	var keynum; 
    	if(window.event) { 
    		keynum = e.keyCode; 
    	} else if(e.which) { 
    		keynum = e.which; 
    	}
    	if (keynum == 13) {
    	    document.getElementById(searchBtnId).click();
    	} 
    }
}
function display(clientId, show){
    if(show){
        document.getElementById(clientId).style.display = "block";
    }else{
        document.getElementById(clientId).style.display = "none";
    }
}
function change_src(imgId, imgPath){
    document.getElementById(imgId).src = imgPath;
}
function pageScroll(pixels) {
    	window.scrollBy(0,pixels);
}

/**
 * JavaScript code to detect available availability of a 
 * particular font in a browser using JavaScript and CSS. 
 * 
 * Author : Lalit Patel
 * Website: http://www.lalit.org/lab/jsoncookies
 * License: Creative Commons Attribution-ShareAlike 2.5
 *          http://creativecommons.org/licenses/by-sa/2.5/
 * Version: 0.15 
 *          changed comparision font to serif from sans-serif, 
 *          as in FF3.0 font of child element didn't fallback 
 *          to parent element if the font is missing.
 * Updated: 09 July 2009 10:52pm
 * 
 */

/**
 * Actual function that does all the work. Returns an array with all the info.
 * This test will fail for the font set as the default serif font.
 * 
 * Usage: d = new Detector();
 *        d.test('font_name');
 */
var Detector = function(){
	var h = document.getElementsByTagName("BODY")[0];
	var d = document.createElement("DIV");
	var s = document.createElement("SPAN");
	d.appendChild(s);
	d.style.fontFamily = "sans";			//font for the parent element DIV.
	s.style.fontFamily = "sans";			//serif font used as a comparator.
	s.style.fontSize   = "72px";			//we test using 72px font size, we may use any size. I guess larger the better.
	s.innerHTML        = "mmmmmmmmmmlil";		//we use m or w because these two characters take up the maximum width. And we use a L so that the same matching fonts can get separated
	h.appendChild(d);
	var defaultWidth   = s.offsetWidth;		//now we have the defaultWidth
	var defaultHeight  = s.offsetHeight;	//and the defaultHeight, we compare other fonts with these.
	h.removeChild(d);
	/* test
	 * params:
	 * font - name of the font you wish to detect
	 * return: 
	 * f[0] - Input font name.
	 * f[1] - Computed width.
	 * f[2] - Computed height.
	 * f[3] - Detected? (true/false).
	 */
	function debug(font) {
		h.appendChild(d);
		var f = [];
		f[0] = s.style.fontFamily = font;	// Name of the font
		f[1] = s.offsetWidth;				// Width
		f[2] = s.offsetHeight;				// Height
		h.removeChild(d);
		font = font.toLowerCase();
		if (font == "serif") {
			f[3] = true;	// to set arial and sans-serif true
		} else {
			f[3] = (f[1] != defaultWidth || f[2] != defaultHeight);	// Detected?
		}
		return f;
	}
	function test(font){
		f = debug(font);
		return f[3];
	}
	this.detailedTest = debug;
	this.test = test;	
}
function check_corbel(linkId, altFontSizeLink){
    var detective = new Detector();
    if(!detective.test('corbel')){
        document.getElementById(linkId).src = altFontSizeLink;
    }
}
