﻿
//Cookieチェックと
function AJL_checkAllEnviroments(location, pre, iis){
	//check cookie
	if( !checkCookie(location, pre, iis) ){
		return false;
	}

	//Check flash player
	if( !windowOpen4FlashPlayer(location, pre, iis) ){
		return false;
	}
	return true;
}


function AJL_checkScriptAndFlashPlayer(){

	if( !windowOpen4FlashPlayer() ){
		return false;
	}
	return true;
}



function windowOpen4FlashPlayer(location, pre, iis){

	// Version check for the Flash Player that has the ability to start Player Product Install (6.0r65)
	var hasProductInstall = DetectFlashVer(6, 0, 65);

	// Version check based upon the values defined in globals
	var hasReqestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
	
	// Check to see if a player with Flash Product Install is available and the version does not meet the requirements for playback
	if ( hasProductInstall && !hasReqestedVersion ) {
		// MMdoctitle is the stored document.title value used by the installation process to close the window that started the process
		// This is necessary in order to close browser windows that are still utilizing the older version of the player after installation has completed
		// DO NOT MODIFY THE FOLLOWING FOUR LINES
		// Location visited after installation is complete if installation is required
		var MMPlayerType = (isIE == true) ? "ActiveX" : "PlugIn";
		//Set opener url
//		var MMredirectURL = window.location;
		var tmp = "cookiebasewindow=" + escape(document.location) + ";";
		
		document.cookie = tmp;
		document.title = document.title.slice(0, 47) + " - Flash Player Installation";
		var MMdoctitle = document.title;

		//【Debug】alert window
//		alert("■Open a window for EXPRESS INSTALL");
		//【Todo】write HTML hear
		//【Todo】document path here
		
		parent.location.href = "/playercheck/flash2.html?tmp=" + escape(document.location);
		return false;


	} else if (hasReqestedVersion) {
		//This enviroment is valid enough for amwaylive.
//		alert("VALID!! 何も起こらずコンテンツ表示。スルー");

		//tentative code
		//【Todo】現在は、デフォルトのサンプルムービー表示。環境OKならここが表示される
//	AC_FL_RunContent(
//			"src", "example",
//			"width", "550",
//			"height", "200",
//			"align", "middle",
//			"id", "detectionExample",
//			"quality", "high",
//			"bgcolor", "#FFFFFF",
//			"name", "detectionExample",
//			"allowScriptAccess","sameDomain",
//			"type", "application/x-shockwave-flash",
//			'codebase', 'http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab',
//			"pluginspage", "http://www.adobe.com/go/getflashplayer"
//	);
//
//		document.write("<p>元の呼ばれた画面を表示しています</p>");  // insert non-flash content


		return true;


	} else {
		// flash is too old or we can't detect the plugin
		//Window open for installing valid version of flash player.

		//【Debug】alert window
//		alert("★Open a window for installing flex player");
		
		parent.location.href = "/playercheck/flash.html?iis=" + iis;
//		//【Todo】write HTML hear
//
//		var alternateContent = 'Alternate HTML content should be placed here.<BR>'
//		+ 'This content requires the Adobe Flash Player. '
//		+ '<a href=http://www.adobe.com/go/getflash/>Get Flash</a>'
//		+ '<p>aiueo</p> ';
//		document.write(alternateContent);  // insert non-flash content
//
//
//		//【Todo】write HTML hear

		return false;

	}

}


function getCheckCookie( key, tmp1, tmp2, xx1, xx2, xx3 ){
    tmp1 = " " + document.cookie + ";";
    xx1 = xx2 = 0;
    len = tmp1.length;
    while (xx1 < len) {
        xx2 = tmp1.indexOf(";", xx1);
        tmp2 = tmp1.substring(xx1 + 1, xx2);
        xx3 = tmp2.indexOf("=");
        if (tmp2.substring(0, xx3) == key) {
            return(unescape(tmp2.substring(xx3 + 1, xx2 - xx1 - 1)));
        }
        xx1 = xx2 + 1;
    }
    return("");
}

function checkCookie(location, pre, iis){
	var tmp = "cookiecheck="+escape('true')+"; ";
	document.cookie = tmp;
	cookiecheck = getCheckCookie("cookiecheck");
	
	if ( cookiecheck == "true" ){
		//Cookie is available.
	        var tmp = "cookiecheck="+escape('')+"; ";
        	document.location.cookie = tmp;
		return true;
	}else{
		//Cookie is unavailable.
		//Cookie off so that the logic no loger gets progress down there.
		var preAddrs = "/playercheck/cookie.html?iis="+iis;
		subWin = window.open(preAddrs,'ajl_install_player','width=680,height=480,status=yes,scrollbars=yes');
		return false;
	}

}

