﻿<!--

/** 
 * Shortcut for document.getElementById(element_id) 
 * @param string element_id 
 * @return mixed 
 */ 
/*$ = function(element_id) { 
    return document.getElementById(element_id) 
}*/
var runOnLoad = new Array();
function OnLoad() {
	var func;
	for (var i=0; i < runOnLoad.length; i++) {
		if( typeof runOnLoad[i] == 'function' ){
			func = runOnLoad[i];
			func();
		}
	}
	return true;
}
function OnSubmit() { // This function should be overrided if you want to use your own onsubmit functionality
	return true;
}
/* For forms with cancel button (to avoid unneccesary form submits) */
function OnCancel(gotoURL) {
	window.location = gotoURL;
	return false;
}

/*Returns operating system name*/
function checkOS() {
	if(navigator.userAgent.indexOf('IRIX') != -1)
	{ var OpSys = "Irix"; }
	else if((navigator.userAgent.indexOf('Win') != -1) && (navigator.userAgent.indexOf('95') != -1))
	{ var OpSys = "Windows95"; }
	else if(navigator.userAgent.indexOf('Win') != -1)
	{ var OpSys = "Windows3.1 or NT"; }
	else if(navigator.userAgent.indexOf('Mac') != -1)
	{ var OpSys = "Macintosh"; }
	else if(navigator.userAgent.indexOf('Linux') != -1)
	{ var OpSys = "Linux"; }
	else { var OpSys = "other"; }
	return OpSys;
}

/* Window opener */
function OpenWin(windowURL, windowWidth, windowHeight, windowName, windowFeatures, noPopup) {

	// Add popup flag to querystring
	if (typeof(noPopup) == "undefined") {
		if (windowURL.lastIndexOf("?") >= 0)
			windowURL = windowURL + "&popup=true";
		else if (windowURL.substr(windowURL.length-1, 1) != "/")
			windowURL = windowURL + "/?popup=true";
		else
			windowURL = windowURL + "?popup=true";
	}

	// Default window sizes
	if (typeof(windowWidth) == "undefined" || windowWidth == "default")
		windowWidth = "550";
	if (typeof(windowHeight) == "undefined" || windowHeight == "default")
		windowHeight = "400";

	// Default window name
	if (typeof(windowName) == "undefined" || windowName == "default")
		windowName = "popup";

	// Default window features
	if (typeof(windowFeatures) == "undefined" || windowFeatures == 'default')
		windowFeatures = "top=50,left=50,toolbar=no,location=no,menubar=no,scrollbars=yes,status=no,resizable=yes";

	// Open and focus
	popupWindow = window.open(windowURL, windowName, windowFeatures + ',width=' + windowWidth + ',height=' + windowHeight);
	popupWindow.focus();

	return false;
}

