/*js For Getting round */
function roundNumber(num, dec) {
	if (isNaN(num)) {
		return 0;
	}
	var result = Math.round(num * Math.pow(10, dec)) / Math.pow(10, dec);
	return result;
}

/* Function for BookMarking */
function addBookmark() {
	if (window.sidebar) { // Mozilla Firefox Bookmark
		window.sidebar.addPanel(document.title,window.location ,"");
	} else if( window.external ) { // IE Favorite
		try {
			window.external.AddFavorite(document.title,window.location); 
		} catch(e) {
			alert('Error trying to bookmark. Please check your security settings.');
		}
	} else if(window.opera && window.print) { // Opera Hotlist
		return true; 
	}
}

/* Function for Printing */
function showPrint() {
	if (navigator.appName == 'Netscape') {
		alert('Browser is not IE. Flash print not available. Show help page.');
		return;
	}
	window.print();
}
function showTime() {

	var d = new Date();
	var t_hour = d.getHours();
	if(4<=t_hour&&t_hour<12){
	return ("おはようございます");
	}
	else if(12<=t_hour&&t_hour<18){
	return ("こんにちは");
	}
	else
	return ("こんばんは");
}

function SaveSearchList(){
    /*if(validate(document.getElementById(activeFormId)))	{
    var value="searchConditionSave.do?method=inputNameSave&TB_iframe=true&height=520&width=680&modal=true";
    document.getElementById(activeFormId).action = value;
    document.getElementById(activeFormId).submit();
    }*/
}

function showElements() {
    for (i = 0; i < arguments.length; i++) {
        $('#' + arguments[i]).show(); 
    }
}

function hideElements() {
    for (i = 0; i < arguments.length; i++) {
        $('#' + arguments[i]).hide(); 
    }
}

function toggleShow() {
    for (i = 0; i < arguments.length; i++) {
	    $('#' + arguments[i]).toggle(); 
	}
}

function switchInputMode(mod) {
    if (mod == 2) {
    	hideElements('search_open');
    	showElements('search_close')
        $('.simple_mode').hide();;
        $('.full_mode').fadeIn('fast');
        
    } else {
       	hideElements('search_close');
	    showElements('search_open');
        $('.full_mode').hide();
        $('.simple_mode').fadeIn('fast');
    }
}


function countWords(txt) {
    var str  = $('#' + txt).val();
    var match = str.match(/([^　\s]+)/g);
    if (null == match) {
        return 0;
    }
    return match.length;
}

function exportExcel(page, searchKey) {
    var url = 'export/exportExcel.do?search_key=' + searchKey + '&page=' + page;
    parent.tb_remove();
    parent.location.href = url;
}

function exportPPT(page, searchKey) {
    var url = 'ajax/ajaxExportPPT.do?search_key=' + searchKey + '&page=' + page;
    jQuery.ajax({ url: url,
            success: function(msg) { 
                alert (msg == 'ok'? message.ppt_success: message.ppt_error);
                parent.tb_remove();
            }
       });
}
