

function opacity(id, opacStart, opacEnd, millisec) {
	
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;
	
	document.getElementById(id).style.visibility = "visible";
	
	
    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
		setTimeout(hideLoader, 500);
		
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
		
    }
}
function hideLoader()
{
	document.getElementById('download_error').style.visibility = "hidden";
	document.getElementById('download_loader').style.visibility = "hidden";
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
} 


// init validation
function initValidation()
{  
	email = document.downloadAjax.email.value;
	
	if (ValidateEmail(email))
	{
		// start download
		initDownload();
	}
	else
	{
		// fade in error
	    opacity("download_error", 0, 100, 300);
		//test();
		//alert("wont work");
		
	}
}

function tryAgain()
{  
	// fade out error
	opacity('download_error', 100, 0, 300);
}

function clearForm()
{
	document.downloadAjax.email.value = "";
}

// ValidatePhone
// 
// ###-###-####
// ###.###.####
// 
// Tests a phone number against the formats shown above.
function ValidatePhone(strInput)
{
	// The regular expression to test the input against.
	var objRegExp = /^\d{3}(\-|\.)\d{3}(\-|\.)\d{4}/;
	
	// Return the test results.
	return objRegExp.test(strInput);
}

// ValidateEmail
// 
// X#@X#.XX
// X#@X#.XXX
// 
// Tests an email address against the formats shown above.
function ValidateEmail(strInput)
{
	// The regular expression to test the input against.
	//var objRegExp = /^\w+(@)\w+(\.){1}[a-z]{2,3}$/;
	var objRegExp = /^[\w\.\-]+(@)[\w\.\-]+(\.){1}[a-zA-Z]{2,4}$/;
	
	// Return the test results.
	return objRegExp.test(strInput);
}

// ValidateData
// 
// #-#-####
// #/#/####
// #.#.####
// ##-##-####
// ##/##/####
// ##.##.####
// 
// Teets a date against the formats shown above.
function ValidateData(strInput)
{
	// The regular expression to test the input against.
	var objRegExp = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/;
	
	// Return the test results.
	return objRegExp.test(strInput);
}