/**
* A bit better window opener.... from @url www.sinutaht.ee
* Opens window with URL, aligned as specified
* @param string url         Window URL
* @param string dims        Window dimensions as string: 'width*height', where width and height are numbers or 'max' (max possible).
*                           Width and height are always cut down to screen usable height and width (minus 20px from edges)
* @param string align       Alignment of window as string 'vertical horizontal'
*                           vertical = top|middle|bottom
*                           horizontal = left|center|right
*                           Defaults to 'middle center'
* @param string window_name Name of window to be opened, defaults to '_blank'
* @return object Opened window object
*/
function OpenWindow(url, dims, align, window_name, windowFeatures) { // {{{
    // constants (almost) {{{
    
    var margin = 20; // margin from all edges except bottom
    var margin_bottom = 50; // margin from bottom (taskbar)
    
    // }}}
    
    // parse and init parameters {{{
    
    // parse dimensions
    
    // regexp for parsing dimensions
    var re_dims = new RegExp('^([0-9]+|max)\\*([0-9]+|max)$');
    var tmp_dims = re_dims.exec(dims);
    if (!tmp_dims) {
        throw('OpenWindow: Invalid dimensions value: \''+dims+'\'');
        return undefined;
    }
    // windows specified width and height
    var width = tmp_dims[1];
    var height = tmp_dims[2];
    
    // parse alignment
    
    // if empty, make string
    if (!align) align = '';
    
    var re_align_x = new RegExp('^(left|center|right)$');
    var re_align_y = new RegExp('^(top|middle|bottom)$');
    
    // find word(s), separated by space
    var re_align = new RegExp('^([a-z]+)?(?:\\s+([a-z]+))?$');
    var tmp_align = re_align.exec(align);
    var align_x = 'center';
    var align_y = 'middle';
    
    if (re_align_x.exec(tmp_align[1])) { // if first word is align_x
        align_x = tmp_align[1];
    } else if (re_align_y.exec(tmp_align[1])) { // if align_y
        align_y = tmp_align[1];
    } else {
        throw('Invalid align value: \''+tmp_align[1]+'\'');
        return undefined;
    }
    
    if (re_align_x.exec(tmp_align[2])) { // if second word is align_x
        align_x = tmp_align[2];
    } else if (re_align_y.exec(tmp_align[2])) { // if align_y
        align_y = tmp_align[2];
    } else {
        throw('Invalid align value: \''+tmp_align[2]+'\'');
        return undefined;
    }
    
    if (!window_name) window_name = '_blank';
    
    // }}}
    
    // determine window dimensions and coordinates {{{
    
    // determine width and height
    
    var max_width = screen.availWidth - 2*margin;
    var max_height = screen.availHeight - (margin + margin_bottom);
    
    if (width == 'max') { // width is set to 'max'
        width = max_width;
    } else { // width is set numerically
        width = Math.min(width, max_width);
    }
    if (height == 'max') { // height is set to 'max'
        height = max_height;
    } else { // height is set numerically
        height = Math.min(height, max_height);
    }
    
    // determine x and y according alignment
    
    switch (align_x) {
        case 'left':
            var x = margin;
        break;
        case 'center':
            var x = Math.round((max_width - width)/2 + margin, 0);
        break;
        case 'right':
            var x = max_width - width + margin;
        break;
    }
    
    switch (align_y) {
        case 'top':
            var y = margin;
        break;
        case 'middle':
            var y = Math.round((max_height - height)/2 + margin, 0);
        break;
        case 'bottom':
            var y = max_height - height + margin;
        break;
    }
    
    // }}}
    
    
    // display window {{{
    
    // window properties
    var props = // main shit
        'width='+width
        +',outerWidth='+width
        +',height='+height
        +',outerHeight='+height
        +',top='+y
        +',screenY='+y
        +',left='+x
        +',screenX='+x; 
    var props2 = // other nÃ¤nn
    	'toolbar=no'
        +'directories=0'
        +',location=no'
        +',menubar=0'
        +',resizable=no'
        +',scrollbars=yes'
        +',status=no';
    var win = window.open(url, window_name, props + ',' + props2);
    
    win.focus();
    
    // }}}
    
    return win;
} // }}}

/* Help opener */
function OpenHelp(url) {
	if ((typeof(url) == "undefined" || url == null) && event.srcElement.href != null)
		url = event.srcElement.href;
	
	OpenWin(url, 540, 400, 'helpwin', 'top=50,left=50,toolbar=yes,location=no,menubar=yes,scrollbars=yes,status=yes,resizable=yes',true);
	return false;
}

function ShowHelp() {
	var srcID = event.srcElement.id;
	if (srcID == null)
		return true;
	var helpObj = document.getElementById('help-'+srcID);
	if (helpObj == null)
		return true;
	helpObj.style.backgroundColor = 'white';
	return true;
}
function HideHelp() {
	var srcID = event.srcElement.id;
	if (srcID == null)
		return true;
	var helpObj = document.getElementById('help-'+srcID);
	if (helpObj == null)
		return true;
	helpObj.style.backgroundColor = 'transparent';
	return true;
}
function MapHelpFunctions(oForm) {
	var aInputs = oForm.getElementsByTagName("INPUT");
	for (var i=0; i < aInputs.length; i++) {
		aInputs[i].onfocus = ShowHelp;
		aInputs[i].onblur = HideHelp;
	}
	var aSelects = oForm.getElementsByTagName("SELECT");
	for (var i=0; i < aSelects.length; i++) {
		aSelects[i].onfocus = ShowHelp;
		aSelects[i].onblur = HideHelp;
	}
	var aTextareas = oForm.getElementsByTagName("TEXTAREA");
	for (var i=0; i < aTextareas.length; i++) {
		aTextareas[i].onfocus = ShowHelp;
		aTextareas[i].onblur = HideHelp;
	}
	var aButtons = oForm.getElementsByTagName("BUTTON");
	for (var i=0; i < aButtons.length; i++) {
		aButtons[i].onfocus = ShowHelp;
		aButtons[i].onblur = HideHelp;
	}
	return true;
}
function MapHelpLinks(obj) {
	var aDivs = obj.getElementsByTagName("DIV");
	var aHelpLinks = null;
	var i = 0;
	var j = 0;
	for (i=0; i < aDivs.length; i++) {
		if (aDivs[i].className == "help") {
			aHelpLinks = aDivs[i].getElementsByTagName("A");
			for (j=0; j < aHelpLinks.length; j++) {
				aHelpLinks[j].href = "javascript:void(OpenHelp('"+aHelpLinks[j].href+"'))";
			}
		}
	}
	return true;
}

