// JavaScript Document
var ajaxURL_CD="/f/apps/card/card_ajax.php";
function GetXmlHttpObject()
{
	try
	{ // Firefox, Opera 8.0+, Safari
		var fm_xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{ // Internet Explorer
		try
		{
			fm_xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		 catch (e)
		{
			try 
			{
				fm_xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
				alert("Your browser does not support AJAX, please try with another browser or on different computer!");
			}
		}
	}
	return fm_xmlHttp;
}
function fm_getOffsetTop(elm) 
{
	var mOffsetTop = elm.offsetTop;
	var mOffsetParent = elm.offsetParent;	
	while(mOffsetParent)
	{
		mOffsetTop += mOffsetParent.offsetTop;
		mOffsetParent = mOffsetParent.offsetParent;
	}	
	return mOffsetTop;
}
function fm_getOffsetLeft(elm) 
{
	var mOffsetLeft = elm.offsetLeft;
	var mOffsetParent = elm.offsetParent;

	while(mOffsetParent)
	{
		mOffsetLeft += mOffsetParent.offsetLeft;
		mOffsetParent = mOffsetParent.offsetParent;
	}
	return mOffsetLeft;
}
function fm_getYOffset() 
{
    var pageY;
    if(typeof(window.pageYOffset)=='number') 
	{	pageY=window.pageYOffset;}
    else {	pageY=document.documentElement.scrollTop;}
    return pageY;
}
function fm_getXOffset() 
{
    var pageX;
    if(typeof(window.pageXOffset)=='number') 
	{	pageX=window.pageXOffset;}
    else {	pageX=document.documentElement.scrollLeft;}
    return pageX;
}
function isArray(obj) {
    return obj.constructor == Array;
}
function fm_colse(id_name)
{
	document.getElementById(id_name).innerHTML='loading...';
	document.getElementById(id_name).style.display='none';
}
function fm_closeBox(id_name,not_move)
{
	if (not_move==-1)//move
		return "<div id='"+id_name+"_move' style='cursor:move;float:left;padding:2px' class='fm_btn'>Move</div><div align=right style='padding:0 0 2px 5px;'> <img src='/images/close_window.gif' onclick=\"fm_colse('"+id_name+"')\" style='cursor:pointer'></div>";
	else return "<div align=right style='padding:0 0 2px 5px;'> <img src='/images/close_window.gif' onclick=\"fm_colse('"+id_name+"')\" style='cursor:pointer'></div>";
		//return "<table cellspacing=0 cellpadding=0 border=0><tr><td><div id='"+id_name+"_move' style='cursor:move' class='fm_btn' style='padding:3px'>Move</div></td><td align=right style='padding:0 0 2px 5px;'> <img src='/images/close_window.gif' onclick=\"fm_colse('"+id_name+"')\" style='cursor:pointer'></td></tr></table>";
}
//id_name nothing, with value show close btn
//id_name -1 add value to innerHTML
function fm_getAjaxContent(obj,url,id_name,no_close)
{
	var fm_xmlHttp=GetXmlHttpObject();
	if (fm_xmlHttp==null)
	{
	  alert ("Browser does not support HTTP Request");
	  return;
	} 
	url=url+"&y="+Math.random();
	fm_xmlHttp.onreadystatechange=function (){
		if (fm_xmlHttp.readyState==4 || fm_xmlHttp.readyState=="complete")
		{
			if (id_name==-1)	obj.innerHTML+=fm_xmlHttp.responseText;			
			else if (id_name && !no_close)	
				obj.innerHTML=fm_closeBox(id_name,0)+fm_xmlHttp.responseText;
			else	obj.innerHTML=fm_xmlHttp.responseText;
		}
	};
	fm_xmlHttp.open("GET",url,true);
	fm_xmlHttp.send(null);	
}
var Drag = {
	obj : null,move : null,
	init : function(o,target)
	{//target is the moving target instead of o, mousedown on o but move target
		Drag.move=o;
		Drag.move.onmousedown= Drag.start;	
		if (target)	Drag.obj=target;
		else Drag.obj=o;
	},

	start : function(e)
	{
		//var o =Drag.obj= this;
		e = Drag.fixE(e);
		var y = parseInt(Drag.obj.style.top);
		var x = parseInt(Drag.obj.style.left);
		Drag.obj.lastMouseX	= e.clientX;
		Drag.obj.lastMouseY	= e.clientY;
		document.onmousemove	= Drag.drag;
		document.onmouseup		= Drag.end;
		return false;
	},

	drag : function(e)
	{
		e = Drag.fixE(e);
		
		var ey	= e.clientY;
		var ex	= e.clientX;
		var y = parseInt(Drag.obj.style.top);
		var x = parseInt(Drag.obj.style.left);
		var nx, ny;

		nx = x + ex - Drag.obj.lastMouseX;
		ny = y + ey - Drag.obj.lastMouseY;

		Drag.obj.style.left = nx + "px";
		Drag.obj.style.top= ny + "px";
		Drag.obj.lastMouseX	= ex;
		Drag.obj.lastMouseY	= ey;

		return false;
	},

	end : function()
	{
		document.onmousemove = null;
		document.onmouseup   = null;		
		ajax_boxStartingTop=parseInt(Drag.obj.style.top);
		ajax_boxStartingLeft=parseInt(Drag.obj.style.left);
	},

	fixE : function(e)
	{
		if (typeof e == 'undefined') e = window.event;
		if (typeof e.layerX == 'undefined') e.layerX = e.offsetX;
		if (typeof e.layerY == 'undefined') e.layerY = e.offsetY;
		return e;
	}
};
//type 0 box showing right side cur obj, 1 same left and top as cur obj
//array show in the middle of the page 0 is width 1 is height
//array if the 3rd element is 1, width and height is related to the top left point of the current obj
//type <0 box showing lef side cur obj, abs(type) is the width of cur obj
//if url =-1 no ajax
//if no_close =2 no border and no close
function fm_contenBoxMaker(id_name,url,cur_obj,type,frame_html,no_close,is_grey_border)
{
	if (document.getElementById(id_name)==null)
	{
		var fm_frame=document.createElement('div');//frame
		document.body.appendChild(fm_frame);
		fm_frame.id=id_name;
		fm_frame.style.position="absolute";	
		fm_frame.style.textAlign="left";	
		fm_frame.style.backgroundColor="#FFFFFF";	
		if (no_close!=2)
		{
			if (is_grey_border)
			{
				fm_frame.style.border="2px solid #CCCCCC";	
				fm_frame.style.padding="10px";
			}
			else
			{
				fm_frame.style.padding="5px";
				fm_frame.style.border="5px solid #f17d7e";	
			}			
		}
		fm_frame.style.zIndex="3000";
	}		
	else	var fm_frame=document.getElementById(id_name);
	//set size
	if (isArray(type))	
	{
		if (type[2])	fm_frame.style.top=(fm_getOffsetTop(cur_obj)+type[1])+"px";		
		else	fm_frame.style.top=(fm_getYOffset()+(document.documentElement.clientHeight-type[1])/2)+"px";		
	}
	else	fm_frame.style.top=fm_getOffsetTop(cur_obj)+"px";	
	
	if (isArray(type))	
	{
		if (type[2])	fm_frame.style.left=(fm_getOffsetLeft(cur_obj)+type[0])+"px";		
		else	fm_frame.style.left=(fm_getXOffset()+(document.documentElement.clientWidth-type[0])/2)+"px";
	}
	else if (type<0)	fm_frame.style.left=(fm_getOffsetLeft(cur_obj)-Math.abs(parseInt(type))-15)+"px";
	else if (type==1)	fm_frame.style.left=fm_getOffsetLeft(cur_obj)+"px";
	else	fm_frame.style.left=(fm_getOffsetLeft(cur_obj)+cur_obj.offsetWidth+5)+"px";

	fm_frame.style.display="block";
	if (url==-1)	
	{
		fm_frame.innerHTML='';
		if (no_close<1)	fm_frame.innerHTML=fm_closeBox(id_name,no_close);
		fm_frame.innerHTML+=frame_html;
		if (no_close==-1) 
			Drag.init(document.getElementById(id_name+"_move"),document.getElementById(id_name));
	}
	else
	{
		fm_frame.innerHTML="<center>Loading...</center>";
		fm_getAjaxContent(fm_frame,url,id_name,no_close);
	}
	
}
/* end of contentBoxMaker and getAjaxContent*/
/*	cd_xmlHttp.open("POST", url);
	var ssss="abc=s&cd=11";
	cd_xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
cd_xmlHttp.setRequestHeader("Content-length", ssss.length);

	 cd_xmlHttp.send(ssss);*/
function autoSave_CD(name,value,card_id,table)
{
	var cd_xmlHttp=GetXmlHttpObject();
	if (cd_xmlHttp==null)
	{
	  alert ("Browser does not support HTTP Request");
	  return;
	} 
	if (!table)	table='card';
	value=value.replace(/&/g, "%26");
	value=value.replace(/\?/g, "%3F");
	value=value.replace(/#/g, "%23");
	var url=ajaxURL_CD+"?type=1&name="+name+"&table="+table+"&value="+value;
	if (card_id)	url=url+"&card_id="+card_id;
	url=url+"&y="+Math.random();
	cd_xmlHttp.open("GET",url,true);
	cd_xmlHttp.send(null);		
	//alert(url);
}
function hintBoxMaker_CD(name,cur_obj,option,pozition)
{
	fm_contenBoxMaker(name,ajaxURL_CD+"?type=2&option="+option,cur_obj,pozition,"",0,0);
}
function imgBoxMaker_CD(name,cur_obj,option,pozition,img_id,size,card_id,max_dem,idea_dem)
{
	fm_contenBoxMaker(name,-1,cur_obj,pozition,"<iframe src=\"/f/apps/card/img_upload_form.php?img_id="+img_id+"&box_name="+name+"&size="+size+"&card_id="+card_id+"&max_dem="+max_dem+"&idea_dem="+idea_dem+"\" frameborder=0 scrolling='no' allowtransparency='true' width='250px' height='160px'></iframe>",0,0);
}
function ideaBoxMaker_CD(name,cur_obj,pozition,card_id,field,mesg_cat)
{
	fm_contenBoxMaker(name,-1,cur_obj,pozition,"<iframe src=\"/f/apps/card/message_idea.php?card_id="+card_id+"&field="+field+"&mesg_cat="+mesg_cat+"\" frameborder=0 scrolling='no' allowtransparency='true' width='200px' height='220px'></iframe>",0,0);
}
function previewBoxMaker_CD(name,cur_obj,width,height,id_name,id,position)
{
	fm_contenBoxMaker(name,-1,cur_obj,new Array(width,height),"<iframe name='showing_card' id='showing_card' src=\"/f/apps/card/preview.php?id_name="+id_name+"&id="+id+"\" frameborder=0 scrolling='no' allowtransparency='true' width='"+width+"px' height='"+height+"px'></iframe>",-1,1);	
	
//	fm_contenBoxMaker(name,-1,cur_obj,new Array(width,height),"<iframe name='showing_card' src=\"/f/apps/card/preview.php?id_name="+id_name+"&id="+id+"\" frameborder=0 scrolling='no' allowtransparency='true' width='"+width+"px' height='"+height+"px'></iframe>",0,1);	
	/*
	if (position==2)
		fm_contenBoxMaker(name,-1,cur_obj,1,"<iframe name='showing_card' src=\"/f/apps/card/preview.php?id_name="+id_name+"&id="+id+"\" frameborder=0 scrolling='no' allowtransparency='true' width='"+width+"px' height='"+height+"px'></iframe>",0);
	else if (position)
		fm_contenBoxMaker(name,-1,cur_obj,0,"<iframe name='showing_card' src=\"/f/apps/card/preview.php?id_name="+id_name+"&id="+id+"\" frameborder=0 scrolling='no' allowtransparency='true' width='"+width+"px' height='"+height+"px'></iframe>",0);
	else	fm_contenBoxMaker(name,-1,cur_obj,new Array(-(width+20),0,1),"<iframe  name='showing_card' src=\"/f/apps/card/preview.php?id_name="+id_name+"&id="+id+"\" frameborder=0 scrolling='no' allowtransparency='true' width='"+width+"px' height='"+height+"px'></iframe>",0);
	*/
}

function print_box_ins(cur_obj,id_name,id,width,height)
{
	width=663;
	height=430;
	fm_contenBoxMaker('print_view_ins',-1,cur_obj,new Array(width,height/2),"<b>For optimal printing,</b> you may need to upgrade your browser to the latest versions of Firefox or Internet Explorer.<br><br><br>Download the latest versions here:<br><br><a href='http://www.mozilla.com/en-US/firefox/personal.html'>Firefox</a><br><br><a href='http://www.microsoft.com/windows/Internet-explorer/default.aspx'>Internet Explorer</a><br><br><Br><Br><b>To print this card:</b><br><br>1) Internet Explorer Users<br><br>Click 'Tools -> Internet Options'<br>Click 'Advanced'<br>Scroll down until you see 'Printing' and check 'Print background colors and images'<br>Click 'OK'<br><br><br>2) Firefox Users<br><br>Click 'File -> Page Setup'<br>Check 'Print Background (colors & images)<br><br><a href='#' onclick=\"document.getElementById('print_view_ins').style.display='none';print_box('"+id_name+"',"+id+","+width+","+height+");return false;\">Print this card</a>",0,0);		
}

function print_box(id_name,id,width,height)
{
	fm_contenBoxMaker('print_view',-1,document.getElementById('print_card_btn'),new Array(-width+100,-height-100,1),"<iframe  name='showing_card' src=\"/f/apps/card/preview.php?id_name="+id_name+"&id="+id+"&print=1\" frameborder=0 scrolling='no' allowtransparency='true' width='"+width+"px' height='"+height+"px'></iframe>",0,1);
}
function get_popBox(id_name,cur_obj,card_id,no_save,return_url)
{
//	alert(return_url);
	//fm_contenBoxMaker(id_name,ajaxURL_CD+"?type=5&mode="+mode+"&card_id="+card_id,cur_obj,new Array(width,0,1),'',1);
	fm_contenBoxMaker(id_name,-1,cur_obj,new Array(-20,0,1),"<iframe src=\"/f/apps/card/login_page.php?card_id="+card_id+"&no_save="+no_save+"&return_url="+return_url+"\" frameborder=0 scrolling='no' allowtransparency='true' width='335px' height='140px'></iframe>",0,0);
}
function recepientBox(cur_obj,height,url,id)
{
	fm_contenBoxMaker('recepientBox',-1,cur_obj,new Array(560,height),"<iframe src=\""+url+"card_id="+id+"\" frameborder=0 scrolling='no' allowtransparency='true' width='560px' height='"+height+"px'></iframe>",0,0);
}
function name_finderPopup(cur_obj)
{
	if (!document.getElementById("name_finder"))
	fm_contenBoxMaker("name_finder",-1,cur_obj,new Array(-200,0,1),"<div style='width:130px;' align=center>Looking for a Baby<br>Name?<br><a href='http://www.babyzone.com/babynames/' style='font-size:11px;color:#48c2c5' target='_blank'>Click here to try our<br>Name Finder</a></div>",0,0);
}
function thanksPopup(cur_obj,text)
{
	if (!document.getElementById("name_finder"))
	fm_contenBoxMaker("thanks_popwindow",-1,cur_obj,new Array(200,100),text,0,0);
}
var TmpPopuptimeer="";
var preview_abc=0;
function viewTmpPopup(cur_obj,template_id)
{
	if (preview_abc)
	{
	clearInterval(TmpPopuptimeer);
	var the_url=ajaxURL_CD+'?type=12&template_id='+template_id;
	fm_contenBoxMaker('pre_show_template',-1,cur_obj,new Array((cur_obj.width-123)/2,(cur_obj.height-50)/2,1),"<div class='preview_nob' onmouseover='TmpPopuptimeer=clearInterval(TmpPopuptimeer);' onclick=\"fm_contenBoxMaker('show_template','"+the_url+"',new Object(),new Array(0,0),'',2,0)\" style='cursor:pointer'>&nbsp;</div>",2,0);
	}
	
}
function offTmpPopup()
{
	if (preview_abc)
	{
	TmpPopuptimeer=setInterval(function (){
		document.getElementById('pre_show_template').style.display='none';
		TmpPopuptimeer=clearInterval(TmpPopuptimeer);
		},500);
	}
}


