// --------------
//  Select Image
// --------------

function SelectImage()
{	
	var url = "/newsImages.aspx";
	// display popup window allowing user to select from an image list, or upload their own
	flist = "dialogHeight:520px;dialogWidth:800px;resizable:yes;";

	var myObject = new Object();
	myObject.cancel = true;
	myObject.imagePath = "";
	myObject.testString = "Hello";

	var dialog = window.showModalDialog(url, myObject, flist);

	if (myObject.cancel) return;
	document.getElementById("txtPhoto").value = myObject.imagePath;
}

// --------------------------------------------
// Send Email
// --------------------------------------------

function SendEmail()
{
	var name,email,subject,message;	
	name = document.getElementById('txtName').value;
	email = document.getElementById('txtEmail').value;
	subject = document.getElementById('txtSubject').value;
	message = document.getElementById('txtMessage').value;	
	_default.SendEmail(name,email,subject,message,SendEmail_callback);
}

function SendEmail_callback(res)
{
	//Show confirmation and hide the email form
	var hiddenDiv;
	var emailFormDiv;
	hiddenDiv = document.getElementById('emailConfirmation');
	emailFormDiv = document.getElementById('emailForm');
	emailFormDiv.style.display='none';
	hiddenDiv.style.display = 'block';
}

// --------------------------------------------
// Popup code
// --------------------------------------------

var newwindow;
function popuphotbagswindow(url)
{
	newwindow=window.open(url,'name','location=0,status=0,scrollbars=0,width=800,height=500');
	if (window.focus) {newwindow.focus()}
}

// Pre-load rollover images

var preloaded = new Array();
function preload_images() 
{
   for (var i = 0; i < arguments.length; i++)
    {
        preloaded[i] = document.createElement('img');
        preloaded[i].setAttribute('src',arguments[i]);
    };
};

function preload_primarynav()
{
	preload_images
	(	'/res/images/nav/aboutus_on.gif',
	    '/res/images/home_on.gif',
		'/res/images/nav/casestudies_on.gif',
		'/res/images/nav/contactus_on.gif',
		'/res/images/nav/links_on.gif',
		'/res/images/nav/newsandevents_on.gif',
		'/res/images/nav/ourservices_on.gif',
		'/res/images/howcanwehelpyou_rollover.jpg',
		'/res/images/kitchenstories_rollover.jpg',
		'/res/images/whatourclientssay_rollover.jpg');		
};

// Spares and Breakdown Form Submission

function validateSparesForm()
{
    var emailAddress;
    
    emailAddress = document.getElementById('txtEmailAddress').value;
    if (emailAddress == "")
    {
        alert('Email address is a mandatory field.');
    }
    else
    {
        var firstName, surname, message;
        
        firstName = document.getElementById('txtFirstName').value;
        surname = document.getElementById('txtSurname').value;
        message = document.getElementById('txtMessage').value;
        
        whitco.ajaxFunctions.submitSparesForm(firstName,surname,emailAddress,message,submitSparesForm_callback);
    }
}

function submitSparesForm_callback()
{
    var thankYouDiv = document.getElementById('sparesThankYou');
    var theForm = document.getElementById('sparesForm');
    
    thankYouDiv.style.display = 'block';    
    theForm.style.display = 'none';    
}

// Breakdown Form

function validateBreakdownForm()
{
    var emailAddress;
    
    emailAddress = document.getElementById('txtEmailAddress').value;
    if (emailAddress == "")
    {
        alert('Email address is a mandatory field.');
    }
    else
    {
        var firstName, surname, message;
        
        firstName = document.getElementById('txtFirstName').value;
        surname = document.getElementById('txtSurname').value;
        message = document.getElementById('txtMessage').value;
        
        whitco.ajaxFunctions.submitBreakdownForm(firstName,surname,emailAddress,message,submitBreakdownForm_callback);
    }
}

function submitBreakdownForm_callback()
{
    var thankYouDiv = document.getElementById('breakdownThankYou');
    var theForm = document.getElementById('breakdownForm');
    
    thankYouDiv.style.display = 'block';    
    theForm.style.display = 'none';    
}

// AJAX Pro Testing

function ajaxTest()
{
    ajaxProTest.stringTest(ajaxTest_callback);
}

function ajaxTest_callback()
{
    alert('callback');
}
