(function() {

// Localize jQuery variable
var jQuery;

/******** Load jQuery if not present *********/
var host = window.location.hostname;

if(host == 'www.bhumi.ngo'){
	
	if (window.jQuery === undefined) {	
		var script_tag = document.createElement('script');
	    script_tag.setAttribute("type","text/javascript");
	    script_tag.setAttribute("src",
	        "https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js");
	    if (script_tag.readyState) {
	      script_tag.onreadystatechange = function () { // For old versions of IE
	          if (this.readyState == 'complete' || this.readyState == 'loaded') {
	              scriptLoadHandler();
	          }
	      };
	    } else {
	      script_tag.onload = scriptLoadHandler;
	    }
	    // Try to find the head, otherwise default to the documentElement
	    (document.getElementsByTagName("head")[0] || document.documentElement).appendChild(script_tag);
	} else {
	    // The jQuery version on the window is the one we want to use
	    jQuery = window.jQuery;
	    main();
	}
}
else{
	if (window.jQuery === undefined || window.jQuery.fn.jquery !== '1.4.2.0') {
		var script_tag = document.createElement('script');
	    script_tag.setAttribute("type","text/javascript");
	    script_tag.setAttribute("src",
	        "https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js");
  
	    if (script_tag.readyState) {
	      script_tag.onreadystatechange = function () { // For old versions of IE
	          if (this.readyState == 'complete' || this.readyState == 'loaded') {
	              scriptLoadHandler();
	          }
	      };
	    } else {
	      script_tag.onload = scriptLoadHandler;
	    }
	    // Try to find the head, otherwise default to the documentElement
	    (document.getElementsByTagName("head")[0] || document.documentElement).appendChild(script_tag);
	} else {
	    // The jQuery version on the window is the one we want to use
	    jQuery = window.jQuery;
	    main();
	}
		
}

    

/******** Called once jQuery has loaded ******/
function scriptLoadHandler() {
    // Restore $ and window.jQuery to their previous values and store the
    // new jQuery in our local jQuery variable
    jQuery = window.jQuery.noConflict(true);
    // Call our main function
    main(); 
}

/******** Our main function ********/
function main() { 

    jQuery(document).ready(function($) {
        /******* Load CSS *******/       
	jQuery = jQuery.noConflict(true);
	    
	   var css_link = $("<link>", { 
            rel: "stylesheet", 
            type: "text/css", 
            href: "https://danamojo.org/dm/css/widget_style.css" 
        });
        css_link.appendTo('head');   
        
        var js_link = $("<script>", { 
        	type: "text/javascript",
            src: "https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js" 
        });
        js_link.appendTo('head');         
		
		var js_link_bs = $("<script>", { 
        	type: "text/javascript",
            src: "https://danamojo.org/dm/js/bootstrap.min.js" 
        });
        js_link_bs.appendTo('head'); 
        
        if(host == 'www.ideafoundation.org.in'){
	        var js1_link_bs = $("<script>", { 
	        	type: "text/javascript",
	            src: "http://cdnjs.cloudflare.com/ajax/libs/jquery-easing/1.3/jquery.easing.min.js" 
	        });
	        js1_link_bs.appendTo('head'); 
        }
        var uandi = document.referrer;
        if(uandi == 'http://uandi.org.in/' || host == 'uandi.strikingly.com'){
	        var js1_link_bs = $("<script>", { 
	        	type: "text/javascript",
	            src: "http://code.jquery.com/ui/1.10.3/jquery-ui.js" 
	        });
	        js1_link_bs.appendTo('head'); 
	        
        }
		
		 if(host == 'www.tamassociety.com'){
	        var js1_link_bs = $("<script>", { 
	        	type: "text/javascript",
	            src: "https://code.jquery.com/jquery-1.11.3.js" 
	        });
	        
	        js1_link_bs.appendTo('head'); 
	        
		        var js_link_bs = $("<script>", { 
	        	type: "text/javascript",
	            src: "https://danamojo.org/dm/js/bootstrap.min.js" 
	        });
	        js_link_bs.appendTo('head'); 
	        
        }
        
        if(host == 'lks.co.in'){
	        var js_link_bs = $("<script>", { 
	        	type: "text/javascript",
	            src: "https://code.jquery.com/jquery-1.11.3.js" 
	        });	        
	        js_link_bs.appendTo('head'); 
        }
        
     
        if(host == 'prastutee.org'){       
        	
	        var js_link_bs = $("<script>", { 
	        	type: "text/javascript",
	            src: "http://prastutee.org/js/jquery-migrate.min.js" 
	        });	        
	        js_link_bs.appendTo('head');
	        
	        var js_link_agewell = $("<script>", { 
	        	type: "text/javascript",
	            src: "http://cdnjs.cloudflare.com/ajax/libs/jquery-easing/1.3/jquery.easing.min.js" 
	        });	        
	        js_link_agewell.appendTo('head');
	        
        }
        
        if(host == 'www.agewellfoundation.org'){
	        var js_link_bs = $("<script>", { 
	        	type: "text/javascript",
	            src: "http://www.agewellfoundation.org/wp-includes/js/jquery/jquery-migrate.min.js?ver=1.2.1" 
	        });	        
	        js_link_bs.appendTo('head');
	         
	        var js_link_agewell = $("<script>", { 
	        	type: "text/javascript",
	            src: "http://cdnjs.cloudflare.com/ajax/libs/jquery-easing/1.3/jquery.easing.min.js" 
	        });	        
	        js_link_agewell.appendTo('head');
        }
        
        if(host == 'muskanfoundation.org.in'){        	
        	
	        var js_link_bs = $("<script>", { 
	        	type: "text/javascript",
	            src: "http://muskanfoundation.org.in/wp-includes/js/jquery/jquery-migrate.min.js?ver=1.2.1" 
	        });	        
	        js_link_bs.appendTo('head');
	        
	        var js_link_muskan = $("<script>", { 
	        	type: "text/javascript",
	            src: "https://cdnjs.cloudflare.com/ajax/libs/jquery-easing/1.4.1/jquery.easing.js" 
	        });	        
	        js_link_muskan.appendTo('head');
        }
        
		var sw = parseInt(window.screen.width);        
        var ngoId = $('#ngoContentContainer').attr('iNGOId');        
        var dispalyType = $('#ngoContentContainer').attr('oDisplay');
        
         var sourceType = $('#ngoContentContainer').attr('sourceType');
         if(typeof sourceType === 'undefined')
			sourceType = 0;//website
        else
        	sourceType = 2;//branded page
        
        var products = $('#ngoContentContainer').attr('iProductId');
        if(typeof products === 'undefined'){
			products = '';
		}
		
		/*var retryMail = $('#ngoContentContainer').attr('retryMail');
        if(typeof retryMail === 'undefined'){
			retryMail = '';
		}*/
		
		var refererUrl = (window.location != window.parent.location) ? document.referrer: document.location;	
		var iframeUrl = (window.location != window.parent.location) ? document.referrer: '';
		
		var ifr_url = iframeUrl.split('/');
		var a = ifr_url.indexOf("ngo"); 
		var b = ifr_url.indexOf("trafficsignal"); 
 		if(a>0 || b>0){
			iframeUrl = '';
		}
		//var iframeUrl = document.referrer;
		
        if(typeof iframeUrl === 'undefined' || iframeUrl == ''){      	
			iframeUrl = '';
		}else{
			
			sourceType = 3;
		}		       
		
        if(dispalyType == 'button'){
        	var buttonImage = $('#ngoContentContainer').attr('iCustomButtonImage');
        	if(buttonImage == 'yes'){				
				$('#dmScriptContainer a').attr("onclick", "donationProductsOverlay();");
			}
			else{
							
	        	//$('#dmScriptContainer').html('<a href="#" onclick="donationProductsOverlay();"><img src="https://danamojo.org/dm/images/donate_btn_powered.png" alt="donate now"></a>');
				$('#dmScriptContainer').html('<a href="#" onclick="donationProductsOverlay();"><img src="images/donate_btn.png" alt="donate now"></a>'); 
		    }
		    
		   var url = "https://danamojo.org/dm/widget/productoverlay?ngoId="+ngoId+"&products="+products+"&sw="+sw+"&sourceType=1&refererUrl="+refererUrl;
			$.get(url, function(data, status){
		       $('#ngoContentContainer').html(data);
		       $("#loading_div").hide(); 
		    });
		    $("#loading_div").hide(); 
		    $('#dmScriptContainer').show();		
		}else{// if(dispalyType == 'product'){
					
			var url = "https://danamojo.org/dm/widget/index?ngoId="+ngoId+"&products="+products+"&sw="+sw+"&sourceType="+sourceType+"&refererUrl="+refererUrl;        
	        $.get(url, function(data, status){
		        $('#ngoContentContainer').html(data);
		        $("#loading_div").hide(); 	
		              
		    });
		    $("#loading_div").hide();
		}
		/*else{
			document.getElementById("ngoContentContainer").innerHTML="<center> <p style='color:#a94442;'>Please check your oDisplay type on script.</p></center>";
			$("#loading_div").hide(); 
		}*/
        
    });
}

})(); // We call our anonymous function immediately


