/*
Power By CHIU 2010-05-29

Parameter:
1.  URL
2.  Postion(1 = center, 2 = left, 3 = right)
3.  Iframe Width
4.  Iframe Height
5.  Top            (Default = 0px)
6.  Scroll         (1 = Yes, 0 = No)
7.  BG Color       (0 = No BG, 1 = Black, or Type any color)
8.  BG_Effect      (1 = Yes, 0 = No)
9.  BG_Close       (1 = Yes, 0 = No)
10. Lang           (en = English, tc = Tchinese, sc= simple chinese, Default = yser define)

Sample:

ShowFrameBox(
 Url       = 'http://58.64.135.44/',
 Position  = 1,
 Width     = 600,
 Height    = 400,
 Top       = 10,
 Scroll    = 0,
 BG_Color  = 1,
 BG_Effect = 1,
 BG_Close  = 1,
 Lang      = 'en');
 
 );


// 2011-03-24
Add function slideout(div_id , time)
*/

function ShowFrameBox(Url, Postion, Width, Height, Top, Scroll, BG_Color, BG_Effect, BG_Close, Lang){
  /************Init***************/
   BG_Height = WindowHeight();
   BG_Width  = WindowWidth();
  /*********** End Init **********/


  var scroll_top = $(document).scrollTop();
  //alert(scroll_top);

  /**********Define***********/
  if(Url == "")
    Url = "http://www.google.com";

  if(Postion == "1"){// center
    Left = (parseInt(BG_Width) - Width)/2;
  }
  else if(Postion == "2"){//left
    Top  = parseInt(BG_Height) - Height - 70;
    Left = parseInt(BG_Width) - Width - 20;
  }
  else if(Postion == "3"){//right
    Top  = parseInt(BG_Height) - Height - 70;
    Left = "20";
  }
  else{//default center
     Left = (parseInt(BG_Width) - Width)/2;
 }

 if(Scroll == "1")
  Scroll = "Yes";
 else 
  Scroll = "No";


 if(BG_Effect == "1")
  BG_Effect =true;
else
  BG_Effect =false;


if(BG_Color == "1")
  BG_Color = "#000000";


if(BG_Close == "1")
  BG_Close =true;
else
  BG_Close =false;


if(Lang == "en")
 Close_Text = "X";
else if(Lang == "tc")
 Close_Text = "X";
else if(Lang == "sc")
 Close_Text = "X";
else if(Lang == "image")
 Close_Text = "<img src='../assets/images/close.png' width=9 height=11 title='Close' alt='Close'>";
else
 Close_Text = Lang;

/***************************/

if(Lang == "en"){
 Close_Text2 = "< Close >";}
else if(Lang == "tc"){
 Close_Text2 = "< 關閉 >";}
else if(Lang == "sc"){
 Close_Text2 = "< 关闭 >";}



 if(BG_Effect)
    $('body').append('<div id="lightbox_background"></div>');
    $('#lightbox_background')
    .css('position','absolute')
    .css('display','none')
    .css('width','100%')
    .css('height','100%')
    .css('top','0px')
    .css('left','0px')
    .css('background-color', BG_Color )
    .css('z-index','99');
 
  tmp_table  = "<table cellpadding=0 cellspacing=0 bgcolor='#333333' width=100%>";
  tmp_table += "<tr>";
  tmp_table += "<td>";
  tmp_table += "<div id='my_lightbox_drag'>&nbsp;</div>";
  tmp_table += "</td>";
  tmp_table += "<td width=10>";
  tmp_table += "<div id='my_lightbox_close'>"+ Close_Text +"</div>";
  tmp_table += "</td>";
  tmp_table += "<tr>";
  tmp_table += "</table>";
  
  //$('body').append('<div id="lightbox_container"><div id="my_lightbox_drag"></div><iframe id="FrameID" name="FrameNames" src=\"' + Url + '\" marginwidth="0" marginheight="0" frameborder="0" scrolling=' + Scroll + ' width='+ Width +' height=' + Height + ' ></iframe><div id="my_lightbox_close">'+ Close_Text +'</div></div>');
  //tIframeHtml = '<div id="lightbox_container">'+tmp_table+'<iframe id="FrameID" name="FrameNames" src=\"' + Url + '\" marginwidth="0" marginheight="0" frameborder="0" scrolling=' + Scroll + ' width='+ Width +' height=' + Height + ' ></iframe></div>';
  tIframeHtml = '<div id="lightbox_container">'+tmp_table+'<iframe id="FrameID" name="FrameNames" src=\"' + Url + '\" marginwidth="0" marginheight="0" frameborder="0" width='+ Width +' height=' + Height + ' ></iframe></div>';
  $('body').append(tIframeHtml);
  //alert(tIframeHtml);
  

  $('#lightbox_container')
  .css('position','absolute')
  .css('width', Width)
  .css('top', scroll_top + Top + 'px')
  .css('left', Left +'px')
  .css('display','none')
  .css('border','1px solid #666666')
  .css('z-index','999999')
  .css('padding','2px')
  .css("background", "#ffffff");

  $('#my_lightbox_drag')
  .css('cursor','move')
  .css('width','100%')
  .css('border','0px solid #cccccc')
  .css('padding','0px');

  $('#my_lightbox_close')
  .css('font-family','Arial')
  .css('font-weight','bold')
  .css('font-size','12px')
  .css('color','#fff')
  .css('padding-right','8px')
  .css('border','0px solid #ffffff')
  .css('cursor','pointer');


   $('#my_lightbox_close2')
  .css('font-family','Arial')
  .css('font-weight','bold')
	     .css('font-size','12px')
  .css('text-align','center')
  .css('color','#222222')
  .css('padding-top','0px')
  .css('padding-bottom','0px')
  .css('padding-right','8px')
  .css('border','0px solid #ffffff')
  .css('cursor','pointer')
  .css("background", "#D7CFDA");


  $('#lightbox_background')
    .css('opacity',0.5)
	.css('height', BG_Height + "px")
	.css('width', BG_Width+ "px").show();

  $("#lightbox_container").fadeIn();//effect

  if( $("#my_lightbox_drag").length > 0)// if exist this id
    $( "#lightbox_container" ).draggable({ handle: '#my_lightbox_drag' });

   $('#lightbox_background').click(function(){
	 if(BG_Close){
      hideLightBox();
      }
    });

	$('#my_lightbox_close, #my_lightbox_close2').click(function(){
      hideLightBox();
    });

  }// end of ShowLightBox function

 function hideLightBox(){
   $("#lightbox_background").hide();
   $("#lightbox_container").hide();
   $('#lightbox_container').remove();
 }

