/*
 JS form popup support (thickbox style)
 GPL Intime It 2010
 --------------------
 dependencies 
   loginform.css style to be loaded
   jquery
   jquery.form
 
*/


// base object with default values and methods
var seat_hndl = {
  // config vars
  loading_url:jsrelpath+'images/tbf_loading.gif',
  closebut_url:jsrelpath+'images/close_win.png',
  loading_img: new Image(),
  getfrm_url:jsrelpath+'shop/seatmap.php',
  caption:'',
  act_height:550, act_width:830,  // default size
  max_height:640,max_width:830,
  
  init: function () {
    seat_hndl.loading_img.src = seat_hndl.loading_url; // preload
    seat_hndl.max_height = getmyHeight();
    seat_hndl.max_width = getmyWidth();
  },
  

  seatform: function (params) {
  
  	    if (typeof params == "undefined") {errhnd.error(33400,'seatselect:params undefined');}
  	    
  	    seat_hndl.caption = 'RIK S&aelig;de valg';
  	    params.height = 550;  params.width = 500;
  	    
		seat_hndl.show_win(params);
		
        $("#TB_ajaxContent").hide();
        params.cmd = 'getform';

     errhnd.logobj(params,'seatselect.params (bef getform)');

        $.ajax({type:'POST', url:seat_hndl.getfrm_url, dataType:'json', data:params,
             success:	function(data){
                errhnd.logobj(data,'formdata');
 			     $("#TB_ajaxContent").html(data.formdata);
  			     seat_hndl.position();
                 $("#TB_ajaxContent").show();
                 
 			     
 				 $("#TB_load").remove();
				 $("#TB_window").css({display:"block"});
/*				 
 	             params.cmd = 'seatselform';
  
				 $("#seatselform").ajaxForm({data:params,url:seat_hndl.getfrm_url, dataType:'json', 

                   beforeSubmit: function(a) {
                   }, // end beforeSubmit

                   success: function (responseText, statusText, xhr, $form) {
                     errhnd.logobj(responseText,'responseText');
                     if (responseText.update) {
                         eval(responseText.updateexp);
                     }
                     if (responseText.refreshmes) {
           			     $("#loginformmes").html(responseText.loginformmes).hide().show(1);
                     }
                     if (responseText.refresh) {
                        location.reload(true);
                     }
                     if (responseText.close) {
                        seat_hndl.remove();
                     }
                     if (responseText.gotonuser) {
                        seat_hndl.nuserbox({});
                     }
                   } // end success
				 }); // end ajaxForm
*/				 
 			  } 
		}); // end ajax
  }, // end function loginbox

  seatselect: function (b,r,s) {
     params = {};
     params.cmd = 'seatselect';
     params.seatselect_block = b;
     params.seatselect_row = r;
     params.seatselect_seat = s;
    
     $.ajax({type:'POST', url:seat_hndl.getfrm_url, dataType:'json', data:params,
             success:	function(data){
                if (data.close) {
                    seat_hndl.remove();
                }
                if (data.refresh) {
                    location.reload(true);
                }
             }
     }); // end ajax
   
  }, // end function seatselect
  
  show_win: function (params) {
  
       if (typeof params.height !== "undefined") seat_hndl.act_height = params.height;
       if (typeof params.width!== "undefined")   seat_hndl.act_width= params.width;

       if(seat_hndl.act_height>seat_hndl.max_height) seat_hndl.act_height = seat_hndl.max_height-10;
       if(seat_hndl.act_width>seat_hndl.max_width) seat_hndl.act_width= seat_hndl.max_width-10;
       
		if (typeof document.body.style.maxHeight === "undefined") {//if IE 6
			$("body","html").css({height: "100%", width: "100%"});
			$("html").css("overflow","hidden");
			if (document.getElementById("TB_HideSelect") === null) {//iframe to hide select elements in ie6
				$("body").append("<iframe id='TB_HideSelect'></iframe><div id='TB_overlay'></div><div id='TB_window'></div>");
				$("#TB_overlay").click(seat_hndl.remove);
			}
		}else{//all others
			if(document.getElementById("TB_overlay") === null){
				$("body").append("<div id='TB_overlay'></div><div id='TB_window'></div>");
				$("#TB_overlay").click(seat_hndl.remove);
			}
		}
		
//		if(tb_detectMacXFF()){
//			$("#TB_overlay").addClass("TB_overlayMacFFBGHack");//use png overlay so hide flash
//		}else{
			$("#TB_overlay").addClass("TB_overlayBG");//use background and opacity
//		}
		
		$("body").append("<div id='TB_load'><img src='"+seat_hndl.loading_img.src+"' /></div>");//add loader to the page
		$('#TB_load').show();//show loader
		
		ajaxContentW = seat_hndl.act_width - 30;
		ajaxContentH = seat_hndl.act_height - 45;
			
		if(0 /*url.indexOf('TB_iframe') != -1*/){// either iframe or ajax window		

/*				urlNoQuery = url.split('TB_');
					$("#TB_iframeContent").remove();
					if(params['modal'] != "true"){//iframe no modal
						$("#TB_window").append("<div id='TB_title'><div id='TB_ajaxWindowTitle'>"+caption+"</div><div id='TB_closeAjaxWindow'><a href='#' id='TB_closeWindowButton' title='Close'>close</a> or Esc Key</div></div><iframe frameborder='0' hspace='0' src='"+urlNoQuery[0]+"' id='TB_iframeContent' name='TB_iframeContent"+Math.round(Math.random()*1000)+"' onload='tb_showIframe()' style='width:"+(ajaxContentW + 29)+"px;height:"+(ajaxContentH + 17)+"px;' > </iframe>");
					}else{//iframe modal
					$("#TB_overlay").unbind();
						$("#TB_window").append("<iframe frameborder='0' hspace='0' src='"+urlNoQuery[0]+"' id='TB_iframeContent' name='TB_iframeContent"+Math.round(Math.random()*1000)+"' onload='tb_showIframe()' style='width:"+(ajaxContentW + 29)+"px;height:"+(ajaxContentH + 17)+"px;'> </iframe>");
					}
*/			
 		} else {// not an iframe, ajax
			        
		  if($("#TB_window").css("display") != "block"){
		    if(params['modal'] != "true"){//ajax no modal
		      $("#TB_window").append("<div id='TB_title'><div id='TB_ajaxWindowTitle'>"+seat_hndl.caption+"</div><div id='TB_closeAjaxWindow'><a href='#' id='TB_closeWindowButton'><img width='16px' style='border:0' src='"+seat_hndl.closebut_url+"'></a></div></div><div id='TB_ajaxContent' style='width:"+ajaxContentW+"px;height:"+ajaxContentH+"px'></div>");
   		    }else{//ajax modal
			  $("#TB_overlay").unbind();
			  $("#TB_window").append("<div id='TB_ajaxContent' class='TB_modal' style='width:"+ajaxContentW+"px;height:"+ajaxContentH+"px;'></div>");	
  	        }
		  } else {//this means the window is already up, we are just loading new content via ajax
		  	  $("#TB_ajaxContent")[0].style.width = ajaxContentW +"px";
			  $("#TB_ajaxContent")[0].style.height = ajaxContentH +"px";
			  $("#TB_ajaxContent")[0].scrollTop = 0;
			  $("#TB_ajaxWindowTitle").html(seat_hndl.caption);
		  }
		} // endif iframe or ajax
					
		$("#TB_closeWindowButton").click(seat_hndl.remove);
  
  },// end function show_win

  

  position: function () {
     $("#TB_window").css({marginLeft: '-' + parseInt((seat_hndl.act_width / 2),10) + 'px', width: seat_hndl.act_width + 'px'});
//	 if ( !(jQuery.browser.msie && jQuery.browser.version < 7)) { // take away IE6
		$("#TB_window").css({marginTop: '-' + parseInt((seat_hndl.act_height / 2),10) + 'px'});
//     }
  }, // end function position
  
  
  remove: function () {


	$("#TB_closeWindowButton").unbind("click");
	$("#TB_window").fadeOut("fast",function(){$('#TB_window,#TB_overlay,#TB_HideSelect').trigger("unload").unbind().remove();});
	$("#TB_load").remove();
	if (typeof document.body.style.maxHeight == "undefined") {//if IE 6
		$("body","html").css({height: "auto", width: "auto"});
		$("html").css("overflow","");
	}
//	document.onkeydown = "";
//	document.onkeyup = "";
	return false;
  } // end function remove
  
} // end var seat_hndl


	  


