LOADING_BOX = null;
var LoadingBox = new Class({
	initialize: function() {
		this.bound = {			
			"winresize": this.resize.bind(this),
			"close": this.close.bind(this)
		};	
	},
	enableClick: function(){
		if(this.coverdiv)this.coverdiv.addEvent('click',this.bound.close);
	},
	disableClick: function(){
		if(this.coverdiv)this.coverdiv.removeEvents('click');
		window.removeEvents('resize');
	},
	close: function(){	
		if(this.coverdiv != null) {
			this.coverdiv.setStyle("display", "none");
			this.shield(false);			
		}
		this.disableClick();
		if(LIGHT_BOX)LIGHT_BOX.hidemodal();
		if(CONFIRM_BOX)CONFIRM_BOX.hidemodal();
		if(newsfeedLightbox)newsfeedLightbox.hidemodal();
	},
	loading: function() {
		if(this.coverdiv == null) {
			this.coverdiv=new Element('div');
			this.coverdiv.setStyles({
				'z-index':100,
				'background-color': '#1b3766',
				'position':'absolute'
			});							
			this.coverdiv.setOpacity(0.5);
			this.coverdiv.injectInside(document.body);
		}
		this.coverdiv.setStyles({
			"display": "block",
			width:getWidth(),
			height:getHeight(),
			top:Window.getScrollTop(),
			left:Window.getScrollLeft()	
		});
		window.addEvent('resize', this.bound.winresize).addEvent('scroll', this.bound.winresize);
		this.shield(true);		
	},	
	
	shield: function(open){ //hide controls such as select for IE
		var elements = $A($$('object'));
		elements.extend($$(window.ActiveXObject ? 'select' : 'embed'));
		elements.each(function(el){ el.style.visibility = open ? 'hidden' : ''; });	
	},
		
	resize: function(){	
	this.browserheight = (window.navigator.appName == "Opera") ? window.innerHeight : Window.getHeight();
	if(this.coverdiv)	{	
		this.coverdiv.setStyles({
			top: Window.getScrollTop()+'px',
			left: Window.getScrollLeft()+'px', 
			height: this.browserheight+'px',
			width: Window.getWidth()+'px'
		});
	}
}
});

//Lightbox******************************************************START
LIGHT_BOX = null
var Lightbox = new Class({
		options: {
		htmlcont:'',
		minwidth:50,
		minheight:50,
		maxwidth:380,
		maxheight:350,
		left: 0,
		top: 0
	},
	initialize: function(options){				
		if(options){
			this.setOptions(options);
		}		
		this.lbox=null;
		this.content=null;
	},	
	empty: function(){
		if(this.lbox){
			this.lbox.remove();
		}
		this.lbox=null;
		this.content=null;
	},
	hidemodal: function(){		
		if(this.lbox) {
			this.lbox.setStyle('visibility','hidden');
			this.lbox.setStyle('display','none');
		}
		if(this.content) {
			this.content.setStyle('visibility','hidden');
			this.content.setStyle('display','none');
		}
	},
	generatemodal: function(text, isDom){
		if(!this.lbox){
			this.lbox=new Element('div');
			this.lbox.injectInside(document.body);
			var btnclose=new Element('img');
			btnclose.injectInside(this.lbox);
			this.lbox.addClass('lbox');
			btnclose.setProperty('src','../page/images/lightbox/close.jpg').setStyles({float:'right',cursor:'pointer'});			
			btnclose.addEvent('click',LOADING_BOX.bound.close);			
		}	
		this.browserheight = (window.navigator.appName == "Opera") ? window.innerHeight : Window.getHeight();
		this.lbox.setStyles({			
			width:this.options.maxwidth,
			height:this.options.maxheight,
			'left': (Window.getWidth()/2+Window.getScrollLeft())+'px',
			'top': (this.browserheight/2+Window.getScrollTop())+'px',
			'margin-left':-this.options.maxwidth/2,
			'margin-top':-this.options.maxheight/2,
			'visibility': 'hidden',
			'display': 'none'
		});
		if(!this.content){
			this.content=new Element('div');
			this.content.injectInside(this.lbox);
			this.content.setStyles({background:'#fff'});			
		}
		this.content.empty();		
		if(isDom){			
			text.injectInside(this.content);
		}else{
			this.content.setHTML(text);
		}
		this.content.setStyle('visibility','hidden');
		this.content.setStyle('display','none');
	},
	showmodal: function(text, isDom){		
		this.generatemodal(text, isDom);
		if(this.beforeFn){
			var retval = this.beforeFn.bind(this, text)();
		}
		this.beforeFn = null;
		if(typeof(retval) == 'undefined' || (typeof(retval) != 'undefined' && retval)){
			if(LOADING_BOX){
				LOADING_BOX.loading();
				LOADING_BOX.enableClick();
			}
			if(this.lbox) {
				this.lbox.setStyle('visibility','visible');
				this.lbox.setStyle('display','block');
			}			
			if(this.content) {
				this.content.setStyle('visibility','visible');
				this.content.setStyle('display','block');
			}			
		}else{
			if(LOADING_BOX)LOADING_BOX.close();
		}
	},
	bindbeforedisplay: function(fn){
		this.beforeFn = fn;
	}
});

