// JavaScript Document

function slide_show(div,name,data){
	this.div = div;
	this.className = name;
	this.cur_image = 0;
	var images = data.images;
	this.length = data.length;
	this.fps = data.fps
	this.delay = data.delay;
	slide_anim = new fx(this.div,'slide_anim',{length:this.length, fps:this.fps});
	
	this.slide_start = function(){
		if(this.cur_image == images.length){
			this.cur_image = 0;
		}else{
			this.cur_image++;
		}
		document.getElementById(this.div).innerHTML = '<img src="'+images[this.cur_image]+'" />';
		slide_anim.fade({start_opacity:0,end_opacity:100,callback:{name:this.className+".fade_out()",delay:this.delay}});
	}
	
	this.fade_out = function(){
		slide_anim.fade({start_opacity:100,end_opacity:0,callback:{name:this.className+".slide_start()",delay:0}});
	}
	
}

function progress_bar(div,name,data){
	this.className = name;
	this.div = div;
	this.progressbar_width = data.width;
	this.progressbar_max_stages = data.max_stages;
	this.completed_str = data.complete
	this.pixels_per_stage = Math.ceil(this.progressbar_width / this.progressbar_max_stages);
	this.cur_position = this.progressbar_width;
	this.end_position = 0;
	this.cur_stage = 1;
	this.bar_content = '<span id="progressStatus">Step <span id="progressStep">1</span> of '+this.progressbar_max_stages+' </span><br /><span class="progressBar" id="element1"><img title="15%" id="element1_percentImage" src="images/ui/progress/percentImage.png" alt="15%" style="margin: 0pt; padding: 0pt; width: 120px; height: 12px; background-position: -'+this.progressbar_width+'px 50%; background-image: url(images/ui/progress/percentImage_back.png);" class="percentImage" /></span>';
	
	this.init_progress = function(){
		document.getElementById(this.div).innerHTML = this.bar_content;
	}
	
	this.animate_bar = function(){
		//bar start
		this.cur_position = this.progressbar_width - ((this.cur_stage - 1) * this.pixels_per_stage);
		//bar_end
		this.end_position = this.progressbar_width - ((this.cur_stage) * this.pixels_per_stage);
		eval(this.className+".animate_bar_anim()");
	}
	
	this.animate_bar_anim = function(){
		if(parseInt(this.cur_position) > parseInt(this.end_position)){	
			this.cur_position = parseInt(this.cur_position) - 5;
			document.getElementById('element1_percentImage').style.backgroundPosition = "-"+ this.cur_position +'px 50%';
			//alert(this.cur_position)
			setTimeout(this.className+'.animate_bar_anim()',100);
		}else{
			this.cur_stage++;
			if(this.cur_stage > this.progressbar_max_stages){
				document.getElementById('progressStatus').innerHTML = this.completed_str;
			}else{
				document.getElementById('progressStep').innerHTML = this.cur_stage;
			}
		}
	}
}

function calendar(div,name,ajax_className){
	this.div = div;
	this.className = name;
	var ajax = ajax_className;
	this.fieldId = '';
	
	this.load_calendar = function(obj){
		obj_x = parseInt(findPosX(obj)) + 100;
		obj_y = findPosY(obj)
		this.fieldId = obj.id;
		cur_state = document.getElementById('calendarContainer').className
		if(cur_state == 'visible'){
			document.getElementById('calendarContainer').className = 'hidden'
		}else{
			document.getElementById('calendarContainer').style.top = obj_y +'px'
			document.getElementById('calendarContainer').style.left = obj_x +'px'
			document.getElementById('calendarContainer').className = 'visible'
			ajax.post_response({type: "POST", data: 'js_className='+this.className,url: '/form_service/service_controll/ajax/calendar.php', update: true,callback:false});
		}
	}
	
	this.calendar_month_change = function(sel_obj){
		month = sel_obj.options[sel_obj.selectedIndex].value
		year = document.getElementById('calendarYearSelect').options[document.getElementById('calendarYearSelect').selectedIndex].value
		data_string = 'js_className='+this.className+'&month='+month+'&day=0&year='+year;
		ajax.post_response({type: "POST", data: data_string,url: '/form_service/service_controll/ajax/calendar.php', update: true,callback:false});
	}
	
	this.calendar_click_day = function(day_val, month_val, year_val){
		document.getElementById(this.fieldId).value = month_val+"-"+day_val+"-"+year_val
		this.hide_calendar()
	}

	this.calendar_year_change = function(sel_obj){
		year = sel_obj.options[sel_obj.selectedIndex].value
		month = document.getElementById('calendarMonthSelect').options[document.getElementById('calendarMonthSelect').selectedIndex].value
		data_string = 'js_className='+this.className+'&month='+month+'&day=0&year='+year
		ajax.post_response({type: "POST", data: data_string,url: '/form_service/service_controll/ajax/calendar.php', update: true,callback:false});
	}
	
	this.calendar_back_month = function(month_val){
		month = month_val
		if(month == 0){
			year = parseInt(document.getElementById('calendarYearSelect').options[document.getElementById('calendarYearSelect').selectedIndex].value) - 1
			month = 12
		}else{
			year = document.getElementById('calendarYearSelect').options[document.getElementById('calendarYearSelect').selectedIndex].value
		}
		data_string = 'js_className='+this.className+'&month='+month+'&day=0&year='+year
		ajax.post_response({type: "POST", data: data_string,url: '/form_service/service_controll/ajax/calendar.php', update: true,callback:false});
	}
	
	this.calendar_forward_month = function(month_val){
		month = month_val
		year = document.getElementById('calendarYearSelect').options[document.getElementById('calendarYearSelect').selectedIndex].value
		data_string = 'js_className='+this.className+'&month='+month+'&day=0&year='+year
		ajax.post_response({type: "POST", data: data_string,url: '/form_service/service_controll/ajax/calendar.php', update: true,callback:false});
	}
	
	this.calendar_over_day = function(day_val, month_val, year_val){
		
	}
	
	this.calendar_out_day = function(day_val, month_val, year_val){
		
	}
	
	this.hide_calendar = function(){
		document.getElementById('calendarContainer').className = 'hidden'
	}
}