// JavaScript Document

function determinePosition()
{
	var pageHeight 	= document.body.clientHeight;
	var divHeight 	= document.getElementById('loading').offsetHeight;
	
	var totalDist	= pageHeight - divHeight;
	
		document.getElementById('loading').style.top = ((document.body.scrollTop-2)+totalDist)+'px'; 
	
	setTimeout("determinePosition()", 10);
}

function opacity(id, opacStart, opacEnd, millisec) { 
    //speed for each frame 
    var speed = Math.round(millisec / 100); 
    var timer = 0; 

    //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++; 
        } 
    } else if(opacStart < opacEnd) { 
        for(i = opacStart; i <= opacEnd; i++) 
            { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } 
} 

//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 + ")"; 
}

function hidediv(pass) { 
var divs = document.getElementsByTagName('div'); 
for(i=0;i<divs.length;i++){ 
if(divs[i].id.match(pass)){//if they are 'see' divs 
if (document.getElementById) // DOM3 = IE5, NS6 
divs[i].style.visibility="hidden";// show/hide 
else 
if (document.layers) // Netscape 4 
document.layers[divs[i]].display = 'hidden'; 
else // IE 4 
document.all.hideShow.divs[i].visibility = 'hidden'; 
} 
} 
} 

function showdiv(pass) { 
var divs = document.getElementsByTagName('div'); 
for(i=0;i<divs.length;i++){ 
if(divs[i].id.match(pass)){ 
if (document.getElementById) 
divs[i].style.visibility="visible"; 
else 
if (document.layers) // Netscape 4 
document.layers[divs[i]].display = 'visible'; 
else // IE 4 
document.all.hideShow.divs[i].visibility = 'visible'; 
} 
} 
} 


function btn_change(to) {
// Define source image file to work with >>>>
	var source_image = event.srcElement.src.split("/");
	var source_name = source_image[source_image.length-1];
	var directory = source_image[0];
	var new_source = source_name.split("_");
	var dir_num = (source_image.length)-2;
// Collect and set dir location for new pic >>>>
		for(a=1;a<=dir_num;a++) {
		var directory = directory + "/" + source_image[a];
		}
	var new_image = new_source[0];
	var num = (new_source.length)-1;
	new_source[num] = to + ".gif";
// Collect and set source file name for new pic >>>>
		for(x=1;x<=num;x++) {
		var new_image = new_image + "_" + new_source[x];
		}
// Reset image on screen >>>>
	event.srcElement.src = directory + "/" + new_image;
}

function formChange(form_id,form_action,submit_form) { 
	document.getElementById(form_id).action = form_action;
	if(submit_form) {
		document.getElementById(form_id).submit();
	}
}

function app_check() {
	var chk = document.getElementsByTagName('input');
	for(a=0;a<chk.length;a++) {
		if(chk[a].value == '' || chk[a].value == ' ') {
			alert('********** Submission Error: **********\n\n               Please fill out ALL fields!\n\n                        Thank you :)');
			return false;
		}
	}
	if(document.getElementById('app_area_country')) {
		if(document.getElementById('app_area_country').value == '' || document.getElementById('app_area_country') == ' ') {
			alert('********** Submission Error: **********\n\n       Please enter a "Target Country"!\n\n                        Thank you :)');
			return false;
		}
		if(document.getElementById('app_experience').value == 'Please enter your relevant sales experience and details about yourself professionally (work ethic, personality, etc)') {
			alert('********** Submission Error: **********\n\n       Please enter "Your Experience"!\n\n                        Thank you :)');
			return false;
		}
		if(document.getElementById('app_area_proposal').value == 'Please enter the details of your selected region such as cities/suburbs, target population and why you think it would make a good target area') {
			alert('********** Submission Error: **********\n\n       Please enter "Proposal Details"!\n\n                        Thank you :)');
			return false;
		}
	}
	var em = document.getElementById('app_email');
	if(em.value.indexOf('.') > 2 && em.value.indexOf('@') > 0) {
		return true;
	}
	else {
		alert('********** Submission Error: **********\n\n       Please enter a valid email address!\n\n                        Thank you :)');
		return false;
	}
}

function set_prop(to) {
	var new_html		=	new Array();
	new_html['tgt_1']	=   ( '&nbsp;<span style="font-size:16px; color:#FF0000;">&raquo;</span>&nbsp;Targeted&nbsp;Country:');

	new_html['tgt_2']	=	( '<select class="nbi_small_black" id="app_area_country" name="app_area_country">'
							+ '<option>-- Select a Country --</option>'
							+ '<option value="Canada">Canada</option>'
							+ '<option value="Ireland">Ireland</option>'
							+ '<option value="New Zealand">New Zealand</option>'
							+ '<option value="United States">United States</option>'
							+ '<option value="United Kingdom">United Kingdom</option>'
							+ '</select>&nbsp;'
							+ '<span class="business_app_note">'
							+ '<span style="font-size:14px;">&laquo;</span>&nbsp;Select the country you wish to target with your license</span>');
	
	new_html['tgt_3']	=	( '1px' );
							 
	new_html['alt_1']	= 	( '&nbsp;<span style="font-size:16px; color:#FF0000;">&raquo;</span>&nbsp;Alternative&nbsp;Country:');
	
	new_html['alt_2']	=	( '<input type="text" size="30" class="nbi_small_black" id="app_area_country" name="app_area_country">&nbsp;'
							+ '<span class="business_app_note">'
							+ '<span style="font-size:14px;">&laquo;</span>&nbsp;Enter the country you propose to target with your license</span>');
	
	new_html['alt_3']	=	( '0px' );
	
	document.getElementById('prop0').style.paddingTop 		= new_html[to + '_3'];
	document.getElementById('prop0').style.paddingBottom 	= new_html[to + '_3'];
	document.getElementById('prop1').innerHTML 				= new_html[to + '_1'];
	document.getElementById('prop2').innerHTML 				= new_html[to + '_2'];
}

function jumptopage_menu(id)
{
	var result = document.getElementById(id).value;
	
	if	(result)
	{ window.location = result; }
}
