/**
 * return the flash object with the flash name.
 * 
 * @param flashName, it is the name attribute of embed tag, or the id of object attribute.
 * @return
 */
function getFlashMovieObject(flashName)
{
  if (window.document[flashName]) 
  {
      return window.document[flashName];
  }
  if (navigator.appName.indexOf("Microsoft Internet")==-1)
  {
    if (document.embeds && document.embeds[flashName])
      return document.embeds[flashName]; 
  }
  else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
  {
    return document.getElementById(flashName);
  } 	
}


function addModelToECardEditor(_id, _customName,_daeScale, _initX	, _initY, _initZ,
		_initRotX, _initRotY, _initRotZ, _fileType, _materialName, _meshName,
		_isInteractive,_isShowMsg,  _onClickMsg, _filePath, _imagePath, _uiStatus, _aniType, _aniStrength){
	
	var obj = getFlashMovieObject("eCardEditor"); 
	
	if (navigator.appName.indexOf ("Microsoft") !=-1) {
		obj.addModelIntoLibrary(_customName,_daeScale, _initX	, _initY, _initZ,
				_initRotX, _initRotY, _initRotZ, _fileType, _materialName, _meshName,
				_isInteractive,_isShowMsg,  _onClickMsg, _filePath, _imagePath, 
				_uiStatus,_aniType, _aniStrength);
	} else {
		obj.addModelIntoLibrary(_customName,_daeScale, _initX	, _initY, _initZ,
				_initRotX, _initRotY, _initRotZ, _fileType, _materialName, _meshName,
				_isInteractive,_isShowMsg,  _onClickMsg, _filePath, _imagePath, 
				_uiStatus,_aniType, _aniStrength);
	}
	
	//alert("call flash addModelIntoLibrary:"+_id +":"+name +":"+ _imagePath +":"+ _filePath);

}

function setSceneToECardEditor(_id, _customName,_daeScale,_fileType,_refPath, _imagePath){
	
	var obj = getFlashMovieObject("eCardEditor");
	
	if (navigator.appName.indexOf ("Microsoft") !=-1) {
		obj.setScene(_customName,_daeScale,  _fileType,  _refPath, _imagePath);
	} else {
		obj.setScene(_customName,_daeScale,  _fileType,  _refPath, _imagePath);
	}
	//alert("_filePath=" + refPath);
	//alert("call flash addModelIntoLibrary:"+_id +":"+name +":"+ _imagePath +":"+ _filePath);

}

//function js_saveCard(obj){
//	
//	document.getElementById("save_cardXML").value = obj.cardXmlStr;
//	document.getElementById("save_cardName").value =obj.cardName;
//	document.getElementById("saveCardForm").submit();
//}

function refreshSubCategory(catName, obj){
	
	/*var targetDiv = obj.parentNode.getElementsByTagName("ul")[0];*/
	var targetIFrame = document.getElementById('ecardEditorPanel');
	
	targetIFrame.src = "ecard.do?action=innerEditor";
	
	if (catName == 'scene' ){
		targetIFrame.src+="&cat=scene";
	}
	else if (catName == 'model'){
		targetIFrame.src+="&cat=model";
	}
	else if (catName == 'effect'){
		targetIFrame.src+="&cat=effect";
	}
	else if (catName == 'ecard'){
		targetIFrame.src+="&cat=ecard";
	}
	else if (catName == 'extra'){
		targetIFrame.src+="&cat=extra";
	}
	else{
		targetIFrame.src="jsp/error.jsp";
	}
	
	/*var contentHTML = "";
	for (var i=0; i< subCatArray.length; i++){
		contentHTML += "<li><a>" + subCatArray[i]+ "</a></li>";
	}
	targetDiv.innerHTML = contentHTML;*/
}

function loadTemplateCardXML(cardPath){
	var obj = getFlashMovieObject("eCardEditor");
	
	if (navigator.appName.indexOf ("Microsoft") !=-1) {
		obj.loadTemplateCardXML(cardPath);
	} else {
		obj.loadTemplateCardXML(cardPath);
	}
}

function loadCardForEditing(cardPath){
	
}

function openSendCardPanel(obj){
	
	//alert(obj.name);
}