// UNIData-Informática
// Site v1.0
var Loading ="<img src='Skin/Ajax/Loading.gif' border='0' />";

// Login Module
function LoginModule(){
	$('LoginForm').addEvent('submit', function(e) {
		new Event(e).stop();
		var LogRes = $('Login_Res');
		var LogForm = $('Login_Form');
		LogForm.setStyle("display", "none");
		LogRes.setStyle("display", "block");
		this.send({
			update: LogRes,
			onComplete: function() {
				// Button Login Error
				if ($('Bt_LoginError')){		
					SwapImageButton('Bt_LoginError');
					$('Bt_LoginError').addEvent('click', function() {
						LogForm.setStyle("display", "block");
						LogRes.setStyle("display", "none");
					});
				}
				
				// Button Administration
				if ($('Bt_Admin')){		
					SwapImageButton('Bt_Admin');
				}
				// Button Logout
				if ($('Bt_Logout')){		
					SwapImageButton('Bt_Logout');
					$('Bt_Logout').addEvent('click', function() {
						$('Username').setText('');
						$('Password').setText('');
					});
				}
			},
			onRequest: function(){
				$('Login_Res').innerHTML=Loading;
			}
		});
	});
}


// Mailing Module
function MailingModule(){
	$('MailingForm').addEvent('submit', function(e) {
		new Event(e).stop();
		var MailingRes = $('Mailing_Res');
		var MailingForm = $('Mailing_Form');
		MailingForm.setStyle("display", "none");
		MailingRes.setStyle("display", "block");
		this.send({
			update: MailingRes,
			onComplete: function() {
				// Button Login Error
				if ($('Bt_MailingError')){		
					SwapImageButton('Bt_MailingError');
					$('Bt_MailingError').addEvent('click', function() {
						//$('Mailingemail').setText("");
						MailingForm.setStyle("display", "block");
						MailingRes.setStyle("display", "none");
					});
				}	
			},
			onRequest: function(){
				$('Mailing_Res').innerHTML=Loading;
			}
		});
	});
}



function acordion_fx(){
	var list = $$('#accordion h3');
	list.each(function(element) {
 		var fx = new Fx.Styles(element, {duration:200, wait:false});
			element.addEvent('click', 'javascript: void(0);');
			element.addEvent('mouseenter', function(){
				element.setStyle('background','url(Skin/Accordeon/Accordeon_On.png)');
				fx.start({
					'padding-left': 20
				});
			});
 			element.addEvent('mouseleave', function(){
				element.setStyle('background','url(Skin/Accordeon/Accordeon_Off.png)');
				fx.start({
					'padding-left': 10
				});
		});
 	});
}
function acordion(){
var accordion = new Accordion('h3.atStart', 'div.atStart', {
	opacity: false,
	onActive: function(toggler, element){
		toggler.setStyle('color', '#66FFFF');
	},
	onBackground: function(toggler, element){
		toggler.setStyle('color', '#ffffff');
	}
}, 
$('accordion'));}


function loadmodule(url, targetId){
	var newurl = url + "ms=" + new Date().getTime();
 	var load = new Ajax(newurl, {
			method: 'get',
			update: $(targetId),
			onRequest: function(){
				$(targetId).innerHTML='loading...';
			}
		}); 
		load.request();
 
	}
	
function SelectVehicle(url, targetId, id){//Select Vehicle
	var newurl = url + "ms=" + new Date().getTime();
	var FirstDiv="Sel_" + id;
	var SecondDiv="Unsel_" + id; 
	toggleDiv(FirstDiv);
	toggleDiv(SecondDiv);
 	var load = new Ajax(newurl, {
			method: 'get',
			update: $(targetId),
			onRequest: function(){
				$(targetId).innerHTML='loading...';
			}
		}); 
		load.request();
	}
	
function toggleDiv(id){
	var div = document.getElementById(id);
	var current = div.style.display;
	if (current == 'none')
		div.style.display = 'block';
	else
		div.style.display = 'none';
}
	
// Slide Down	
function VSlideIn(Element,Button){	
	var mySlide = new Fx.Slide(Element);
		mySlide.hide();
		$(Button).addEvent('click', function(e){
			e = new Event(e);
			mySlide.slideIn();
			e.stop();
		});
}

// Slide Up
function VSlideOut(Element,Button){	
	var mySlide = new Fx.Slide(Element);
		$(Button).addEvent('click', function(e){
			e = new Event(e);
			mySlide.slideOut();
			e.stop();
		});
}

function SwapImageButton(Element){//Function To Swap Image Button
	$(Element).addEvents({
		mouseleave: function() {
			this.src = this.src.replace(/Off/g,'On');
			this.effect('opacity').custom(.3,1);
		},
		mouseenter: function() {
			this.src = this.src.replace(/On/g,'Off');
			this.effect('opacity').custom(.3,1);
		}
	});

}


function LastAddVehicles(){//Last Add Vehicles Modules
	new iCarousel("example_3_content", {
		idPrevious: "example_3_previous",
		idNext: "example_3_next",
		idToggle: "undefined",
		item: {
			klass: "example_3_item",
			size: 170},
		animation: {
			duration: 400,
			amount: 3}
	});
}

window.addEvent("domready", function() {//Initialize Page
	//Check If Last Add Vehicles Module Exists
	if ($('example_3_content')){
		LastAddVehicles();
	}
	
	//Check If Login Module Exists
	if ($('LoginForm')){
		SwapImageButton('Submit_Login');
		LoginModule();
	}
	// Button Print
				if ($('Bt_Print')){		
					SwapImageButton('Bt_Print');
				}
	
	//Check If Mailing Module Exists
	if ($('MailingForm')){
		SwapImageButton('Submit_Mailing');
		MailingModule();
	}
	//Check If Vehicles Search Exists
	if ($('Search_Vehicles_Mid')){
		SwapImageButton('Open_Search');
		SwapImageButton('Close_Search');
		SwapImageButton('Search_Submit');
		SwapImageButton('Show_All');
	if ($('SearchSlider')){
		var mySlide = new Fx.Slide('SearchSlider');
		mySlide.hide();
		$('Open_Search').addEvent('click', function(e){
			e = new Event(e);
			document.getElementById('Open_Search').style.display = "none";
			document.getElementById('On_Form_Search').style.display = "block";
			mySlide.slideIn();
			e.stop();
		});
		$('Close_Search').addEvent('click', function(e){
			e = new Event(e);
			document.getElementById('On_Form_Search').style.display = "none";
			document.getElementById('Open_Search').style.display = "block";
			mySlide.slideOut();
			e.stop();
		});
		}
	if ($('SearchSlider1')){
		document.getElementById('Open_Search').style.display = "none";
		document.getElementById('On_Form_Search').style.display = "block";
		document.getElementById('Close_Search').style.display = "none";
		}
		
	}
	//Check If Vehicles Search Exists
	if ($('Selected_Vehicles_Mid')){
		loadmodule('Selected_Vehicles.asp?','Selected_Vehicles_Mid');
	}
	//Check If Vehicles Search Exists
	if ($('Vehicles_Grid')){
		loadmodule('Vehicles_Grid.asp?','Vehicles_Grid');
	}
	if ($('map')){
		gmaps();
	}
	if ($('Company_Top')){
		Lightbox.init({descriptions: '.lightboxDesc', showControls: true});
	}
});
