<!--
function noSpam(domain, user, extension){
	locationstring = "mailto:" + user + "@" + domain + "." +extension;
	window.location = locationstring;
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

/**
 * kun klikataan asetukset sivulla välilehteä ladataan sivu uudelleen
 * ja ladataan oikean välilehden tiedot
 *
 * @param params, String, jossa välitetään halutut parametrit...
 */
function loadTab(params){
	//window.location = targ+'?page=6&lang=1&A=tab_'+tabID;
	window.location = '/index.jsp?'+params;
}

/* functio, joka kopioi valitun tekstin leikepöydälle */
function copyText(field){
	field.select();
	window.clipboardData.setData("Text", field.value);
	alert('Koodi on kopioitu leikepöydällesi, \nvoit liittää sen sieltä sivuillesi painamalla [ctrl]+[v] näppäinyhdistelmää.');
}

function validateOrderForm(theForm) { //v4.0

	// Etunimi
  	if(theForm.form_userFirstname.value == ""){
  		alert("Etunimi on pakollinen kenttä!");
  		return false;
  	}
  	// Sukunimi
  	if(theForm.form_userLastname.value == ""){
  		alert("Sukunimi on pakollinen kenttä!");
  		return false;
  	}
  	// Salasana
  	if(theForm.form_userPassword.value == ""){
  		alert("Salasana on pakollinen kenttä!");
  		return false;
  	}
  	// Sähköpostiosoite
  	if(theForm.form_userUsername.value == ""){
  		alert("Sähköpostiosoite on pakollinen kenttä!");
  		return false;
  	}
  	// Puhelin
  	if(theForm.form_userPhone.value == ""){
  		alert("Puhelin on pakollinen kenttä!");
  		return false;
  	}
  	// Katuosoite
  	if(theForm.form_siteAddress.value == ""){
  		alert("Katuosoite on pakollinen kenttä!");
  		return false;
  	}
  	// Postinumero
  	if(theForm.form_siteZip.value == ""){
  		alert("Postinumero on pakollinen kenttä!");
  		return false;
  	}
  	// Postitoimipaikka
  	if(theForm.form_siteCity.value == ""){
  		alert("Postitoimipaikka on pakollinen kenttä!");
  		return false;
  	}
  	// Sivuston osoite
  	if(theForm.form_siteSiteurl.value == ""){
  		alert("Sivuston osoite on pakollinen kenttä!");
  		return false;
  	}
  	// Sivuston nimi
  	if(theForm.form_siteSitename.value == ""){
  		alert("Sivuston nimi on pakollinen kenttä!");
  		return false;
  	}
  	// Hyväksyn ehdot
  	if(!theForm.form_acceptTerms.checked){
  		alert("Jotta tarjouspyyntösi voidaan hyväksyä tulee sinun vahvistaa antamasi tiedot!");
  		return false;
  	}
  	return true;
}

function validateMyInfoForm(theForm){
	// Etunimi
  	if(theForm.form_userFirstname.value == ""){
  		alert("Etunimi on pakollinen kenttä!");
  		return false;
  	}
  	// Sukunimi
  	if(theForm.form_userLastname.value == ""){
  		alert("Sukunimi on pakollinen kenttä!");
  		return false;
  	}
  	// Salasana
  	if(theForm.form_userPassword.value == ""){
  		alert("Salasana on pakollinen kenttä!");
  		return false;
  	}
  	// Puhelin
  	if(theForm.form_userPhone.value == ""){
  		alert("Puhelin on pakollinen kenttä!");
  		return false;
  	}
  	// Katuosoite
  	if(theForm.form_siteAddress.value == ""){
  		alert("Katuosoite on pakollinen kenttä!");
  		return false;
  	}
  	// Postinumero
  	if(theForm.form_siteZip.value == ""){
  		alert("Postinumero on pakollinen kenttä!");
  		return false;
  	}
  	// Postitoimipaikka
  	if(theForm.form_siteCity.value == ""){
  		alert("Postitoimipaikka on pakollinen kenttä!");
  		return false;
  	}
  	// Sivuston osoite
  	if(theForm.form_siteSiteurl.value == ""){
  		alert("Sivuston osoite on pakollinen kenttä!");
  		return false;
  	}
  	// Sivuston nimi
  	if(theForm.form_siteSitename.value == ""){
  		alert("Sivuston nimi on pakollinen kenttä!");
  		return false;
  	}
  	return true;
}
function setViewImages(){
    if(getView() == "yearly"){
        MM_swapImage('yearly', '', 'images/view-images/view_yearly_r.gif', 1);
        MM_swapImage('monthly', '', 'images/view-images/view_monthly.gif', 1);
        MM_swapImage('weekly', '', 'images/view-images/view_weekly.gif', 1);
        MM_swapImage('daily', '', 'images/view-images/view_daily.gif', 1);
        MM_swapImage('hourly', '', 'images/view-images/view_hourly.gif', 1);
    }
    else if(getView() == "monthly"){
        MM_swapImage('yearly', '', 'images/view-images/view_yearly.gif', 1);
        MM_swapImage('monthly', '', 'images/view-images/view_monthly_r.gif', 1);
        MM_swapImage('weekly', '', 'images/view-images/view_weekly.gif', 1);
        MM_swapImage('daily', '', 'images/view-images/view_daily.gif', 1);
        MM_swapImage('hourly', '', 'images/view-images/view_hourly.gif', 1);
    }
    else if(getView() == "weekly"){
        MM_swapImage('yearly', '', 'images/view-images/view_yearly.gif', 1);
        MM_swapImage('monthly', '', 'images/view-images/view_monthly.gif', 1);
        MM_swapImage('weekly', '', 'images/view-images/view_weekly_r.gif', 1);
        MM_swapImage('daily', '', 'images/view-images/view_daily.gif', 1);
        MM_swapImage('hourly', '', 'images/view-images/view_hourly.gif', 1);
    }
    else if(getView() == "daily"){
        MM_swapImage('yearly', '', 'images/view-images/view_yearly.gif', 1);
        MM_swapImage('monthly', '', 'images/view-images/view_monthly.gif', 1);
        MM_swapImage('weekly', '', 'images/view-images/view_weekly.gif', 1);
        MM_swapImage('daily', '', 'images/view-images/view_daily_r.gif', 1);
        MM_swapImage('hourly', '', 'images/view-images/view_hourly.gif', 1);
    }
    else if(getView() == "hourly"){
        MM_swapImage('yearly', '', 'images/view-images/view_yearly.gif', 1);
        MM_swapImage('monthly', '', 'images/view-images/view_monthly.gif', 1);
        MM_swapImage('weekly', '', 'images/view-images/view_weekly.gif', 1);
        MM_swapImage('daily', '', 'images/view-images/view_daily.gif', 1);
        MM_swapImage('hourly', '', 'images/view-images/view_hourly_r.gif', 1);
    }

}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
function getSite(){
	//return document.forms["siteSelect"].site.value;
	return document.forms["siteSelect"].selectedSite.value;
}
/*
function getYear(){
	return document.forms["selectForm"].year.value;
}
function getMonth(){
	return document.forms["selectForm"].month.value;
}
function getDay(){
	return document.forms["selectForm"].day.value;
}
*/
function getLang(){
    //return document.forms["selectForm"].lang.value;
    return document.forms["dateform"].lang.value;
}
function getChartName(){
    //return document.forms["selectForm"].chartName.value;
    return document.forms["dateform"].chartName.value;
}

/*
 * Aseta näkymä, joka näytetään käyttäjälle kaaviosta.
 * Samalla piilotetaan kaavio ja näytetään "loading..."
 * kunnes uusi kaavio on latautunut
 *
 * @param view parametri, joka asetetaan view kentän arvoksi dateform-lomakkeelle
 */
function setView(view){
    document.forms["dateform"].view.value = view;
    MM_swapImage('visitorsImage', '', 'images/spacer.gif', 1);
    MM_swapImage('visitorsImage', '', getVisitorImage(),1);
    setViewImages();
}
function getView(){
    return document.forms["dateform"].view.value;
}
/*
 * Avaa kalenteri ja kysy aloitus ja lopetus päivämäärät
 */
function showDateRangeSelector(){
        custom_cal = new Calendar('CUSTOM_START', startdate, 'NONE', myActDate, myEndDate, serverTime);
        showCustomCalendar();
}
/*
 * funktio, joka asettaa selectBarissa näytettävän tekstin sen mukaan missä kaaviossa ollaan.
 *
 * @return String selectBar palauttaa selectBarissa näytettävän tekstin
 */
function getSelectBar(){

    var selectBarItems = '';

    // sivulataukset yhteensä
    // sivulataukset / minuutti
    if(getChartName() == "Hit" || getChartName() == "OverAllAvg"){
        selectBarItems += '<nobr><a href="javascript:showDateRangeSelector();" onMouseOver="MM_swapImage(\'timeselect\', \'\', \'images/view-images/view_timeselect_r.gif\', 1);" onMouseOut="MM_swapImgRestore();"><img src="images/view-images/view_timeselect.gif" border=0 align="absmiddle" id="timeselect" name="timeselect" alt=""></a>';
        selectBarItems += '<a href="javascript:setView(\'yearly\');" onfocus="this.blur();"><img src="images/view-images/view_yearly.gif" border=0 align="absmiddle" id="yearly" name="yearly" alt=""></a>';
        selectBarItems += '<a href="javascript:setView(\'monthly\');"><img src="images/view-images/view_monthly.gif" border=0 align="absmiddle" id="monthly" name="monthly" alt=""></a>';
        selectBarItems += '<a href="javascript:setView(\'weekly\');"><img src="images/view-images/view_weekly.gif" border=0 align="absmiddle" id="weekly" name="weekly" alt=""></a>';
        selectBarItems += '<a href="javascript:setView(\'daily\');"><img src="images/view-images/view_daily.gif" border=0 align="absmiddle" id="daily" name="daily" alt=""></a>';
        selectBarItems += '<a href="javascript:setView(\'hourly\');"><img src="images/view-images/view_hourly.gif" border=0 align="absmiddle" id="hourly" name="hourly" alt=""></a></nobr>';
    }
    // Loput sivulataukset pääsivu alasivut
    else if(getChartName() == "Referer" || getChartName() == "Host" || getChartName() == "Directory" || getChartName() == "SearchEngine" || getChartName() == "SearchKeyword" || getChartName() == "TopPage" || getChartName() == "TopIsp") {
        selectBarItems += '<a href="javascript:showDateRangeSelector();"><img src="images/view-images/view_timeselect.gif" border=0 align="absmiddle" alt=""></a>';
    }
    return selectBarItems;
}
/*
 *
 */
function getFormatBar(){
    var imgValign = 'absbottom';
    var formatBar = '<br><br><nobr>';

    // format linkit
    formatBar += '<img src="/images/format-images/downloadChart_text.gif" border=0 alt="" align="absbottom">';
    formatBar += '<img src="/images/spacer.gif" height=10 width=50 border=0 alt="" align="absbottom">';
    formatBar += '<a href="javascript:showFormat(\'csv\');"><img src="/images/format-images/icon_csv.gif" border=0 align="absbottom" alt="CSV -formaatti"></a>';
    formatBar += '<a href="javascript:showFormat(\'excel\');"><img src="/images/format-images/icon_excel.gif" border=0 align="absbottom" alt="EXCEL -formaatti"></a>';
    formatBar += '<a href="javascript:showFormat(\'html\');"><img src="/images/format-images/icon_html.gif" border=0 align="absbottom" alt="HTML -formaatti"></a>';
    formatBar += '<a href="javascript:showFormat(\'pdf\');"><img src="/images/format-images/icon_pdf.gif" border=0 align="absbottom" alt="PDF -formaatti"></a>';
    //formatBar += '<a href="javascript:alert(\'PDF -Format is not ready yet!\');"><img src="/images/format-images/icon_pdf.gif" border=0 align="absbottom" alt="PDF -formaatti"></a>';
    // helppi linkki
    //formatBar += '&nbsp;<a href="javascript:helpMe(\''+getChartName()+'\');"><img src="images/format-images/query.gif" border="0" alt="Ohjeet" valign="'+imgValign+'"></a>';
    formatBar += '</nobr>';

    return formatBar;
}


/**
* Palauttaa visitors kuvan osoitteen
* Käytetään selectBarissa ja vasemmassa menussa
*/
function getVisitorImage(){
    var imgUrl = url;
    imgUrl += '?SITEID='+getSite();
    imgUrl += '&start='+document.forms['dateform'].start_date.value;
    imgUrl += '&end='+escape(document.forms['dateform'].end_date.value);
    imgUrl += '&lang='+getLang();
    imgUrl += '&chartName='+getChartName();
    imgUrl += '&view='+document.forms['dateform'].view.value;
    imgUrl += '&chartTitle='+escape(getChartTitle());
    setViewImages();
    //alert(imgUrl);
    return imgUrl;
}
var chartTitle = "";
function getChartTitle(){
    return chartTitle;
}

function setChartTitle(titleText){
    chartTitle = titleText;
}

/**
* Asetetaan chartName arvo lomakkeen kentään säilöön
*/
function updateChartName(val){
    //document.forms["selectForm"].chartName.value = val;
    document.forms["dateform"].chartName.value = val;
}
var url = "../servlet/Chart";

//
// onChange="MM_jumpMenu('parent',this,0)"
//
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

/*
 * Funktio, joka avaa help ikkunan tietynkokoisena
 * määritettyyn kohtaan ruudulla, käyttäen määritettyjä optioita.
 *
 * @param section kaavio, jonka helppi avataan
 */
function helpMe(chartName){
    var helpWinWidth       = 350;
    var helpWinHeight      = 400;
    var helpWinTopspacer   = 10;
    var helpWinRightSpacer = 20;

    var helpYcord = helpWinTopspacer;
    var helpXcord = (screen.availWidth - (helpWinWidth+helpWinRightSpacer));

    var helpWin;
    helpWin = window.open('includes/help.jsp?chart='+chartName, 'title', 'height='+helpWinHeight+',width='+helpWinWidth+',left='+helpXcord+',top='+helpYcord+',secreenX='+helpXcord+',ScreenY='+helpYcord+',status=0,toolbar=0,menubar=0,scrollbars=1,resizable=1,location=0,directories=0');
    helpWin.focus();
}


/*
 * Funktio, joka avaa html formatti ikkunan...
 */
function showFormat(format){

    var winWidth       = 500;
    var winHeight      = 270;
    var winTopSpacer   = 10;
    var winRightSpacer = 20;

    if(format == "html"){
        winWidth       = 690;
        winHeight      = 320;
    }

    var start = document.forms['dateform'].start_date.value;
    var end   = document.forms['dateform'].end_date.value;
    var view  = getView();

    var yCord = winTopSpacer;
    var xCord = (screen.availWidth - (winWidth+winRightSpacer));

    if(format == "pdf"){
       documentToOpen = 'servlet/PDFWriter';
    }
    else {
        documentToOpen = 'includes/'+format+'Format.jsp';
    }

    var winHandle;
    winHandle = window.open(documentToOpen+'?format='+format+'&chart='+getChartName()+'&start='+start+'&end='+end+'&view='+view, 'formatView', 'height='+winHeight+',width='+winWidth+',left='+xCord+',top='+yCord+',secreenX='+xCord+',ScreenY='+yCord+',status=0,toolbar=0,menubar=0,scrollbars=1,resizable=1,location=0,directories=0');
    winHandle.focus();
}

function selectAll(){

    status = (document.forms["dbResetForm"].toggle.checked) ? true : false;
    document.forms["dbResetForm"].reset_plugins.checked = status;
    document.forms["dbResetForm"].reset_hits.checked = status;
    document.forms["dbResetForm"].reset_referers.checked = status;
}
//-->