function ShowDefault(obj, def) {
	if (obj.value == '')
		obj.value = def;
	return true;
}
function HideDefault(obj, def) {
	if (obj.value == def)
		obj.value = '';
	return true;
}
function NotYet() {
	alert('Ei tööta veel!')
	return false;
}

function detectBrowser() {
    
    var OS,browser,version,total,thestring;

    if (checkIt('konqueror')){
        browser = "Konqueror";
        OS = "Linux";
    }
    else if (checkIt('safari')) browser = "Safari"
    else if (checkIt('omniweb')) browser = "OmniWeb"
    else if (checkIt('opera')) browser = "Opera"
    else if (checkIt('webtv')) browser = "WebTV";
    else if (checkIt('icab')) browser = "iCab"
    else if (checkIt('msie')) browser = "Internet Explorer"
    else if (checkIt('mozilla')) browser = "Mozilla"
    else if (!checkIt('compatible')){
        browser = "Netscape Navigator"
        version = detect.charAt(8);
    }
    else browser = "An unknown browser";
    return browser;
}

function checkIt(string){
    var detect = navigator.userAgent.toLowerCase();
    var place, thestring;
	place = detect.indexOf(string) + 1;
	thestring = string;
	return place;
}

function generatePassword() { // {{{

    if (parseInt(navigator.appVersion) <= 3) {
        alert("Sorry this only works in 4.0+ browsers");
        return true;
    }

    var length=8;
    var sPassword = "";
    var noPunction = true;
    


    for (i=0; i < length; i++) {

        numI = getRandomNum();
        if (noPunction) { while (checkPunc(numI)) { numI = getRandomNum(); } }

        sPassword = sPassword + String.fromCharCode(numI);
    }
    return sPassword;
    
} //}}}

function getRandomNum() { // {{{

    // between 0 - 1
    var rndNum = Math.random()

    // rndNum from 0 - 1000
    rndNum = parseInt(rndNum * 1000);

    // rndNum from 33 - 127
    rndNum = (rndNum % 94) + 33;

    return rndNum;
} // }}}

function checkPunc(num) { // {{{

    if ((num >=33) && (num <=47)) { return true; }
    if ((num >=58) && (num <=64)) { return true; }
    if ((num >=91) && (num <=96)) { return true; }
    if ((num >=123) && (num <=126)) { return true; }

    return false;
} // }}}

/**
*   Function to remove/add items from/to multiple selectboxes
*   @param string frmName - form name
*   @param string sourceSelectName - source selectbox name
*   @param string destSelectName - destination selectbox name
*/
function removeAddSelectedItems(frmName, sourceSelectName, destSelectName) { // {{{
    
    var sel = false;
    var k=0;
    var destSlct = document.forms[frmName].elements[destSelectName];
    var srcSlct = document.forms[frmName].elements[sourceSelectName];
    
    //check if anything is selected and count nr of selections for tmp_arr
    for(i=0; i<srcSlct.options.length; i++){
        if(srcSlct.options[i].selected){
            var sel = true;
            k++;
        }
    }
    //create tmp_arr
    tmp_arr = new Array(k);
    k=0;
    
    //copy option keys to tmp_arr
    for (i=0; i<srcSlct.options.length; i++){
        if(srcSlct.options[i].selected){
            tmp_arr[k] = i;
            k++;
        }
    }
    
    //error message if nothing is selected
    if (!sel){
        alert('Option not choosed!');
        return false;
    }
    
    //move selected items to destination selectbox
    for (i=0; i<tmp_arr.length; i++)
        destSlct.options[destSlct.options.length] = new Option(srcSlct.options[tmp_arr[i]].text, srcSlct.options[tmp_arr[i]].value);
    
    //remove selected items from source selectbox
    for (i=0; i<tmp_arr.length; i++)
            srcSlct.options[tmp_arr[i]-i] = null;

} // }}}

