//////////////////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////////////////////
/// PRIVATE FUNCTIONS
	var win;
	var win2;
	var win3;
	win  = null;
	win2 = null;
	win3 = null;

function do_alert(){
	//alert("Please insert your postal code according to the international standards below or ESA will be unable to process your order!");
	
	var iMyWidth;
	var iMyHeight;

	//half the screen width minus half the new window width (plus 5 pixel borders).
	iMyWidth = (window.screen.width/2) - (150 + 10 + 200);
	//half the screen height minus half the new window height (plus title and status bars).
	iMyHeight = (window.screen.height/2) - (240 + 50);
	
	//Open the window.
	if(win == null){
		win = window.open("alert.php","Alert","status=no,width=300,height=480,resizable=no,left=" + iMyWidth + ",top=" + iMyHeight + ",screenX=" + iMyWidth + ",screenY=" + iMyHeight + ",toolbar=no,menubar=no,scrollbars=no,location=no,directories=no");
		win.focus();
	}
}

function do_alert_2(){
	//alert("Please insert your postal code according to the international standards below or ESA will be unable to process your order!");
	
	var iMyWidth;
	var iMyHeight;

	//half the screen width minus half the new window width (plus 5 pixel borders).
	iMyWidth = (window.screen.width/2) - (340 + 10);
	//half the screen height minus half the new window height (plus title and status bars).
	iMyHeight = (window.screen.height/2) - (40 + 50);

	//Open the window.
	if(win2 == null){
		win2 = window.open("alert_2.php","Alert2","status=no,width=680,height=80,resizable=no,left=" + iMyWidth + ",top=" + iMyHeight + ",screenX=" + iMyWidth + ",screenY=" + iMyHeight + ",toolbar=no,menubar=no,scrollbars=no,location=no,directories=no");
		win2.focus();
	}
}

function do_alert_3(){
	//alert("Please insert your postal code according to the international standards below or ESA will be unable to process your order!");
	
	var iMyWidth;
	var iMyHeight;
	//half the screen width minus half the new window width (plus 5 pixel borders).
	iMyWidth = (window.screen.width/2) - (340 + 10);
	//half the screen height minus half the new window height (plus title and status bars).
	iMyHeight = (window.screen.height/2) - (40 + 50);

	
	//Open the window.
	if(win3 == null){
		win3 = window.open("alert_3.php","Alert3","status=no,width=680,height=80,resizable=no,left=" + iMyWidth + ",top=" + iMyHeight + ",screenX=" + iMyWidth + ",screenY=" + iMyHeight + ",toolbar=no,menubar=no,scrollbars=no,location=no,directories=no");
		win3.focus();
	}
}

function show(){
	var Digital=new Date();
	var hours=Digital.getHours();
	Digital.setHours(hours-(Digital.getTimezoneOffset()/60));	
	var minutes=Digital.getMinutes();
	var seconds=Digital.getSeconds();
	var tics = Digital.getMilliseconds();
	tics = Math.round(tics/10) - 1;
	if (tics<=9){tics="0"+tics}
	var output2 = Digital.toGMTString();
	var output2 = output2.replace(/ UTC/,"");
	var output2 = output2.replace(/ GMT/,"");
	//var output2 = output2+":"+tics;
	
	if (hours<=9){hours="0"+hours}
	if (minutes<=9){minutes="0"+minutes}
	if (seconds<=9){seconds="0"+seconds}
	document.Tick.Clock.value=output2;
	setTimeout("show()",1000)
}

function logincrypt() {
	var hash = hex_hmac_md5(document.loginform.username.value, document.loginform.password.value);
	//alert(hash);
	
	document.loginform.password.value = hash;
	document.loginform.action="index.php?do=login.login";
	document.loginform.submit();
}

function hidestatus(){
window.status=''
return true
}

function isValidEmail(str) {
   return (str.indexOf(".") >=1) && (str.indexOf("@") > 0);
 
}


function do_terms(){
	if(document.mainform.accept.value=="false"){
		document.mainform.accept.value="true";
	}else{
		document.mainform.accept.value="false";
	}	
}

function do_news(){
	if(document.mainform.news.value=="false"){
		document.mainform.news.value="true";
	}else{
		document.mainform.news.value="false";
	}	
}

