// JScript source code
function isValidEmail(str) {
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(str)){
		return true;
	}
	else {
		return false;
	}
}

function checkenquiry(){
	var ftxt = '';

	if (document.enquiry.Name.value==''){
		ftxt += '\n- Please enter your Name.';
	}
	
	if (document.enquiry.Company.value==''){
		ftxt += '\n- Please enter your Company.';
	}
	
	if (document.enquiry.Telephone.value==''){
		ftxt += '\n- Please enter your Telephone Number.';
	}
	
	if (isValidEmail(document.enquiry.email.value)==false){
		ftxt += '\n- Please enter your Email Address.';
	}
	
	if (document.enquiry.subject.value==''){
		ftxt += '\n- Please select an enquiry Subject.';
	}
	
	if (ftxt!==''){
		alert('One or more errors were found while submitting this form. The errors found are displayed below.\n' + ftxt + '\n\nPlease correct the above errors and try again.');
		return false;
	}
	else {
		return true;
	}
}

function checknewenquiry(){
	var ftxt = '';
	
	if (document.EnquireForm.subject.value==''){
		ftxt += '\n- Please select a Subject.';
	}
	
	if (document.EnquireForm.FirstName.value==''){
		ftxt += '\n- Please enter your First Name.';
	}
	
	if (document.EnquireForm.LastName.value==''){
		ftxt += '\n- Please enter your Last Name.';
    }

    if (document.EnquireForm.Company.value == '') {
        ftxt += '\n- Please enter your Company Name.';
    }
	
	if (isValidEmail(document.EnquireForm.email.value)==false){
		ftxt += '\n- Please enter your Email Address.';
    }

    if (document.EnquireForm.Country.value == '') {
        ftxt += '\n- Please enter your Country.';
    }
	
	if (document.EnquireForm.Message.value==''){
		ftxt += '\n- Please enter your Message.';
	}
	
	if (ftxt!==''){
		alert('One or more errors were found while submitting this form. The errors found are displayed below.\n' + ftxt + '\n\nPlease correct the above errors and try again.');
		return false;
	}
	else {
		return true;
	}
}


function clearemailfield(fieldVal){
	if (isValidEmail(fieldVal)==false){
		document.newsletterform.email.value='';
	}
}

function clearText(field){
    if (field.defaultValue == field.value) field.value = '';
    else if (field.value == '') field.value = field.defaultValue;
}

function mainmenu(){
$(" #navlist ul ").css({display: "none"}); // Opera Fix
$(" #navlist li").hover(function(){
		$(this).find('ul:first').css({visibility: "visible",display: "none"}).slideDown(0);
		},function(){
		$(this).find('ul:first').css({visibility: "hidden"});
		});
}

 $(document).ready(function(){					
	mainmenu();
});



/* Main Page Functions */
function checksitesearchform() {
    if (document.sitesearchform.Criteria.value == '' || document.sitesearchform.Criteria.value == 'Search site') {
        alert('Please enter your Search Criteria');
        return false;
    }
    else {
        return true;
    }
}

/* Ecommerce */
function addToOrder(optionId,productId) {
    if (eval('document.optionsform.Option' + optionId + '.value') == '') {
        alert('Please enter a Quantity.');
        return false;
    }
    else {
        location.href = '/Scripts/BasketFunctions.asp?ID='+ productId +'&VariantID=' + optionId + '&Quantity=' + eval('document.optionsform.Option' + optionId + '.value');
    }
}

function checkbasket() {
    // Here
}

function confirmBasketDelete(submitstring) {
    if (confirm('Are you sure you want to remove this item from your basket?')) {
        location.href = submitstring;
    }
}

function checklogin() {
    var ftxt = '';

    if (document.login.AccountNumber.value == '' || document.login.AccountNumber.value == 'Username') {
        ftxt += '\n- Please enter your Username.';
    }

    if (document.login.Password.value == '' || document.login.Password.value == 'password') {
        ftxt += '\n- Please enter your Password.';
    }

    if (ftxt !== '') {
        alert('One or more errors were found while submitting this form. The errors found are displayed below.\n' + ftxt + '\n\nPlease correct the above errors and try again.');
        return false;
    }
    else {
        return true;
    }
}

function checkforgottenpassword() {
    var ftxt = '';

    if (isValidEmail(document.forgottenpassword.EmailAddress.value) == false) {
        ftxt += '\n- Please enter your Email Address.';
    }

    if (ftxt !== '') {
        alert('One or more errors were found while submitting this form. The errors found are displayed below.\n' + ftxt + '\n\nPlease correct the above errors and try again.');
        return false;
    }
    else {
        return true;
    }
}


