(function($) {
	$.fn.Disposable = function(cln) {
		return this.each(function() {
			var el = this;
			if (!el.dispose) {
				el.dispose = cleanup; // will be called by
						    // Microsoft for cleanup
				$(window).bind("unload", cleanup);
			}
			function cleanup() {
				if (!el)
					return;
				$(el).unbind();
				$(window).unbind("unload", cleanup);
				el.dispose = null;
				el = null;
			};
		});
	};
})(jQuery);



var sPath = window.location.pathname;
var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);

$(document).ready(function(){
  inputtext_focusblur();
});	

function inputtext_focusblur(){
   $('input[type="text"]').focus(function() {
  	        if (!$(this).attr("readonly")) {	
     		$(this).removeClass("textblur").addClass("textfocus");
//  		    if (this.value == this.defaultValue){ 
//  		    	this.value = '';		}
		    if(this.value != this.defaultValue){
   			    this.select();}
			}	
  		});
  	$('input[type="text"]').blur(function() {
  	        if (!($(this).attr("readonly"))) {
  			  $(this).removeClass("textfocus").addClass("textblur");
  		      if ($.trim(this.value) == ''){
  	    	  this.value = (this.defaultValue ? this.defaultValue : '');
			  }
		   }
  	});
}

function  input_varmi(xattr,xstart,xvalue) {
    var xreturn = '0';
        $("input["+xattr+"^='"+xstart+"']").each(function(index) {
         var xid = $(this).val();
         if (xid == xvalue)  xreturn = '1';
       });
 return xreturn;
}

function  input_varyoket(xattr,xstart,xvalue,xseviye) {
    var xthis;
        $("input["+xattr+"^='"+xstart+"']").each(function(index) {
         var xid = $(this).val();
         if (xid == xvalue && xseviye == '1' )  xthis = $(this).parent();
         if (xid == xvalue && xseviye == '2' )  xthis = $(this).parent().parent();
       });
 return xthis;
}

function show_dialog(xlink, xtitle, xwidth, xheight){

var xh = $(window).height()*90/100;
var xw = $(window).width()*90/100;

if (parseInt(xheight) > parseInt(xh)) xheight = xh;
if (parseInt(xwidth) > parseInt(xw)) xwidth = xw;

var yhtml =jQuery.trim(xlink);

if (yhtml.indexOf("link:") != -1) 
		  yhtml = $.ajax({
		                 url: (yhtml.substring(5)+"?rnd="+Random_Number()),
		                 async: false
		                 }).responseText;
 
   $('#basic-modal-content').html(yhtml);	
   if (xtitle.length>3) $('#dialog_title').html(xtitle);	
   $('#basic-modal-content').modal({
   						containerCss:{
										height:xheight,
										width:xwidth},   
   						onClose: function (dialog) {
											dialog.container.hide('slow', function () {
												dialog.overlay.slideUp('slow', function () {
													$.modal.close();
												});
										});}									
	});

								

}

function  get_test(xurl) {
var yhtml = $.ajax({url: xurl,async: false, timeout: 10000}).responseText.replace(/\n/g,'');
alert(yhtml);
}
function  get_testex(xurl,xform) {
alert($(xform).serialize());
   $.post(xurl, $(xform).serialize(),
       function(data){
	    var yhtml = jQuery.trim(data).replace(/\n/g,'');
            yhtml = yhtml.replace('<script language="JavaScript">', '');
            yhtml = yhtml.replace("<script>", "");
	    yhtml = yhtml.replace("</script>", "");
           alert(yhtml);
	  });
}

function  ajax_getpost(xtype, xurl,xform,xasync){
    var yreturn;
          $.ajax({
            type: xtype,
            url: xurl,
            async: xasync,
            data: $(xform).serialize(),
            dataType: "html",
            success: function(data) {yreturn = data;}
          });
  return(yreturn);
}


function  get_message(xurl) {
var yhtml = $.ajax({url: xurl,async: false, timeout: 10000}).responseText.replace(/\n/g,'');
alert(yhtml);
}

function  object_link(xobj,xurl) {
alert(xurl);
 var yhtml = $.ajax({url: xurl,async: false, timeout: 10000}).responseText.replace(/\n/g,'');
 $(xobj).html(yhtml);
}

function  object_html(xobj,xhtml) {
   $(xobj).html(xhtml.replace(/\n/g,''));
}

function  get_ajax(xurl,xasync,xtype,xobj) {

var yhtml = $.ajax({
	          url: xurl,
                  async: xasync,
		  timeout: 10000,
                  success: function(data){
	              var yhtml = jQuery.trim(data);
                      if (yhtml.indexOf("<script>") > -1 && yhtml.indexOf("<script>") < 3 && yhtml.indexOf("<script>") > 0 ) {
                           yhtml = yhtml.replace("<script>", "");
                           yhtml = yhtml.replace("</script>", "");
                           setTimeout(yhtml, 100);
                         }else{
                          if (xtype == "object")  $(xobj).html(yhtml);
                          if (xtype == "script")  setTimeout(yhtml, 100);
                       }
                  }
	              });
}		 

function  get_post(xurl,xform,xtype,xobj){
   $.post(xurl, $(xform).serialize(), 
       function(data){
	    var yhtml = jQuery.trim(data).replace(/\n/g,'');
		if (xtype != "script" && yhtml.indexOf("<script>") < 3 && yhtml.indexOf("<script>") > 0  ) { 
		   yhtml = yhtml.replace("<script>", "");
		   yhtml = yhtml.replace("</script>", "");
		   setTimeout(yhtml, 100);
		 }else{ 
 	      if (xtype == "object")  $(xobj).html(yhtml);		
	      if (xtype == "script")  setTimeout(yhtml, 100);
		 } 
	  });

}

function  get_runscript(xurl,xform){

   $.post(xurl, $(xform).serialize(),
       function(data){
	    var yhtml = jQuery.trim(data).replace(/\n/g,'');
            yhtml = yhtml.replace('<script language="JavaScript">', '');
            yhtml = yhtml.replace("<script>", "");
	    yhtml = yhtml.replace("</script>", "");
           setTimeout(yhtml, 100);
	  });

}

function  get_postscript(xurl,xform){
   $.post(xurl, $(xform).serialize(),
       function(data){
	    var yhtml = jQuery.trim(data).replace(/\n/g,'');
           setTimeout(yhtml, 100);
	  });
}


function resetForm(id) {
	$('#'+id).each(function(){
	        this.reset();
	});
}

function Random_Number(){
 return(Math.random().toString().substring(6));
}

function center_width(){
    return $(window).width();
}
function center_height(){
    return $(window).height();
}

function ReplaceAll(Source,stringToFind,stringToReplace){
  var temp = Source;
  var index = temp.indexOf(stringToFind);
   while(index != -1){
     temp = temp.replace(stringToFind,stringToReplace);
     index = temp.indexOf(stringToFind);
   }
 return temp;
}

