
var txtFirstName = "    -First Name\n";
var txtLastName = "    -Last Name\n";
/*var txtCity = "    -City\n";
var txtState = "    -State/Province\n";
var txtZip = "    -Postal Code/Zip Code\n";
var txtCountry = "    -Country\n";*/
var txtEmail = "    -Email Address\n";
var txtConfirmEmail = "    -Confirm Email Address\n";
var txtTitle = "    -Submission title\n";
var txtPhoto = "    -Photo\n";
var txtTerms = "    -Terms and conditions\n";
var txtRequired = "*- indicates required field";
var txtValidate = "The following fields contain missing or invalid information:\n\n";


function ValidateEmailAddress(EmailAddress)
{
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	
	if (filter.test(EmailAddress))
	{
		return true;
	}
	else
	{
		return false;
	}
}

String.prototype.trim=function()
{
	return this.replace(/^\s*|\s*$/g,'');
}

function ValidateForm() {

    switch (document.Form1.hidType.value) {
        case "8":
            txtFirstName = "    -姓\n";
            txtLastName = "    -名\n";
            txtEmail = "    -電子郵件\n";
            txtConfirmEmail = "    - 再確認一次電子郵件\n";
            txtTitle = "    -作品內容\n";
            txtPhoto = "    -相片\n";
            txtTerms = "    -條件\n";
            txtRequired = "*- 必填攔位";
            txtValidate = "下列是必填或無效資訊\n\n";
            break;
        case "9":
            txtFirstName = "    -First NameDE\n";
            txtLastName = "    -Last NameDE\n";
            txtEmail = "    -Email AddressDE\n";
            txtConfirmEmail = "    -Confirm Email AddressDE\n";
            txtTitle = "    -Submission titleDE\n";
            txtPhoto = "    -PhotoDE\n";
            txtTerms = "    -Terms and conditionsDE\n";
            txtRequired = "*- indicates required fieldDE";
            txtValidate = "The following fields contain missing or invalid informationDE:\n\n";
            break;
    }
    
    
	var IsValid = true;
	var ValidationMessage = txtValidate;
	
	if(document.Form1.hidType.value == 4 || document.Form1.hidType.value == 6)
	{
		if(document.Form1.tbCompanyName.value == "")
		{
			IsValid = false;
			ValidationMessage += "    -Company Name\n"
		}
	}
	
	if(document.Form1.tbFirstName.value == "")
	{
		IsValid = false;
		ValidationMessage += txtFirstName
	}
	
	if(document.Form1.tbLastName.value == "")
	{
		IsValid = false;
		ValidationMessage += txtLastName
}
if (document.Form1.tbPhone != null)
	{

	    if (document.Form1.tbPhone.value == "")
	    {
		    IsValid = false;
		    ValidationMessage += "    -Phone Number\n"
	    }
	}

	if (document.Form1.tbShippingAddress1 != null) 
	{
	    if (document.Form1.tbShippingAddress1.value == "") 
	    {
	        IsValid = false;
	        ValidationMessage += "    -Shipping Address 1\n"
	    }
	}

	if (document.Form1.hidType.value != 7 && document.Form1.hidType.value != 8 && document.Form1.hidType.value != 9)
	{   
	    if(document.Form1.tbCity.value == ""){
		    IsValid = false;
		    ValidationMessage += "    -City\n"
		}
	}

	if (document.Form1.hidType.value != 7 && document.Form1.hidType.value != 8 && document.Form1.hidType.value != 9)
	{
	    if(document.Form1.tbState.value == ""){
		    IsValid = false;
		    ValidationMessage += "    -State/Province\n"
		}
	}

	if (document.Form1.tbZip != null) {
	    if (document.Form1.tbZip.value == "") 
	    {
	        IsValid = false;
	        ValidationMessage += "    -Postal Code/Zip Code\n"
	    }
	}

	if (document.Form1.hidType.value != 7 && document.Form1.hidType.value != 8 && document.Form1.hidType.value != 9)
	{
	    if(document.Form1.tbCountry.value == ""){
		    IsValid = false;
		    ValidationMessage += "    -Country\n"
		}
	}
	
	if(document.Form1.tbEmailAddress.value == "")
	{
		IsValid = false;
		ValidationMessage += txtEmail
	}
	else if(!ValidateEmailAddress(document.Form1.tbEmailAddress.value.trim()))
	{
		IsValid = false;
		ValidationMessage += txtEmail
	}
	else if(document.Form1.tbEmailAddress.value != document.Form1.tbConfirmEmailAddress.value)
	{
		IsValid = false;
		ValidationMessage += txtConfirmEmail
	}
	
	if((document.Form1.hidType.value == 4 || document.Form1.hidType.value == 6) && document.Form1.tbSystemPageURL.value == "")
	{
		IsValid = false;
		
		if(document.Form1.hidType.value == 6)
		{
			ValidationMessage += "    -NVIDIA Dedicated URL\n"
		}
		else
		{
			ValidationMessage += "    -System Page URL\n"
		}
	}
	
	if(document.Form1.hidType.value == 4 && document.Form1.tbSystemCost.value == "")
	{
		IsValid = false;
		ValidationMessage += "    -System Cost\n"
	}
	
	if(document.Form1.hidType.value == 4 && document.Form1.tbSystemDescription.value == "")
	{
		IsValid = false;
		ValidationMessage += "    -System Description\n"
	}
	
	if(document.Form1.hidType.value == 2 && document.Form1.tbCLUBSLIMemberNumber.value == "")
	{
		IsValid = false;
		ValidationMessage += "    -CLUB SLI Member Number\n"
    }

    if ((document.Form1.hidType.value == 7 || document.Form1.hidType.value == 8 || document.Form1.hidType.value == 9) && document.Form1.tbAttachmentTitle.value == "") {
        IsValid = false;
        ValidationMessage += txtTitle
    }
	
	if(document.Form1.hidType.value != 1 && document.Form1.hidType.value != 5 && document.Form1.flImage.value == "")
	{
		IsValid = false;
		
		if(document.Form1.hidType.value == 6)
		{
			ValidationMessage += "    -Corporate Logo\n"
		}
		else
		{
		    ValidationMessage += txtPhoto
		}
	}

	if (document.Form1.hidType.value != 1 && document.Form1.hidType.value != 4 && document.Form1.hidType.value != 5 && document.Form1.hidType.value != 6 && document.Form1.hidType.value != 7 && document.Form1.hidType.value != 8 && document.Form1.hidType.value != 9 && document.Form1.flMedia.value == "")
	{
		IsValid = false;
		ValidationMessage += "    -Media\n"
	}

	if (document.Form1.hidType.value == 5 && document.Form1.hidType.value != 7 && document.Form1.hidType.value != 8 && document.Form1.hidType.value != 9 && document.Form1.flVideo.value == "")
	{
		IsValid = false;
		ValidationMessage += "    -Video\n"
	}
	
	if(document.Form1.hidType.value == 1 && (document.Form1.flImage.value != "" || document.Form1.flMedia.value != ""))
	{
		if(document.Form1.tbAttachmentDescription.value == "")
		{
			IsValid = false;
			ValidationMessage += "    -Attachment Description\n"
		}
	}
	
	if(document.Form1.hidType.value == 1 && document.Form1.flImage.value == "" && document.Form1.flMedia.value == "" && document.Form1.tbTestimonial.value == "")
	{
		IsValid = false;
		ValidationMessage += "    -Attachment(s) or Testimonial\n"
	}
	
	if(document.Form1.chkAgreement.checked != true)
	{
		IsValid = false;
		ValidationMessage += txtTerms
	}
	
	if(!IsValid)
	{
		alert(ValidationMessage);
	}
	else
	{
		document.Form1.btnUploadMedia_disabled.style.display = "";
		document.Form1.btnUploadMedia.style.display = "none";
	}
	
	return IsValid;
}