/**
*   Function to select all elements in multiple selectbox
*   @param string frmName - form name
*   @param string sourceSelectName - source selectbox name
*/
function allSelect(frmName, sourceSelectName){ // {{{
    
    var list = document.forms[frmName].elements[sourceSelectName];
    
    for (i=0;i<list.length;i++)
        list.options[i].selected = true;
    
} // }}}

/**
*   Function to show/hide one or another html element.
*   @param string element1 - id of first element
*   @param string element2 - id of second element
*   @return void
*/
function toggleBetween2( element1, element2 ){ //{{{
    if(typeof element1 == 'string') {
        element1 = document.getElementById(element1)
    }
    
    if(typeof element2 == 'string') {
        element2 = document.getElementById(element2)
    }
    
    if (null == element1 || null == element2) {
        return;
    }
    
    if(element1.style.display == 'none') {
        element1.style.display = ''
    }
    element2.style.display = 'none';
} //}}}

/**
*   Function to set css class to certan html element
*   @param string element - element ID
*   @param string class_name - css class name to be applied
*   @return void
*/
function setStyleClass( element, class_name){ //{{{
    if(typeof element == 'string') {
        element = document.getElementById(element)
    }
    if (null == element) {
        return;
    }
    
    element.setAttribute("class", class_name); //standard
    element.setAttribute("className", class_name); //IE compatible
} //}}}

/**
 * Adds event to window.onload event queu
 */
function addLoadEvent( func ){
    var oldonload = window.onload;
    if( typeof window.onload != 'function' ){
        window.onload = func;
    }else{
        window.onload = function( ){
            if( oldonload){
                oldonload( );
            }
            func();
        }
    }
}

/**
 * Function to rezise window. If params are set to 0 then 
 * window is streched to max size users screen allows
 * @param int width
 * @param int height
 */
function resizeWindow( width, height ){
	window.moveTo( 0, 0 );
	
	if( !width )	width 	= screen.availWidth; //maximize
	if( !height )	height 	= screen.availHeight
	
	if( document.all ){
		top.window.resizeTo( width, height );
	}else if( document.layers || document.getElementById ){
		top.window.outerHeight = height;
		top.window.outerWidth = width;
	}
}

/**
 * Function loops through all form elements
 * Checks if there is default value for element and in focusing removes def form field value
 * On blur default value is added back
 * If field name is specified as second param then only certan field def valu is switched
 */
function resetFormFields( whichform, whichfield ){
    if( !whichform )  return false;
    if( !whichfield ){
        for( var i=0; i<whichform.elements.length; i++ ){
            var element = whichform.elements[i];
            if( element.type == "submit" ) continue;
            if( !element.defaultValue ) continue;
                element.onfocus = function( ){
                if( this.value == this.defaultValue ){
                    this.value = "";
                }
            }
            element.onblur = function( ){
                if( this.value == "" ){
                    this.value = this.defaultValue;
                }
            }
        }
    }else{
        var element = whichform.elements[whichfield];
        if( element && element.defaultValue ){
                element.onfocus = function( ){
                if( this.value == this.defaultValue ){
                    this.value = "";
                }
            }
            element.onblur = function( ){
                if( this.value == "" ){
                    this.value = this.defaultValue;
                }
            }
        }
    }
}

/**
 * Function adds onclick event to login link
 * Used to display my info box on clicking to login link
 */
function showMyInfoBoxOnLoginClick( ){
    //if( !document.getElementById( 'login_link' ) )  return false;
    var login_link  = document.getElementById( 'login_link' );
    var uname       = document.getElementById( 'login_username' );
    login_link.onclick = function( ){
        var result = toggle( 'my_info_block' ); //toggle is defined in common_blog.js file
        if( result != 'none' ){ //to avoid link following in IE
            uname.focus( );
        }
        return false;
    }
}

/**
 * Function for quick search tab for displaying all obj nums
 */