/* Register Form */
function checkregisterform() {
    var ftxt = '';

    if (document.registerform.BillingName.value == '' || document.registerform.BillingName.value == 'Name*') {
        ftxt += '\n- Please enter your Name.';
    }

    if (document.registerform.BillingCompany.value == '' || document.registerform.BillingCompany.value == 'Company Name*') {
        ftxt += '\n- Please enter your Company Name.';
    }

    if (document.registerform.BillingAddress1.value == '' || document.registerform.BillingAddress1.value == 'Address Line1*') {
        ftxt += '\n- Please enter your Address Line 1.';
    }

    if (document.registerform.BillingCity.value == '' || document.registerform.BillingCity.value == 'City*') {
        ftxt += '\n- Please enter your City.';
    }

    if (document.registerform.BillingCounty.value == '' || document.registerform.BillingCounty.value == 'County*') {
        ftxt += '\n- Please enter your County.';
    }

    if (document.registerform.BillingPostcode.value == '' || document.registerform.BillingPostcode.value == 'Post Code*') {
        ftxt += '\n- Please enter your Post Code.';
    }

    if (document.registerform.Position.value == '' || document.registerform.Position.value == 'Position*') {
        ftxt += '\n- Please enter your Position.';
    }

    if (isValidEmail(document.registerform.EmailAddress.value)==false) {
        ftxt += '\n- Please enter your Email Address.';
    }

    if (document.registerform.LandlinePhone.value == '' || document.registerform.LandlinePhone.value == 'Telephone Number*') {
        ftxt += '\n- Please enter your Telephone Number.';
    }

    if (document.registerform.Website.value == '' || document.registerform.Website.value == 'Company Website*') {
        ftxt += '\n- Please enter your Company Website.';
    }

    if (document.registerform.AreaofInterest.value == '' || document.registerform.AreaofInterest.value == 'Area of Interest*') {
        ftxt += '\n- Please enter your Area of Interest.';
    }

    if (document.registerform.DetailsFrom.value == '' || document.registerform.DetailsFrom.value == 'How did you hear about DYNE?*') {
        ftxt += '\n- Please enter how you heard about DYNE.';
    }
    
    if (ftxt !== '') {
        alert('One or more errors were found while submitting this form. The errors found are displayed below.\n' + ftxt + '\n\nPlease correct the above errors and try again.');
        return false;
    }
    else {
        return true;
    }
}

/* Update Form */
function checkupdateform() {
    var ftxt = '';

    if (document.updateform.BillingName.value == '' || document.updateform.BillingName.value == 'Name*') {
        ftxt += '\n- Please enter your Name.';
    }

    if (document.updateform.BillingCompany.value == '' || document.updateform.BillingCompany.value == 'Company Name*') {
        ftxt += '\n- Please enter your Company Name.';
    }

    if (document.updateform.BillingAddress1.value == '' || document.updateform.BillingAddress1.value == 'Address Line1*') {
        ftxt += '\n- Please enter your Address Line 1.';
    }

    if (document.updateform.BillingCity.value == '' || document.updateform.BillingCity.value == 'City*') {
        ftxt += '\n- Please enter your City.';
    }

    if (document.updateform.BillingCounty.value == '' || document.updateform.BillingCounty.value == 'County*') {
        ftxt += '\n- Please enter your County.';
    }

    if (document.updateform.BillingPostcode.value == '' || document.updateform.BillingPostcode.value == 'Post Code*') {
        ftxt += '\n- Please enter your Post Code.';
    }

    if (isValidEmail(document.updateform.EmailAddress.value) == false) {
        ftxt += '\n- Please enter your Email Address.';
    }

    if (document.updateform.LandlinePhone.value == '' || document.updateform.LandlinePhone.value == 'Telephone Number*') {
        ftxt += '\n- Please enter your Telephone Number.';
    }

    if (ftxt !== '') {
        alert('One or more errors were found while submitting this form. The errors found are displayed below.\n' + ftxt + '\n\nPlease correct the above errors and try again.');
        return false;
    }
    else {
        return true;
    }
}

/* Checkout Delivery */
var specifydelivery = false;
function specifyDelivery(theval) {
    var deliveryone = document.getElementById("deliveryone");
    var deliverytwo = document.getElementById("deliverytwo");

    if (theval) {
        specifydelivery = true;
        deliveryone.style.display = 'none';
        deliverytwo.style.display = 'block';
    }
    else {
        specifydelivery = false;
        deliveryone.style.display = 'block';
        deliverytwo.style.display = 'none';
    }
}

function checkfinalcheckout() {
    var ftxt = '';

    //alert(specifydelivery);

    if (specifydelivery) {
        if (document.ordersubmit.Name.value == '') {
            ftxt += '\n- Please enter your Name.';
        }

        if (document.ordersubmit.Company.value == '') {
            ftxt += '\n- Please enter your Company.';
        }

        if (document.ordersubmit.Address1.value == '') {
            ftxt += '\n- Please enter your Address 1.';
        }

        if (document.ordersubmit.City.value == '') {
            ftxt += '\n- Please enter your City.';
        }

        if (document.ordersubmit.County.value == '') {
            ftxt += '\n- Please enter your County.';
        }

        if (document.ordersubmit.Postcode.value == '') {
            ftxt += '\n- Please enter your Postcode.';
        }
    }

    if (ftxt !== '') {
        alert('One or more errors were found while submitting this form. The errors found are displayed below.\n' + ftxt + '\n\nPlease correct the above errors and try again.');
        return false;
    }
    else {
        return true;
    }
}

function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    }
    else {
        window.onload = function() {
            oldonload();
            func();
        }
    }
}

function checkcontactform() {
    var ftxt = '';

    if (document.contactform.Name.value == '' || document.contactform.Name.value == 'Name') {
        ftxt += '\n- Please enter your Name.';
    }

    if (document.contactform.TelephoneNumber.value == '' || document.contactform.TelephoneNumber.value == 'Your telephone number') {
        ftxt += '\n- Please enter your Telephone Number.';
    }

    if (document.contactform.Question.value == '' || document.contactform.Question.value == 'Your question') {
        ftxt += '\n- Please enter your Question.';
    }

    if (ftxt !== '') {
        alert('One or more errors were found while submitting this form. The errors found are displayed below.\n' + ftxt + '\n\nPlease correct the above errors and try again.');
        return false;
    }
    else {
        return true;
    }
}

/* Logout */
function checklogout() {
    if (confirm('Are you sure you want to logout?')) {
        location.href = '/Scripts/AccountHomeFunctions.asp?Logout=True'
    }
}