window.onload = function() {
    addAsterisks();
}

function addAsterisks() {
    if (document.Form1.hidType.value == 7 || document.Form1.hidType.value == 8 || document.Form1.hidType.value == 9) {
        document.getElementById('asterisk1').innerHTML = '*';
        document.getElementById('asterisk1').style.color = 'red';
        document.getElementById('asterisk2').innerHTML = '*';
        document.getElementById('asterisk2').style.color = 'red';
        document.getElementById('asterisk3').innerHTML = '*';
        document.getElementById('asterisk3').style.color = 'red';
        document.getElementById('asterisk4').innerHTML = '*';
        document.getElementById('asterisk4').style.color = 'red';
        document.getElementById('asterisk5').innerHTML = '*';
        document.getElementById('asterisk5').style.color = 'red';
        document.getElementById('asterisk6').innerHTML = '*';
        document.getElementById('asterisk6').style.color = 'red';
        document.getElementById('trIsRequired').style.display = '';
        document.getElementById('isRequiredField').style.color = 'red';
    }

    switch (document.Form1.hidType.value) {
        case "7":
            document.getElementById('isRequiredField').innerHTML = txtRequired;
            break;
        case "8":
            txtRequired = "*- 必填";
            document.getElementById('isRequiredField').innerHTML = txtRequired;
            break;
        case "9":
            txtRequired = "*- indicates required fieldDE";
            document.getElementById('isRequiredField').innerHTML = txtRequired;
            break;
    }
}