Lightbox.implement(new Options);

CONFIRM_BOX = null;

function generateConfirmBox(result, schoolId){
    LOADING_BOX.loading();
    if(CONFIRM_BOX == null){
      CONFIRM_BOX = new Lightbox({maxwidth:380,maxheight:90});
    }
    var content = new Element("div");
    CONFIRM_BOX.showmodal(content, true);
    
    // insert description.
    var description = new Element("div");    
    description.injectInside(content);
    description.setText("Remove this college from Your College List.");
    description.addClass("word");
    
    // insert confirm button.
    var confirmBtn = new Element("div");
    confirmBtn.injectInside(content);
    confirmBtn.addClass("confirmbtns");
    
    var delOneImg = new Element("img");
    if(result){
    	delOneImg.setProperty("src", '../page/images/admissions/confirm_delone.gif');
    	delOneImg.setProperty("title","REMOVE FROM ONE LIST");
    	delOneImg.setStyle("width", "134px");
    }else{
    	delOneImg.setProperty("src", '../page/images/admissions/confirm_delfromlist.gif');
    	delOneImg.setProperty("title","REMOVE FROM LIST");
    	delOneImg.setStyle("width", "111px");
    }    
    delOneImg.setStyle("height", "18px");
    delOneImg.addEvent("click", function(){LOADING_BOX.close();TRACKER_TICKER_SEARCH_INSTANCE.deleteOperation(schoolId, false);})
    delOneImg.injectInside(confirmBtn); 
    
    if(result){
      var delBothImg = new Element("img");
      delBothImg.setProperty("title","REMOVE FROM BOTH LISTS");
      delBothImg.setStyle("width", "140px");
      delBothImg.setStyle("height", "18px");
      delBothImg.setProperty("src", '../page/images/admissions/confirm_delboth.gif');
      delBothImg.addEvent("click", function(){LOADING_BOX.close();TRACKER_TICKER_SEARCH_INSTANCE.deleteOperation(schoolId, true);})
      delBothImg.injectInside(confirmBtn);
      
    }
    var cancelImg = new Element("img");
    cancelImg.setProperty("src", '../page/images/admissions/confirm_cancel.gif');
    cancelImg.setStyle("width", "56px");
    cancelImg.setStyle("height", "18px");
    cancelImg.setProperty("title","CANCEL");
    cancelImg.addEvent("click", LOADING_BOX.bound.close)
    cancelImg.injectInside(confirmBtn);    
}

