// JavaScript Document

//Delete Email
function removeEmail(theForm,email){
	var r = confirm("Are you sure you want to remove this account?: \n"+email);
	return r;
	}


//check payment information
function payForm(theForm,a){
	b = theForm.amount.value;
	if(a!=b){
		theForm.action = 'client.php?message=SECURITY ERROR<br/>Log out and try again';
		theForm.submit();
		}
	}

//remove invoice
function remove_invoice(f,id,amount){
	var r=confirm("Are you sure you want to remove this invoice?\nInvoice: "+id+"\nAmount: $"+amount);
	if (r==true){
	  document.getElementById(f).submit();
	  }else{
		  return false;
	  }
}



//renew Domain
function renew_Domain(domain){
	var r=confirm("Are you sure you want to add a year to this domain: \n"+ domain);
	if (r==true){
	  	return true;
	  }else{
		return false;
	  }
}

//Submit Form (used for links to submit forms)
function straight_submit(id){
	  document.getElementById(id).submit();
}


//Set invoice as paid
function pay_invoice(f,id,amount){
	var r=confirm("Are you sure you want to set this invoice as paid?\nInvoice: "+id+"\nAmount: $"+amount);
	if (r==true){
	  document.getElementById(f).submit();
	  }else{
		  return false;
		  }
}


// renew domain form
function renewDomain(f,domain){
	var r=confirm("Are you sure you want to renew this domain?\n"+domain);
	if (r==true){
	  document.getElementById(f).submit();
	  }else{
		  return false;
		  }
}


// show hidden fields
function showForm(id){
	  document.getElementById(id).style.display = 'table-row';
}


//************ Form Validations *************//

//New email account
function validateNewEmail(theForm){
	
	if(theForm.username.value.length < 4){
		alert('Error: email username must be at least 4 characters long \n Note: username will be used as: "username\"@yourdomain.com');
		return false
	}
	
	re = /^\w+$/; 
	if(!re.test(theForm.username.value)){
		alert('Error: email username must contain only letters, numbers and underscores \n Note: username will be used as: "username\"@yourdomain.com');
		return false
	}
	
		
	if(theForm.password.value.length < 6){
		alert('Error: email password must be at least 6 characters long');
		return false
	}
	
	re = /^\w+$/; 
	if(!re.test(theForm.password.value)){
		alert('Error: password must contain only letters and numbers');
		return false
	}
		
}



//new Alias
function validateAlias(theForm){
	re = /^\w+$/; 
	if(!re.test(theForm.alias.value)){
		alert('Error: email alias must contain only letters, numbers and underscores \n Note: alias will be used as: \"alias\"@yourdomain.com and sent to \"username\"@yourdomain.com');
		return false
	}
	
	if(theForm.alias.value.length < 4){
		alert('Error: email alias must be at least 4 characters long');
		return false
	}
}




//Hosting Password
function validateHostingPassword(theForm){
	if(theForm.pass.value.length < 6){
		alert('Error: new passwords must be at least 6 characters long');
		return false
	}
	re = /^\w+$/; 
	if(!re.test(theForm.pass.value)){
		alert('Error: new passwords must contain only letters, numbers and underscores');
		return false
	}
	re = /[0-9]/; 
	if(!re.test(theForm.pass.value)){
	alert('Error: new passwords must contain at least one number and one capital letter');
		return false;	
		}
	re = /[A-Z]/; 
	if(!re.test(theForm.pass.value)){
	alert('Error: new passwords must contain at least one number and one capital letter');
		return false;	
		}
}

//Email Password
function validatePassword(theForm){
	if(theForm.pass.value.length < 6){
		alert('Error: new passwords must be at least 6 characters long');
		return false
	}
	re = /^\w+$/; 
	if(!re.test(theForm.pass.value)){
		alert('Error: new passwords must contain only letters, numbers and underscores');
		return false
	}

}



//Send email from link to info@multimediaxp.com
function openMailclient(){
	window.location = "mailto:info@multimediaxp.com";	
}



//validate profile form and password
function validateLoginPassword(theForm){
	
	//Check name
	if(theForm.name.value==""){
		alert('Error: sorry you must provide a contact name');
		return false;
		}
		
	if(theForm.company.value==""){
		alert('Error: sorry you must provide a company name\n If you don\'t have one simply re-write your name');
		return false;
		}
	
	//Check email
	re = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	if(!re.test(theForm.email.value)){
		alert('Error: invalid email address');
		return false;
		}
		
	//username validation
	if(theForm.username.value.length < 4){
		alert('Error: login username must be at least 4 characters long');
		return false
	}
	re = /^\w+$/; 
	if(!re.test(theForm.username.value)){
		alert('Error: login username must contain only letters, numbers and underscores');
		return false
	}
	
	//password validation
	if(theForm.pass.value.length < 4){
		alert('Error: login password must be at least 4 characters long');
		return false
	}
	re = /^\w+$/; 
	if(!re.test(theForm.pass.value)){
		alert('Error: login password must contain only letters, numbers and underscores');
		return false
	}
	
	if(theForm.pass.value == 'password'){
		alert('Error: please change the default login password \"password\"');
		return false
	}
	
	
}
