/*global self window AppVersion jk*/

function flash2js_SWFAddressSetValue(params){
	
	//window.setTimeout(jk.SWFAddress.setValue,1,params);
	jk.SWFAddress.setValue(params);
	jk.utils.debug("Flash->JS:flash2js_SWFAddressSetValue("+params+")",params);
}

function flex2js_showFlex(){
	jk.utils.debug("Flex->JS:flex2js_showFlex()");
	
	window.setTimeout(jk.flex.show,1);
	//return jk.flex.show();
	return true;
}

function showPreloader(params){
	
	//window.setTimeout(jk.flex.showPreload,1,params);
	jk.flex.showPreload(params);
	jk.utils.debug("Unknown->JS:showPreloader("+params+")",params);
	return true;
}

function forceFlex(){
	alert("forceFlex deprecated");
}

function wakeUpIE8(){
	alert("wakeUpIE8 deprecated");
}

function flex2js_showFlash(){
	jk.utils.debug("Flex->JS:flex2js_showFlash()");
	
	window.setTimeout(jk.flash.show,1);
	//jk.flash.show();
	return true;
}

function flex2js_ping(){
	jk.utils.debug("Flex->JS:flex2js_ping()");
	return jk.utils.ping();
}

function testSayEmediate() {
	alert('Testing say emediate!');
}

function flex2js_reload(params){
	jk.utils.debug("Flex->JS:flex2js_reload("+params+")",params);
	
	//Report Flex loading error -> restart
	jk.utils.reportTag("/Jokakoti/LoaderRestart");
	jk.utils.searchResultHandler.timeStamp = null;
	
	jk.utils.reloadPage(params);
}

function flex2js_bugReport(params){
	jk.utils.debug("Flex->JS:flex2js_bugReport("+params+")",params);
	
	//Report Flex loading error -> restart
	jk.utils.reportTag("/Jokakoti/LoaderFailed");
	jk.utils.searchResultHandler.timeStamp = null;
	
	jk.utils.openBugReport(params);
}

/* TO FLASH */
function flex2flash_search(params){
	jk.utils.debug("Flex->JS:flex2flash_search("+params+")",params);
	
	//window.setTimeout(jk.flash.presearch,1,params);
	jk.flash.presearch(params);
	return true;
}

function flex2flash_isReady(){
	jk.utils.debug("Flex->JS:flex2flash_isReady()");
	
	window.setTimeout(jk.flex.onLoadComplete,1);
	//jk.flex.onLoadComplete();
	return true;
}

/*TO FLEX*/
function flash2flex_isReady(){
	jk.utils.debug("Flash->JS:flash2flex_isReady()");
	
	window.setTimeout(jk.flash.onLoadComplete,1);
	//jk.flash.onLoadComplete();
	return true;
}

function flash2flex_search(params){
	jk.utils.debug("Flash->JS:flash2flex_search("+params+")",params);
	
	//window.setTimeout(jk.flex.presearch,1,params);
	jk.flex.presearch(params);
	return true;
}
function flash2flex_startSearch(params){
	jk.utils.debug("Flash->JS:flash2flex_startSearch("+params+")",params);

	
	/* Figure out what type the search was and report it */
	//XXXDOPXXX
	var tag = null;
	
	var haku = (params.searchMode=="list")?"Listahaku":"Karttahaku";
	
	if(params.searchType == 1){
		tag = "/Jokakoti/Etusivu/"+haku+"/Ostokohde";///"+params.searchCount;
	}else if(params.searchType == 2){
		tag = "/Jokakoti/Etusivu/"+haku+"/Vuokrakohde";///"+params.searchCount;
	}else if(params.searchType == 3){
		tag = "/Jokakoti/Etusivu/Haku/Yritys/"+params.searchString;
	}
	if(tag !== null){
		jk.utils.reportTag(tag);
	}
	
	jk.utils.searchResultHandler.init(params.searchType);
	
	//window.setTimeout(jk.flex.search,1,params);
	jk.flex.search(params);
	
	return true;
}

