// JavaScript Document
 
function callFloat(name,data,callback){

     window_loading(1);
     var appendata='';

     if( data != null )
        appendata = "&"+data;
     
     var id_name = name +""+ parseInt(Math.random()*100);
    
     $('<div id="dlg_'+ id_name +'" ></div>').insertAfter('body').load( base_index() +'float/'+ name +'?dlg_id=dlg_'+ id_name + ''+ appendata ,
         function(){
             window_loading(0);
            if( callback != null ) callback();
         }
     );

}

var windowMessage;
function window_message(html,callback,title){
        if(title==null){
            title = 'Message';
        }
 		if( !windowMessage ){
				 windowMessage = $('<div ></div>').insertAfter('body');
 				 $(windowMessage).dialog({
					width: 410,
					height: 200,
					modal: true,
					cache: true,
 					title: title,
					buttons:{
						'Close':function(){
							$(this).dialog('close');									
						}
					},
					close: function(){
						if( callback != null )
							callback();
 					}
				 });
		}
 		$(windowMessage).html(html);
		$(windowMessage).dialog('open');
}
function window_error(html,callback){
    window_message("<div class='fcRed'>"+html+"</div>",callback,'Error'); 
}
var confirmMessage;
function window_confirm(html,yes_callback,no_callback,close_callback){

 		if( !confirmMessage ){
				 confirmMessage = $('<div ></div>').insertAfter('body');
 				 $(confirmMessage).dialog({
					width: 420,
					height: 180,
					modal: true,
					cache: true,
 					title: 'Confirm',
					buttons: { 	
								 'No':function(){
									 
									 	if( no_callback != null )
 											no_callback();
											
 								 		$(this).dialog('close');
								 },
								 'Yes':function(){
								 
									 if( yes_callback != null )
 										yes_callback();
									 
									 $(this).dialog('close');						
								 }
						},
					close: function(){
							if( close_callback != null )
								close_callback();
 						}
						
				 });
		
		}
 		$(confirmMessage).html(html);
		$(confirmMessage).dialog('open');

}

var loadingMessage;
function window_request(flag){

 		if( !loadingMessage ){
				 loadingMessage = $('<div ><br /><img src="/images/loader.gif" style="padding-left:20px;vertical-align:middle"> <strong>Sending Request</strong></div>').insertAfter('body');
 				 $(loadingMessage).dialog({
					width: 260,
					height: 155,
					modal: true,
					cache: true,
 					title: 'Please wait...',
					buttons: {
							 'Close':function(){
									$(this).dialog('close');
							 }
						},
					close: function(){  }
				 });
		
		}

		if( flag ){
  			$(loadingMessage).dialog('open');
		}else
 			$(loadingMessage).dialog('close');

}
 
function window_loading(flag){

		if( flag ){ 
 			$('#bottomBar').show();
		    $("#coverpage").show();
		}else{ 
 			$('#bottomBar').hide();
			$("#coverpage").hide();
		}
	
}

function window_pop(name,url){
	eval('var '+ name+'; if(  '+ name+' ){$( '+ name+').dialog(\'destroy\'); $( '+ name+').remove();} '+ name+' = $(\'<div title="Make New Album"></div>\').insertAfter(\'body\'); $('+ name+').load(\'load.php?pop='+ name+'&dlg_id='+ name+''+url+'\',function(){  $('+ name+').dialog(\'open\')  });' );
}
 
function form_silentv2(element,validate,callback){
 
    $("input[type=submit]",element).click(function(){
 
            if( validate() == false ){return false;}

         	var rand = parseInt( Math.random()*10000 );
         	var frame_id = 'hiddenform_'+ rand; 
        	var formhide = $('<div style="display:none" ><iframe id="'+ frame_id +'"   name="'+ frame_id +'"  ></iframe></div>').insertAfter('body'); 

        	element.attr('target',frame_id);
              
            $('iframe',formhide).load(function(){
 
        		window_loading(0);
        		callback(this)
               $(this).unbind('load');
    		   $(formhide).remove();
    	  
            });
 
    });

}

 
function form_silent(element,callback,cancell,opt){

 	var rand = parseInt( Math.random()*10000 );
 	//var frame_id = 'hiddenform_'+ rand;
    var frame_id = 'hidden_iframe';

	//var formhide = $('<div style="display:none" ><iframe id="'+ frame_id +'"   name="'+ frame_id +'"  ></iframe></div>').insertAfter('body'); 
    //var formhide = $('<div style="display:none" ><iframe id="hidden_iframe"   name="hidden_iframe"  ></iframe></div>').insertAfter('body'); 

    _opt = {nosharp:false}; 
    _opt = $.extend({},_opt,opt);  
    
    _element =  '#'+element;  

    element =  $(_element); 
	element.attr('target',frame_id);
 
    setTimeout(function(){
       
        is_btn_exist = 0;
        $("input[type=submit]",element).each(function(){
            $(this).trigger('click');
            is_btn_exist = 1;
        })

        if(is_btn_exist==0){
            element.submit();
        }
        
	},500);

	var t_cancell = setTimeout(function(){
		$("#btn_opcancel").show();
	},10000);

	window_loading(1);

 	$('#'+frame_id).load(function(){

		clearTimeout(t_cancell);
		window_loading(0);
		callback(this);

		$(this).unbind('load');
		//$(formhide).remove();
		//loadingMessage=null;

	});

    //$('#btn_opcancel').click('load');
    $("#btn_opcancel").click(function(){  
            window_loading(0);
            if( cancell != null ) cancell() 
     });
     
} 
 
function img_hover_fx(){ 
     $('.product_photo').hover(function(){
			$(this).css('border-color','#A7FF6C');
	 },function(){
			$(this).css('border-color','#CCC');
	 });

     $('.product_photo_s').hover(function(){
			$(this).css('border-color','#A7FF6C');
	 },function(){
			$(this).css('border-color','');
	 });
}

function get_date_now(){
    
    var currentTime = new Date();
    var m   = currentTime.getMonth();
    var d     = currentTime.getDate();
    var y    = currentTime.getFullYear();
    var months = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];

    now     = months[m] + " " + d + ", " + y; 
    return now;
}

function reload_pagination(id){
    
    $(".page_nav",id).click(function(){
        window_loading(1);
        $(id).parent().load( $(this).attr('href'),function(){
            window_loading(0);
        });
    	return false;
    });
    
}

function get_time_now(){
 
    var currentTime = new Date()
    var hours = currentTime.getHours()
    var minutes = currentTime.getMinutes()
    now = '';
    
    if (minutes < 10){
        minutes = "0" + minutes
    }
    now = hours + ":" + minutes + " "; 

    if(hours > 11){
        now = now+"pm";
    } else {
        now = now+"am";
    }
     return now;
    
} 

function show_cw_balance(){
    
    if(cashwallet_balance()!=false){
        $(".cashwallet_balance").html(cashwallet_balance());
        return;
    }
    $.ajax({
        url: base_index()+"portlet/cw_balance",
        success:function(response){
             g_cw_balance = parseFloat(response);
             $(".cashwallet_balance").html(g_cw_balance);
        }
    })
    
}
 
function reload_profile_menus(){
    $("#profilemenus").load(base_index()+"portlet/profile_menus")    
}