function showQuickSearchAll( ){
    if( !document.getElementById )  return false;
    var all_link = document.getElementById( 'qs_all_link' );
    all_link.onclick = function(){
        var sell_container = document.getElementById( 'qs_sell' );
        var rent_container = document.getElementById( 'qs_rent' );
        var sell_container_last7 = document.getElementById( 'qs_sell_last7' );
        var rent_container_last7 = document.getElementById( 'qs_rent_last7' );
        var deal_type = document.getElementById( 'qs_deal_sell' );
        sell_container_last7.style.display = 'none';
        rent_container_last7.style.display = 'none';
        if( deal_type.checked ){ //sell is active
            sell_container.style.display = '';
            rent_container.style.display = 'none';
        }else{
            sell_container.style.display = 'none';
            rent_container.style.display = '';
        }
        setStyleClass( 'left_tab', 'active_tab' );
        setStyleClass( 'right_tab', 'passive_tab' );
        return false;
    }
}
/**
 * Function for quick search tab for displaying last week obj nums
 */
function showQuickSearchThisWeek( ){
    if( !document.getElementById )  return false;
    var this_week_link = document.getElementById( 'qs_this_week_link' );
    this_week_link.onclick = function(){
        var sell_container_last7 = document.getElementById( 'qs_sell_last7' );
        var rent_container_last7 = document.getElementById( 'qs_rent_last7' );
        var sell_container = document.getElementById( 'qs_sell' );
        var rent_container = document.getElementById( 'qs_rent' );
        var deal_type = document.getElementById( 'qs_deal_sell' );
        sell_container.style.display = 'none';
        rent_container.style.display = 'none';
        if( deal_type.checked ){ //sell is active
            sell_container_last7.style.display = '';
            rent_container_last7.style.display = 'none';
        }else{
            sell_container_last7.style.display = 'none';
            rent_container_last7.style.display = '';
        }
        setStyleClass( 'right_tab', 'active_tab' );
        setStyleClass( 'left_tab', 'passive_tab' );
        return false;
    }
}

/**
 * Switches deal type obj nums in quick search box
 */
function toggleQuickSearchDealType( ){
    if( !document.getElementById )  return false;
    var deal_sell = document.getElementById( 'qs_deal_sell' );
    var deal_rent = document.getElementById( 'qs_deal_rent' );
    
    var sell_container = document.getElementById( 'qs_sell' );
    var rent_container = document.getElementById( 'qs_rent' );
    var sell_container_last7 = document.getElementById( 'qs_sell_last7' );
    var rent_container_last7 = document.getElementById( 'qs_rent_last7' );
    
    var left_tab = document.getElementById( 'left_tab' );
    var right_tab = document.getElementById( 'right_tab' );
    deal_sell.onclick = deal_rent.onclick = function(){
        if( deal_sell.checked ){ //sell is active
            if( left_tab.className == 'active_tab' ){
                sell_container.style.display        = '';
                rent_container.style.display        = 'none';
                sell_container_last7.style.display  = 'none';
                rent_container_last7.style.display  = 'none';
            }else{
                sell_container.style.display        = 'none';
                rent_container.style.display        = 'none';
                sell_container_last7.style.display  = '';
                rent_container_last7.style.display  = 'none';
            }
        }else{
            if( left_tab.className == 'active_tab' ){
                sell_container_last7.style.display  = 'none';
                rent_container_last7.style.display  = 'none';
                sell_container.style.display        = 'none';
                rent_container.style.display        = '';
            }else{
                sell_container_last7.style.display  = 'none';
                rent_container_last7.style.display  = '';
                sell_container.style.display        = 'none';
                rent_container.style.display        = 'none';
            }
        }
    }
}
/**
 * Initial settings for QuickSearch box.
 */
function showQuickSearch( recent, deal_type ){
    if( !document.getElementById )  return false;
    
    var sell_container_last7 = document.getElementById( 'qs_sell_last7' );
    var rent_container_last7 = document.getElementById( 'qs_rent_last7' );
    var sell_container = document.getElementById( 'qs_sell' );
    var rent_container = document.getElementById( 'qs_rent' );
    var sell_radio = document.getElementById( 'qs_deal_sell' );
    var rent_radio = document.getElementById( 'qs_deal_rent' );
    
    
    if ( recent == 1 ){
        sell_container.style.display = 'none';
        rent_container.style.display = 'none';
        if( deal_type == 0 ){ //sell is active
            sell_container_last7.style.display = '';
            rent_container_last7.style.display = 'none';
        }else{
            sell_container_last7.style.display = 'none';
            rent_container_last7.style.display = '';
            rent_radio.checked = true;
        }
        setStyleClass( 'right_tab', 'active_tab' );
        setStyleClass( 'left_tab', 'passive_tab' );
    }else{
        sell_container_last7.style.display = 'none';
        rent_container_last7.style.display = 'none';
        if( deal_type == 0 ){ //sell is active
            sell_container.style.display = '';
            rent_container.style.display = 'none';
        }else{
            sell_container.style.display = 'none';
            rent_container.style.display = '';
            rent_radio.checked = true;
        }
        setStyleClass( 'right_tab', 'passive_tab' );
        setStyleClass( 'left_tab', 'active_tab' );
    }
    
    return false;
}
/**
 * Function sets banners container width according to screen width
 */