function CheckSubmit(){
	var checked = true;
	var first_empty = true;
	
	// Check Address Information
	if (document.mainform.school.value == ""){
		var checked = false;
		if(first_empty == true){document.mainform.school.focus();alert('You need to fill in your school.');}
		var first_empty = false;
	}
	
	if (document.mainform.contact.value == ""){
		var checked = false;
		if(first_empty == true){document.mainform.school.focus();alert('You need to fill in your contact person name.');}
		var first_empty = false;
	}
	
	if (document.mainform.address.value == ""){
		var checked = false;
		if(first_empty == true){document.mainform.address.focus();alert('You need to fill in your Street Name.');}
		var first_empty = false;
	}
	
	if (document.mainform.address_nr.value == ""){
		var checked = false;
		if(first_empty == true){document.mainform.address_nr.focus();alert('You need to fill in your Street Number.');}
		var first_empty = false;
	}
	/*
	if (document.mainform.postcode.value == ""){
		var checked = false;
		if(first_empty == true){document.mainform.postcode.focus();alert('You need to fill in your post code.');}
		var first_empty = false;
	}
	*/
	if (document.mainform.city.value == ""){
		var checked = false;
		if(first_empty == true){document.mainform.city.focus();alert('You need to fill in your city.');}
		var first_empty = false;
	}
	
	if (document.mainform.country.value == ""){
		var checked = false;
		if(first_empty == true){document.mainform.country.focus();alert('You need to fill in your country.');}
		var first_empty = false;
	}
	
	if (document.mainform.phone.value == ""){
		var checked = false;
		if(first_empty == true){document.mainform.phone.focus();alert('You need to fill in your phone number.');}
		var first_empty = false;
	}
	
	
	// Check ESA Information
	if (document.mainform.inf_profession.value == ""){
		var checked = false;
		if(first_empty == true){document.mainform.inf_profession.focus();alert('You need to fill in your profession.');}
		var first_empty = false;
	}
	
	if(checked){
	var emailvalid = isValidEmail(document.mainform.inf_email.value);
		if(emailvalid== false){
			var checked = false; 
			alert('You need to fill in a valid email address.');
		}
	}
	/*
	if (document.mainform.inf_url.value == ""){
		var checked = false;
		if(first_empty == true){document.mainform.inf_url.focus();alert('You need to fill in your schools URL.');}
		var first_empty = false;
	}
	*/
	
	if (document.mainform.inf_ages.value == ""){
		var checked = false;
		if(first_empty == true){document.mainform.inf_ages.focus();alert('You need to fill in the Ages of Pupils taught.');}
		var first_empty = false;
	}
	if (document.mainform.inf_subjects.value == ""){
		var checked = false;
		if(first_empty == true){document.mainform.inf_subjects.focus();alert('You need to fill in the subject taught.');}
		var first_empty = false;
	}
	
	/*
	if (document.mainform.prim_language.value == ""){
		var checked = false;
		if(first_empty == true){
			document.mainform.language.focus();alert('You need to fill in the desired language.');}
		var first_empty = false;
	}
	
	if (document.mainform.sec_language.value == ""){
		var checked = false;
		if(first_empty == true){
			document.mainform.language.focus();alert('You need to fill in the desired language.');}
		var first_empty = false;
	}
	*/
	if (document.mainform.accept.value =="false"){
		var checked = false;
		if(first_empty == true){document.mainform.disclaimer.focus();alert('You need to agree to the terms of service to continue.');}
		var first_empty = false;
	}	
	
	// Check for Error and Send
	document.mainform.action = 'index.php?do=home.confirm';
	if(checked){document.mainform.submit();}
}



function checkthis(field){
	if(document.processform.check_this.checked == true){
		checkall(field);
	}else{
		checknone(field);
	}
}
function checkall(field){for (i = 0; i < field.length; i++){field[i].checked = true ;}}
function checknone(field){for (i = 0; i < field.length; i++){field[i].checked = false ;}}


function do_order(order,type){
	var confirm_msg = (type) ? 'Execute Order Archiving?' : 'Execute Order Processing?';
	var action 	= (type) ? 'index.php?do=admin.archive_order' : 'index.php?do=admin.process_order';
	if(confirm(confirm_msg)){
		document.processform.action = action+'&orders='+order;
		document.processform.submit();
	}
}

function do_delete(order){
	if(confirm('Are you sure you want to delete order #'+order+'?')){
		document.processform.action = 'index.php?do=admin.delete_order&id='+order;
		document.processform.submit();
	}
}

function do_finalize(){document.confirmform.action = 'index.php?do=home.finalize';document.confirmform.submit();}


function process_order(field,type){
	
	document.processform.action = (type) ? 'index.php?do=admin.archive_order' : 'index.php?do=admin.process_order';
	var confirm_msg = (type) ? 'Execute Order Archiving?' : 'Execute Order Processing?';
	
	var o_total = document.processform.o_total.value;
	var o_orders	= new Array;	
	var cnt = 0;
	
	for (i = 0; i < field.length; i++){if(field[i].checked == true){o_orders[cnt] = field[i].value ;cnt++;}}
	
	if(confirm(confirm_msg)){
		document.processform.ordersout.value=o_orders;
		document.processform.submit();
	}
}

function delete_order(field){
	
	var o_total = document.processform.o_total.value;
	var o_orders	= new Array;	
	
	cnt = 0;
	for (i = 0; i < field.length; i++){		
		if(field[i].checked == true){o_orders[cnt] = field[i].value ;cnt++;}
	}
	
	do_delete(o_orders);
}