function flex2js_searchResultsVisible(){
	jk.utils.debug("Flex->JS:flex2js_searchResultsVisible()");
	jk.utils.searchResultHandler.onSuccess();
	return true;
}

function flash2flex_changeUrl(params){
	jk.utils.debug("Flash->JS:flash2flex_changeUrl("+params+")",params);
	
	//window.setTimeout(jk.flex.changeURL,1,params);
	jk.flex.changeURL(params);
	return true;
}

function flash2flex_showEstate(params){
	jk.utils.debug("Flash->JS:flash2flex_showEstate("+params+")",params);
	
	//window.setTimeout(jk.flex.showEstate,1,params);
	jk.flex.showEstate(params);
	
	//Report show estate command
	//XXXDOPXXX
	jk.utils.reportTag("/Jokakoti/Etusivu/Haku/HaeKoodilla/"+params);
		
	return true;
}

function flash2js_setHeight(height){
	alert("flash2js_setHeight is deprecated");
}

function flex2js_isReady(){
	jk.utils.debug("Flex->JS:flex2js_isReady()");
	
	window.setTimeout(jk.flex.onLoadComplete,1);
	//jk.flex.onLoadComplete();
	
	if (!jk.utils.reportedTags["/Jokakoti/LoaderReady"]) {
		//Report Flex loading done
		jk.utils.reportTag("/Jokakoti/LoaderReady");
	}
	
	return true;
}
function flex2js_preloaderReady(){
	jk.utils.debug("Flex->JS:flex2js_preloaderReady()");
	
	window.setTimeout(jk.flex.onLoadBegin,1);
	//jk.flex.onLoadBegin();
	
	//Report Flex preloader start
	jk.utils.reportTag("/Jokakoti/LoaderStart");
	
	return true;
}

function flash2js_debug(msg){
	jk.utils.debug("Flash->JS:flash2js_debug()");
	jk.utils.debug(msg);
}

function flexPercentLoaded(percent){
	alert("flexPercentLoaded deprecated");
}

function flash2js_startLoadingFlex(){
	jk.utils.debug("Flash->JS:flash2js_startLoadingFlex()");
	
	window.setTimeout(jk.flash.onLoadBegin,1);
	//jk.flash.onLoadBegin();
}

function addLoadEvent(func) {
	jk.utils.addPageLoadEvent(func);
}

function checkURL(){
	jk.init();
}

function jk_openPollPopup(){
	jk.utils.debug("Unknown->JS:jk_openPollPopup()");
	jk.poll.open();
	return true;
}
function jk_openPopup(url, title, options){
	jk.utils.popup(url,title,options);
}

function setCookie(cookieName,value,expiredays){
	jk.utils.debug("Unknown->JS:setCookie("+cookieName+","+value+","+expiredays+")",cookieName,value,expiredays);
	jk.cookie.set(cookieName,value,expiredays);
}

function getCookie(cookieName){
	jk.utils.debug("Unknown->JS:getCookie("+cookieName+")",cookieName);
	return jk.cookie.get(cookieName);
}



function flash2js_setLastSearch(params){
	jk.utils.debug("Flash->JS:flash2js_setLastSearch()",params);
	jk.cookie.set("lastSearch",params,30);
}

function flash2js_getLastSearch(){
	jk.utils.debug("Flash->JS:flash2js_getLastSearch()");
	return jk.cookie.get("lastSearch");
}

//jk.flash.init();
addLoadEvent(checkURL);

/* Fixed code from customer tracker */
function OmnsendPage_jokakoti(OmnpageName,Millisekunnit) {
	if (Millisekunnit === undefined) {
		OmnsendPage(OmnpageName);
	} else {
		var Omnrq = OmnmyProtocol + "//" + Omnsensor + "?Log=" + Omnlog + "&v=" + Omnver;
		var Omna = "";
		Omna += "&t=" + encodeURI(OmnpageName);
		
		Omna += "&v1=" + Millisekunnit;
		
		Omna += "&vid=" + Math.random();
		
		var Omnb = new Image();
		Omnb.src = Omnrq + Omna;
	}
} 
