﻿
//var WebRootDir="http://www.361sport.com/promotion/marathon";
var WebRootDir="";
var historyFunction=[];
var historyArgument=[];
var historyMark=[]
var historyPoint=-1

var isInternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
// Handle all the FSCommand messages in a Flash movie.
function shell_DoFSCommand(command, args) {
	var shellObj = isInternetExplorer ? document.all.shell : document.shell;

	
	if(command=="uploadtry"){		
		 useruploadtry();
	}
	if(command=="browse"){		
		 userDoBrowseFile(args);
	}
	if(command=="setdata"){		
		 upformsetdata(args.split("|@@@|"));
	}
	if(command=="submit"){	
		 upformsubmit(args);		
	}
	if(command=="history"){	
		 historymark(args)		
	}
	if(command=="debug"){		
		 debug(args);
	}
	
}

function upformsetdata(arr){
//设置表单
	top[arr[0]].upform[arr[1]].value=arr[2];
}

function userDoBrowseFile(framename){
//浏览	
	try {
		if(typeof(top[framename].upform.f_url) == "object"){			
			top[framename].upform.f_url.click();			
		}
	} catch(err) {
		alert(err)
		return false;
	}
}
function upformsubmit(framename){
//提交上传
	var cframe=top[framename]
	if(cframe.upform.f_url.value==""){
		userDoBrowseFile()
	}else{		
		//提交上传
		cframe.upform.submit()
	}	
}
//flash
function sendvarToflash(arr){
//alert("sendvarToflash");
//给flash赋值arr为length=2的数组，例['_root.a','1']	
	document.shell.SetVariable(arr[0], arr[1]);
}



function sendvarToflash_headUpload(arr){
//网页给flash头像上传赋值	
	sendvarToflash(["_root.JSLObject.headvalue",arr.toString()]);
}
function sendvarToflash_photoUpload(arr){
//网页给flash照片上传赋值	
	sendvarToflash(["_root.JSLObject.photovalue",arr.toString()]);
}
function sendvarToflash_videoUpload(arr){
//网页给flash视频上传赋值	
	sendvarToflash(["_root.JSLObject.videovalue",arr.toString()]);
}
function sendvarToflash_musicUpload(arr){
//网页给flash音频上传赋值	
	sendvarToflash(["_root.JSLObject.musicvalue",arr.toString()]);
}

function historymark(arg){
	//删除当前historyPoint指针以后的所有记录
	var len=historyFunction.length
	var deletelen=len-historyPoint
	historyFunction.splice(historyPoint,deletelen)
	historyArgument.splice(historyPoint,deletelen)
	historyMark.splice(historyPoint,deletelen)
	

	//
	//alert(arg)
	var argmark=arg.split("|@@@|")
	historyFunction.push(argmark[0])
	historyArgument.push(argmark[1])


}
function historygo(flag){
	historyPoint+=flag;
	if(historyPoint<=historyFunction.length && historyPoint>=0){
		//alert("have history:"+historyFunction[historyPoint-1]);
		sendvarToflash(["_root.JSHObject.historyvalue",["historyFunction",historyFunction[historyPoint-1],"historyArgument",historyArgument[historyPoint-1]].toString()]);

	}else{
		alert("error：no history:"+flag);
		
	}
}
function checkhistory(flag){
	var canhistory=-1
	//是否有历史记录
	for(var i=0;i<=historyMark.length;i++){		
		if(flag==historyMark[i]){
			
			canhistory=i;
			break;
		}
	}
	//有
	if(canhistory>=0){
		//比较后退还是前进
		if(historyPoint>canhistory){
			historygo(-1);
		}else{
			historygo(1);
		}		
	}else{
		//为动作添加唯一标记
		historyMark.push(flag)
		historyPoint=historyFunction.length
		//alert("addmark::"+historyMark.toString())
	}
}
// Hook for Internet Explorer.
if (navigator.appName && navigator.appName.indexOf("Microsoft") != -1 && navigator.userAgent.indexOf("Windows") != -1 && navigator.userAgent.indexOf("Windows 3.1") == -1) {
	document.write('<script language=\"VBScript\"\>\n');
	document.write('On Error Resume Next\n');
	document.write('Sub shell_FSCommand(ByVal command, ByVal args)\n');
	document.write('	Call shell_DoFSCommand(command, args)\n');
	document.write('End Sub\n');
	document.write('</script\>\n');
}
// 
function swf_load(fileid, filename, widths, heights, fvs, wmd,bgcolor){

this.FlashVars = (fvs != undefined)? fvs :'';
this.Wmod = (wmd != undefined)? wmd :''; 
var Flashbgcolor=(bgcolor==""||bgcolor==null||bgcolor==undefined)?"ffffff":bgcolor
//添加变量
this.FlashVars+= (FlashPathObj2Str!=undefined)?FlashPathObj2Str():'';
var strSwf = "";
//alert(this.FlashVars);
strSwf += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"';
strSwf += 'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0"';
strSwf += 'width="'+widths+'" height="'+heights+'" id="'+fileid+'" >';
strSwf += '<param name="movie" value="'+filename+'" />';
strSwf += '<param name="quality" value="high" />';
strSwf += '<param name="menu" value="false" />';
strSwf += '<param name="bgcolor" value="'+Flashbgcolor+'" />';
strSwf += (FlashVars != null) ? '<param name="FlashVars" value="'+FlashVars+'">' : '';
strSwf += (Wmod != null) ? '<param name="wmode" value="'+Wmod+'">' : ''; 
strSwf += '<embed';
strSwf += (FlashVars != null) ? ' FlashVars="'+FlashVars+'"' : ''; 
strSwf += (Wmod != null) ? ' wmode="'+Wmod+'"' : ''; 
strSwf += ' src="'+filename+'" quality="high" menu="false" pluginspage="http://www.macromedia.com/go/getflashplayer"';
strSwf += 'type="application/x-shockwave-flash" width="'+widths+'" height="'+heights+'" name="'+fileid+'" ></embed>';
strSwf += '</object>';
document.write(strSwf);
}