function correctBannersContainerMargin(){
    if( !document.getElementById )  return false;
    var container = document.getElementById( 'left_pane' );
    var banners_container = document.getElementById( 'banners_container' );;
    window.onresize = function(){
        var  container_resized = container.offsetWidth;
        if( container_resized < 740 ){
            banners_container.style.width = 604+'px';
            banners_container.style.margin = '0 auto';
        }else{
            banners_container.style.width = 755+'px';
        }
    }
    var container_width = container.offsetWidth;
    if( container_width < 740 ){
        banners_container.style.width = 604+'px';
        banners_container.style.margin = '0 auto';
    }
}

/**
 * Function to change css class with onmouseover and onmouseout events
 */
function changeContainerStyleOnMouseEvent( wrapper_id, res_wrapper_elements, onmouse_class, onmouseout_class ){
	if( !document.getElementById || !document.getElementById( wrapper_id ) ) return false;
	if( !document.getElementsByTagName ) return false
	var result_wrapper = document.getElementById( wrapper_id );
	divs = result_wrapper.getElementsByTagName( res_wrapper_elements );
	for( var i=0; i<divs.length; i++ ){
		if( divs[i].className == onmouseout_class ){
			divs[i].onmouseover = function( ){
				this.className = onmouse_class;
			}
			divs[i].onmouseout = function( ){
				this.className = onmouseout_class;
			}
		}
	}
}

/**
 * This function compares keyword value to elem value. If equal then deletes if from inputbox
 */
function chk_input_text( keyword, elem ) {
    var text = document.getElementById(elem);
    if(text.value == keyword){
        text.value = '';
    }
}

/**
 * This function deletes detail search data, if new search type is chosen
 */
function deleteParams( ) {

    //delete data from textfields
    var textfields = new Array(
                            'area-min'
                            ,'area-max'
                            ,'not-last'
                            ,'area-total'
                            ,'area-total-max'
                            ,'area-ground'
                            ,'area-ground-max');

    for(var i=0; i<textfields.length; i++){
        try {
            document.getElementById(textfields[i]).value = '';
        } catch (exception) {}
    }

    //deselect selectboxes
    var selectboxes = new Array(
                            'structure[]'
                            ,'c[]'
                            ,'purpose[]'
                            ,'sel_land_purpose'
                            ,'detail_plan'
                            ,'waterbody'
                            ,'surroundings'
                            ,'floors-min'
                            ,'floors-max'
                            ,'rooms-min'
                            ,'rooms-max'
                            ,'floor-min'
                            ,'floor-max'
                            ,'sel_building_type'
                            ,'sel_condition');
                            
    for(i=0; i<selectboxes.length; i++){
        try {
            DeselectAllList(document.getElementById(selectboxes[i]));
        } catch (exception) {}
    }

    //deselect checkboxes
    var checkboxes = new Array(
                            'not-last'
                            ,'change_interest');

    for(i=0; i<checkboxes.length; i++){
        try {
            document.getElementById(checkboxes[i]).checked=false;
        } catch (exception) {}
    }
}

/**
 * Function deselects all selectbox values
 */
function DeselectAllList(elem){
    for(var i = 0;i < elem.length;i++){
        elem.options[i].selected = false;
    }
}

function selectNode (node) {
    var selection, range, doc, win;
    if ((doc = node.ownerDocument) && (win = doc.defaultView) && typeof
    win.getSelection != 'undefined' && typeof doc.createRange != 'undefined'
    && (selection = window.getSelection()) && typeof
    selection.removeAllRanges != 'undefined') {
        range = doc.createRange();
        range.selectNode(node);
        selection.removeAllRanges();
        selection.addRange(range);
    } else if (document.body && typeof document.body.createTextRange !=
    'undefined' && (range = document.body.createTextRange())) {
        range.moveToElementText(node);
        range.select();
    }
}
function checkLink( a ) {
    var selIndex = a.selectedIndex;

    var link = a.options[selIndex].value;
    if(link.length > 10){
        window.location = link;
    }
}
//-->