function donationProductsOverlay(){	
	$('#productoverlay').modal({
	  keyboard: true,
	  backdrop:false
    });
    $("#loading_div").hide(); 
    
    $("#_navigation_state").val("0");
	$("#_payment_option").val("1");
	$("#_chequeDraftBankName").val("");
	$("#_chequeDraftNumber").val("");
	$("#_chequeDraftDate").val("");
	$("#_chkbxChequePickup").val("");
	$("#_trackingNumber").val("");
    
        
    $("#donor-data").removeClass("active");    
    $("#donor_data").removeClass("active");
	$("#donor-data").addClass("disabled"); 
	
	$("#payment-options").removeClass('active');
	$("#payment_options").removeClass('active');
	$("#payment-options").addClass('disabled');
	
	
	$("#confirmation-tab").removeClass('active');
	$("#confirmation").removeClass('active');
	$("#confirmation-tab").addClass('disabled');
	
	$("#product-list").removeClass("disabled"); 
    $("#product-list").addClass("active");
   	$("#product_list").addClass("active"); 
    
    $("#payment_options").hide();
	$("#donor_data").hide();
	$("#confirmation").hide();
	$("#product_list").show();  
	$("#customDonationInfoId").val("");    
	
	$("#product-list a").removeAttr("style");
          
}