function layer_hide(){
	document.all.popLayer.style.visibility = 'hidden';
	document.frames.board.location.href = 'blank.htm';
}

function layer_show(){
	document.all.popLayer.style.visibility = 'visible';
	document.frames.board.location.href = "event.html";
}


function openLayer(pageurl) 
{ 
	var w, h; 
	w = 330; 
	h = 275;
	pageurl = "event.html";

	WebRootDir2 = WebRootDir + "swf/"+ pageurl;
	
	var tempX = ((screen.width - w) / 2 - 1) - 140;
	var tempY = ((screen.height - h) / 2 - 1) - 70;
	
	popLayer.style.left = tempX;
		
	// NT 5.0  /  NT 5.1; SV2  / NT 5.2; SV1
	if (navigator.userAgent.indexOf("NT 5.0") > 0) {
		popLayer.style.top = tempY + 185;
		h -= 20;
	}
	else if (navigator.userAgent.indexOf("NT 5.2; SV1") > 0 || navigator.userAgent.indexOf("NT 5.1; SV2") > 0)
		popLayer.style.top = tempY - 195;
	else if (navigator.userAgent.indexOf("NT 5.1") > 0)
		popLayer.style.top = tempY - 185;	
	popLayer.innerHTML="<iframe name='popObject' src='"+WebRootDir2+"' frameborder='0' width='330' height='275' allowtransparency='true'></iframe>";
	popLayer.style.display = 'block';

	
}
function closeLayer() 
{
	popLayer.style.display = 'none';
}

function filedown(filename)
{
		var pop_event;
		var s_width; 
		  var s_height; 
		  
		  var posx=0;
		  var posy=0;
		  
		  s_width   = (screen.width); 
		  s_height  = (screen.height);  
		    
		  width     = 100; 
		  height    = 100;  
		    
		  posx = ((s_width - width) / 2 - 1) - 5; 
		  posy = ((s_height - height) / 2 - 1) - 5; 

		position = "width=" + width + ",height=" + height + ",scrollbars=no,top=0,left=0,resizable=no,status=no";
		pop_event = window.open(WebRootDir+filename,"down",position);
		pop_event.focus()

}
//
//Debug display
function debug(flag){
	debugtextbox.value+=flag+"\n";
	var temp_arr=debugtextbox.value.split("\n")
	if(temp_arr.length>100){
		debugtextbox.value=""
		var s=temp_arr.length-100
		for(var i=0;i<temp_arr.length;i++){
			debugtextbox.value+=temp_arr[i]+"\n";
		}
	}
	
}
function opendebug(){	
	debugLayer.style.display = 'block'
	upformLayer.style.display = 'block'
}
function closedebug(){
	debugLayer.style.display = 'none'
	upformLayer.style.display = 'none'
}
function cleardebug(){
	debugtextbox.value=""
}
function checkey(){ 
	if(event.ctrlKey&&event.keyCode==120) {//ctrl+F9
		if(debugLayer.style.display == 'none'){
			opendebug();
		}else{
			closedebug();	
		}		
	}
//alert(event.keyCode)
} 
document.onkeydown=checkey;
//
function ResumeError() { return true; }
window.onerror = ResumeError;
