﻿//this is for scale the calendar image 
function scaleBasicImage(obj){
  if(isDebug) 
	  outputToConsole("enter function scaleBasicImage,src:"+obj.src); 
  var width =512;  
  var height = 316;
 
  loadedCalendarImagesNum = loadedCalendarImagesNum+1;
 	try{
 		var image = new Image();
 		image.src=obj.src;
 		var scalePercent = parseFloat(width/image.width);
 		var beishu = parseFloat(image.width/image.height);
 		  obj.width=width;
 		  height = scalePercent*image.height;
		  obj.height=height;
   if(initialDebug)
	    outputToConsole("the height:"+imageWidthScalePercent*image.height +"  imageWidthScalePercent:"+imageWidthScalePercent);		  
	 image = null;
   if(initialDebug)
	    outputToConsole("the parentid:"+obj.parentNode.id);	
		obj.parentNode.style.width = width+"px";
		obj.parentNode.style.height = height+"px";
		obj.parentNode.beishu = beishu;
		obj.parentNode.scalePercent = scalePercent;

   //example,<td><div id="baseLayer"><div id="cover"><img id=""><div id="coverLayer0"><img id="coverLayer0img"></div></div><div></td>	  
	}catch(e){
		alert("加載時產生錯誤！"+e.name+"  "+e.message);
	}
}

//this is used to scale the  image which user add
function resizePhoto(obj){
	var image = new Image();
	    image.src = obj.src;
	var width = image.width;
	var height = image.height;
	var beishu = parseFloat(width)/parseFloat(height);
	var percent=1;
	if(80<image.width){
		percent = 80.00/parseFloat(width);
		obj.width = 80;
		obj.height = height*percent;
	}
	obj.parentNode.setAttribute("beishu",beishu);
	obj.style.display="";
	image = null;
}
function out(){
	outputToConsole(document.getElementById("cover").innerHTML);
}
//this is for image loading error
function loadingError(obj){
	if(isDebug) outputToConsole("error ocurred when loading an image,maybe reflesh the page,src="+obj.src);
	if(obj.parentNode.id!=null&&(obj.parentNode.id.indexOf("front")==-1|| obj.parentNode.id.indexOf("back")==-1)){
		 if(obj.parentNode.parentNode!=null)obj.parentNode.style.display="none";
	  	//obj.parentNode.parentNode.removeChild(obj.parentNode);
	}
}

function sceneImageLoaded(image){
	loadedCalendarImagesNum = loadedCalendarImagesNum+1;
	var layer = image.parentNode;
	image.title="點擊進入設計";
	var newImg = new Image();
		  newImg.src = image.src;
	var width = newImg.width;
	var height = newImg.height;	
	if(width>height){
		layer.style.width = 196+"px";
		layer.style.height  = 118 + "px";
	}else{
		layer.style.width = 118+"px";
		layer.style.height  = 196 + "px";
	}
	
	
	//start(index,cardType,imagePath);
}
function getWidthAndHeight(){
	var obj = {width:0,height:0};
	if(window.innerWidth){
		obj.width = window.innerWidth;
		obj.height = window.innerHeight;
	}else if(document.body.clientWidth){
		obj.width = document.body.clientWidth;
		obj.height = document.body.clientHeight;
	}else if(document.documentElement){
		obj.width = document.documentElement.clientWidth;
		obj.width = document.documentElement.clientHeight;
	}
	return obj;
}