$(document).ready(function () {
   $(window).bind("resize", resizeWindow);
   $(window).bind("scroll", resizeWindow);
 });// end ready

 function resizeWindow(e){
   $('#lightbox_background').css('height', WindowHeight() + "px");
   $('#lightbox_background').css('width',  WindowWidth() + "px" );
 }

// end of frame box


function WindowHeight() {
	var scrollHeight,
		offsetHeight;
	// handle IE 6
	if ($.browser.msie) {
		scrollHeight = Math.max(
			document.documentElement.scrollHeight,
			document.body.scrollHeight
		);
		offsetHeight = Math.max(
			document.documentElement.offsetHeight,
			document.body.offsetHeight
		);

		if (scrollHeight < offsetHeight) {
			return $(window).height();
		} else {
			return scrollHeight ;
		}
	// handle "good" browsers
	} else {
		return $(document).height();
	}
}

 function WindowWidth() {
	var scrollWidth,
		offsetWidth;
	// handle IE 6
	if ($.browser.msie ) {
		scrollWidth = Math.max(
			document.documentElement.scrollWidth,
			document.body.scrollWidth
		);
		offsetWidth = Math.max(
			document.documentElement.offsetWidth,
			document.body.offsetWidth
		);

		if (scrollWidth < offsetWidth) {
			return $(window).width();
		} else {
			return scrollWidth;
		}
	// handle "good" browsers
	} else {
		return $(document).width();
	}
}

/**********************************************************************/
/**This function use for clear form value                            **/
/**********************************************************************/

function clear_form_elements(ele) {

    $(ele).find(':input').each(function() {
        switch(this.type) {
            case 'password':
            case 'select-multiple':
            case 'select-one':
            case 'text':
            case 'textarea':
                $(this).val('');
                break;
            case 'checkbox':
            case 'radio':
                this.checked = false;
        }
    });

}