function generateConfirmBoxForProfileForm(result, schoolId){
    LOADING_BOX.loading();
    if(CONFIRM_BOX == null){
      CONFIRM_BOX = new Lightbox({maxwidth:380,maxheight:90});
    }
    var content = new Element("div");
    CONFIRM_BOX.showmodal(content, true);
    
    var description = new Element("div");
    description.injectInside(content);
    description.setText("Remove this college from Your College List.");
    description.addClass("word");
    
    var confirmBtn = new Element("div");
    confirmBtn.injectInside(content);
    confirmBtn.addClass("confirmbtns");
    
    var delOneImg = new Element("img");    
    if(result){
    	delOneImg.setProperty("src", '../page/images/admissions/confirm_delone.gif');
    	delOneImg.setProperty("title","REMOVE FROM ONE LIST");
    	delOneImg.setStyle("width", "134px");
    }else{
    	delOneImg.setProperty("src", '../page/images/admissions/confirm_delfromlist.gif');
    	delOneImg.setProperty("title","REMOVE FROM LIST");
    	delOneImg.setStyle("width", "111px");
    }
    delOneImg.setStyle("height", "18px");
    delOneImg.addEvent("click", function(){
    	LOADING_BOX.close();
    	_hbPageView('Remove+College','/tracker/my_profile');
    	AdmissionProfileService.deleteOperation(schoolId, false, 
    		dwrCallback(null, {callback: function(result){window.document.forms[0].action = "../admission_survey/survey_form.jhtml?method=redisplayForDeletion"; window.document.forms[0].submit();}.bind(this)})
    	);
    });
    delOneImg.injectInside(confirmBtn); 
    if(result){
      var delBothImg = new Element("img");
      delBothImg.setProperty("title","REMOVE FROM BOTH LISTS");
      delBothImg.setStyle("width", "140px");
      delBothImg.setStyle("height", "18px");
      delBothImg.setProperty("src", '../page/images/admissions/confirm_delboth.gif');
      delBothImg.addEvent("click", function(){
      	LOADING_BOX.close();
      	_hbPageView('Remove+College','/tracker/my_profile');
      	AdmissionProfileService.deleteOperation(schoolId, true, 
    		dwrCallback(null, {callback: function(result){window.document.forms[0].action = "../admission_survey/survey_form.jhtml?method=redisplayForDeletion"; window.document.forms[0].submit();}.bind(this)})
    	);
    });
		delBothImg.injectInside(confirmBtn);      
    }
    var cancelImg = new Element("img");
    cancelImg.setProperty("title","CANCEL");
    cancelImg.setStyle("width", "56px");
    cancelImg.setStyle("height", "18px");
    cancelImg.setProperty("src", '../page/images/admissions/confirm_cancel.gif');
    cancelImg.addEvent("click", LOADING_BOX.bound.close)
    cancelImg.injectInside(confirmBtn); 
}

window.addEvent('domready', function(){
	if(LOADING_BOX == null) {
		LOADING_BOX = new LoadingBox();
	}
	if(LIGHT_BOX == null) {
		LIGHT_BOX = new Lightbox();
	}
});
//Lightbox******************************************************END


//NewsfeedLightbox******************************************************START
newsfeedLightbox = null;
var NewsfeedLightbox = Lightbox.extend({
	generatemodal: function(text, isDom){
		if(!this.lbox){
			this.lbox=new Element('div');
			this.lbox.injectInside(document.body);
			var btnclose=new Element('img');
			btnclose.injectInside(this.lbox);
			this.lbox.addClass('lbox');
			btnclose.setProperty('src','../page/images/lightbox/close.jpg').setStyles({float:'right',cursor:'pointer'});			
			btnclose.addEvent('click',LOADING_BOX.bound.close);			
		}	
		this.browserheight = (window.navigator.appName == "Opera") ? window.innerHeight : Window.getHeight();
		this.lbox.setStyles({			
			width:this.options.maxwidth,
			height:this.options.maxheight,
			'left': this.options.left+'px',
			'top': this.options.top+'px',
			'visibility': 'hidden',
			'display': 'none'
		});
		if(!this.content){
			this.content=new Element('div');
			this.content.injectInside(this.lbox);
			this.content.setStyles({background:'#fff', color:'#a60b06', 'font-size':'11px', 'padding-left':'10px', 'padding-top':'7px', 'padding-right':'10px', 'padding-bottom':'9px', 'line-height':'13px'});			
		}
		this.content.empty();		
		if(isDom){			
			text.injectInside(this.content);
		}else{
			this.content.setHTML(text);
		}
		this.content.setStyle('visibility','hidden');
		this.content.setStyle('display','none');
	}
});
NewsfeedLightbox.implement(new Options);
//NewsfeedLightbox******************************************************END