//pre load images
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

//show hide single div
function showHideSingleAlternate (divIdA, divIdB){	
	if(document.getElementById(divIdA).style.display == 'none'){
		document.getElementById(divIdA).style.display = '';
		document.getElementById(divIdB).style.display = 'none';
	}else{
		document.getElementById(divIdA).style.display = 'none';
		document.getElementById(divIdB).style.display = '';
	}
}

//close button bind
function bindClose(){
	//if element exists
	if(document.getElementById("btnClose")){
		$('#btnClose').bind('click', function() {
			 $("#dropDownDiv").slideUp(sliderDuration);
		});
	}
}

//vars
var sliderDuration = 500;

//ajax forms code
$(document).ready(function(){
	
	//request button clisk
	$("#requestButton").click(function () {
		//if hidden
		if($("#dropDownDiv").is(":hidden")){
			//if already on request
			if(document.getElementById("openButton").value  == "request"){
				//then just toggle it open
				$("#dropDownDiv").slideToggle(sliderDuration);
			}else{
				//otherwise show the loader
				$("#dropDownDiv").html("<p align=\"center\"><br /><img src=\"images/loader.gif\"><br />Loading ... please wait!</p>");
				//code to show and hide
				$("#dropDownDiv").slideToggle(sliderDuration);
				//and call the form
				$('#dropDownDiv').load('includes/html_request.php', function() {					
				    //set hidden value to request
				    document.getElementById("openButton").value = "request";
				    //timeout let close button load then bind it
					setTimeout("bindClose()", 3000);
				});
			}
		}else{
			//in case not hidden see if request is the main parameter
			if(document.getElementById("openButton").value  == "request"){
				//simply toggle it close
				$("#dropDownDiv").slideToggle(sliderDuration);
			}else{
				//otherwise first hide			
				$("#dropDownDiv").hide();
				//second call loader
				$("#dropDownDiv").html("<p align=\"center\"><br /><img src=\"images/loader.gif\"><br />Loading ... please wait!</p>");
				//code to show and hide
				$("#dropDownDiv").slideToggle(sliderDuration);
				//and call the form
				//third load form
				$('#dropDownDiv').load('includes/html_request.php', function() {
				    //set hidden value to request
				    document.getElementById("openButton").value = "request";
				    //timeout let close button load then bind it
					setTimeout("bindClose()", 3000);
				});
			}
		}
	});
	
	//contact button clisk
	$("#contactButton").click(function () {
		//if hidden
		if($("#dropDownDiv").is(":hidden")){
			//if already on contact
			if(document.getElementById("openButton").value  == "contact"){
				//then just toggle it open
				$("#dropDownDiv").slideToggle(sliderDuration);
			}else{
				//otherwise show the loader
				$("#dropDownDiv").html("<p align=\"center\"><br /><img src=\"images/loader.gif\"><br />Loading ... please wait!</p>");
				//code to show and hide
				$("#dropDownDiv").slideToggle(sliderDuration);
				//and call the form
				$('#dropDownDiv').load('includes/html_contact.php', function() {	
				    //set hidden value to contact
				    document.getElementById("openButton").value = "contact";
				    //timeout let close button load then bind it
					setTimeout("bindClose()", 3000);
				});
			}
		}else{
			//in case not hidden see if contact is the main parameter
			if(document.getElementById("openButton").value  == "contact"){
				//simply toggle it close
				$("#dropDownDiv").slideToggle(sliderDuration);
			}else{
				//otherwise first hide			
				$("#dropDownDiv").hide();
				//second call loader
				$("#dropDownDiv").html("<p align=\"center\"><br /><img src=\"images/loader.gif\"><br />Loading ... please wait!</p>");
				//code to show and hide
				$("#dropDownDiv").slideToggle(sliderDuration);
				//third load form
				$('#dropDownDiv').load('includes/html_contact.php', function() {
				    //set hidden value to contact
				    document.getElementById("openButton").value = "contact";
				    //timeout let close button load then bind it
					setTimeout("bindClose()", 3000);
				});
			}
		}
	});
	
	/* OLD CODE
	//contact button clisk
	$("#contactButton").click(function () {
		//if hidden
		if($("#dropDownDiv").is(":hidden")){
			//load ajax for loading first
			$("#dropDownDiv").html("<p align=\"center\"><br /><img src=\"images/loader.gif\"><br />Loading ... please wait!</p>");
		}
		//load the content
		$('#dropDownDiv').load('includes/html_contact.php', function() {
			//toggle after loading if not already shown	  		
	  		if($("#dropDownDiv").is(":hidden")){
	  			//code to show and hide
			    $("#dropDownDiv").slideToggle(sliderDuration);
			    //set hidden value to contact
			    document.getElementById("openButton").value = "contact";
			}else{
				//now check if the current one is open and the openButton is "contact"
				if(document.getElementById("openButton").value  == "contact"){
					//toggle to close
					$("#dropDownDiv").slideToggle(sliderDuration);	
				}else{
					//hide and then toggle
					$("#dropDownDiv").hide();
					$("#dropDownDiv").slideToggle(sliderDuration);
					//set to contact
			    	 document.getElementById("openButton").value  = "contact";
				}				
			}
		});
		
		
		
		//timeout let close button load then bind it
		setTimeout("bindClose()", 3000);
	});
	*/
});

//check payment page form
function chkFormPayment(counter){
	counter = counter+1;
	for (var i=1; i < counter; i++){
		requiredField = "requiredField"+i;
		if(document.getElementById(requiredField).value == ""){
			document.getElementById(requiredField).style.backgroundColor = '#FFFD76';
			document.getElementById(requiredField).focus();
			return false;
		}
	}
	
	//amount check
	var checkout_amount = document.getElementById("checkout_form").checkout_amount.value;
	if(isNaN(checkout_amount)){
		alert("Amount must be a number ! (for example: 100, 500, 1000 etc)");
		document.getElementById("checkout_form").checkout_amount.value = '';
		document.getElementById("checkout_form").checkout_amount.focus();
		return false;
	}
	
}	

//return color after js check
function returnFieldColor(a){
	a.style.background = '#FFFFFF';
}
