var Drag = {
	obj : null,

	init : function(o, oRoot, minX, maxX, minY, maxY, bSwapHorzRef, bSwapVertRef, fXMapper, fYMapper)
	{
		o.onmousedown	= Drag.start;

		o.hmode			= bSwapHorzRef ? false : true ;
		o.vmode			= bSwapVertRef ? false : true ;

		o.root = oRoot && oRoot != null ? oRoot : o ;

		if (o.hmode  && isNaN(parseInt(o.root.style.left  ))) o.root.style.left   = "0px";
		if (o.vmode  && isNaN(parseInt(o.root.style.top   ))) o.root.style.top    = "0px";
		if (!o.hmode && isNaN(parseInt(o.root.style.right ))) o.root.style.right  = "0px";
		if (!o.vmode && isNaN(parseInt(o.root.style.bottom))) o.root.style.bottom = "0px";

		o.minX	= typeof minX != 'undefined' ? minX : null;
		o.minY	= typeof minY != 'undefined' ? minY : null;
		o.maxX	= typeof maxX != 'undefined' ? maxX : null;
		o.maxY	= typeof maxY != 'undefined' ? maxY : null;

		o.xMapper = fXMapper ? fXMapper : null;
		o.yMapper = fYMapper ? fYMapper : null;

		o.root.onDragStart	= new Function();
		o.root.onDragEnd	= new Function();
		o.root.onDrag		= new Function();
	},

	start : function(e)
	{
		var o = Drag.obj = this;
		e = Drag.fixE(e);
		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
		o.root.onDragStart(x, y);

		o.lastMouseX	= e.clientX;
		o.lastMouseY	= e.clientY;

		if (o.hmode) {
			if (o.minX != null)	o.minMouseX	= e.clientX - x + o.minX;
			if (o.maxX != null)	o.maxMouseX	= o.minMouseX + o.maxX - o.minX;
		} else {
			if (o.minX != null) o.maxMouseX = -o.minX + e.clientX + x;
			if (o.maxX != null) o.minMouseX = -o.maxX + e.clientX + x;
		}

		if (o.vmode) {
			if (o.minY != null)	o.minMouseY	= e.clientY - y + o.minY;
			if (o.maxY != null)	o.maxMouseY	= o.minMouseY + o.maxY - o.minY;
		} else {
			if (o.minY != null) o.maxMouseY = -o.minY + e.clientY + y;
			if (o.maxY != null) o.minMouseY = -o.maxY + e.clientY + y;
		}

		document.onmousemove	= Drag.drag;
		document.onmouseup		= Drag.end;

		return false;
	},

	drag : function(e)
	{
		e = Drag.fixE(e);
		var o = Drag.obj;

		var ey	= e.clientY;
		var ex	= e.clientX;
		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
		var nx, ny;

		if (o.minX != null) ex = o.hmode ? Math.max(ex, o.minMouseX) : Math.min(ex, o.maxMouseX);
		if (o.maxX != null) ex = o.hmode ? Math.min(ex, o.maxMouseX) : Math.max(ex, o.minMouseX);
		if (o.minY != null) ey = o.vmode ? Math.max(ey, o.minMouseY) : Math.min(ey, o.maxMouseY);
		if (o.maxY != null) ey = o.vmode ? Math.min(ey, o.maxMouseY) : Math.max(ey, o.minMouseY);

		nx = x + ((ex - o.lastMouseX) * (o.hmode ? 1 : -1));
		ny = y + ((ey - o.lastMouseY) * (o.vmode ? 1 : -1));

		if (o.xMapper)		nx = o.xMapper(y)
		else if (o.yMapper)	ny = o.yMapper(x)

		Drag.obj.root.style[o.hmode ? "left" : "right"] = nx + "px";
		Drag.obj.root.style[o.vmode ? "top" : "bottom"] = ny + "px";
		Drag.obj.lastMouseX	= ex;
		Drag.obj.lastMouseY	= ey;

		Drag.obj.root.onDrag(nx, ny);
		return false;
	},

	end : function()
	{
		document.onmousemove = null;
		document.onmouseup   = null;
		Drag.obj.root.onDragEnd(	parseInt(Drag.obj.root.style[Drag.obj.hmode ? "left" : "right"]),
		parseInt(Drag.obj.root.style[Drag.obj.vmode ? "top" : "bottom"]));
		Drag.obj = null;
	},

	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;
	}
};
function check_transaction(){
	document.transaction.submit();
}
function return_to_details_step(){
	document.getElementById('step_3').style.display = 'none'
	document.getElementById('step_2').style.display = ''
	
	document.getElementById('step_3_img').src = 'images/order_steps/3.gif';
	document.getElementById('step_2_img').src = 'images/order_steps/22.gif';
}
function go_to_pay_step(){
	document.getElementById('step_2').style.display = 'none'
	document.getElementById('step_3').style.display = ''
	
	document.getElementById('step_3_img').src = 'images/order_steps/33.gif';
	document.getElementById('step_2_img').src = 'images/order_steps/2.gif';
}
function return_to_template_step(){
	document.getElementById('step_2').style.display = 'none'
	document.getElementById('step_1').style.display = ''
	
	document.getElementById('step_1_img').src = 'images/order_steps/11.gif';
	document.getElementById('step_2_img').src = 'images/order_steps/2.gif';
}
function show_hide_user_panels(form){
	document.getElementById('edit_details_main_form').style.display = 'none'
	document.getElementById('edit_user_details_form').style.display = 'none'
	document.getElementById('edit_thanks_form').style.display = 'none'
	document.getElementById('edit_event_form').style.display = 'none'
	document.getElementById('edit_groom_form').style.display = 'none'
	document.getElementById('edit_bride_form').style.display = 'none'
	document.getElementById('edit_love_story_form').style.display = 'none'
	document.getElementById('edit_pictures_form').style.display = 'none'
	document.getElementById('edit_privacy_form').style.display = 'none'
	
	document.getElementById(form).style.display = ''
}
function delete_question(divNum){
	var d = document.getElementById('add_question');
	var olddiv = document.getElementById('question_'+divNum+'_view');	
	d.removeChild(olddiv);
}
function confirm_delete_question(num){
	var conf = confirm('האם אתה בטוח שברצונך למחוק את השאלה?');	
	if(conf){
		 delete_question(num);		
	}
}
function confirm_delete_quiz(){	
	return confirm('האם אתה בטוח שברצונך למחוק את השאלון');	
}
function confirm_delete_album(){
	return confirm('אם מחיקת האלבום ימחקו כל התמונות. האם אתה בטוח שברצונך למחוק את האלבום?');	
}
function confirm_delete_video(){
	return confirm('האם אתה בטוח שברצונך למחוק את קובץ הוידאו?');	
}
function albums_next_step(albums,pictures){
	if(document.getElementById('album_name').value !=''){
		if(document.getElementById('album_description').value.length<300){
			document.getElementById(albums).style.display='none';
			document.getElementById(pictures).style.display='';
		}
		else{
			alert('אורך התיאור גדול מ-300 תווים');
		}
	}
	else{
		alert('יש להזין שם לאלבום');
	}
}
function albums_forward_step(albums,pictures){
	document.getElementById(albums).style.display='';
	document.getElementById(pictures).style.display='none';
}
function edit_user_details_cat_view(panel1,panel2){		
	if(document.getElementById(panel2).style.display=='none'){
		document.getElementById(panel1).style.display='';
		document.getElementById(panel2).style.display='';		
	}
	else{
		document.getElementById(panel1).style.display='none';
		document.getElementById(panel2).style.display='none';
	}
}
function edit_user_password2(){
	document.getElementById('password_view4').style.display='';
	document.getElementById('password_view5').style.display='';
	document.getElementById('password_view6').style.display='';
	document.getElementById('edit_password3').style.display='none';
	document.getElementById('cancel_edit_password3').style.display='';
}
function cancel_edit_user_password2(){
	document.getElementById('password_view4').style.display='none';
	document.getElementById('password_view5').style.display='none';
	document.getElementById('password_view6').style.display='none';
	document.getElementById('edit_password3').style.display='';
	document.getElementById('cancel_edit_password3').style.display='none';
}
function edit_user_password(){
	document.getElementById('password_view1').style.display='';
	document.getElementById('password_view2').style.display='';
	document.getElementById('password_view3').style.display='';
	document.getElementById('edit_password').style.display='none';
	document.getElementById('cancel_edit_password').style.display='';
}
function cancel_edit_user_password(){
	document.getElementById('password_view1').style.display='none';
	document.getElementById('password_view2').style.display='none';
	document.getElementById('password_view3').style.display='none';
	document.getElementById('edit_password').style.display='';
	document.getElementById('cancel_edit_password').style.display='none';
}
function openWindowViewCard()
{
	window.open('view_card.html', 'newwin', 'status=no,menubar=no,resizable=no,scrollbars=no,width=708,height=410');
}
function openWindowWriteComment()
{
	window.open('write_comment.php', 'newwin', 'status=no,menubar=no,resizable=no,scrollbars=no,width=400,height=400');
}
function coupon_check(value){
	if(value=="free50"){
		document.getElementById('Amount').value = 549;
	}
	if(value=="free100"){
		document.getElementById('Amount').value = 499;
	}
	if(value=="free150"){
		document.getElementById('Amount').value = 449;
	}
}
