﻿// JScript File
function ShowMenu(thisname,name,img1,img2){
    var objname = document.getElementById(thisname);
    var obj = document.getElementById(name);
    if(obj.style.display=="none"){
        obj.style.display = "block";
        objname.src=img2;
    }else{
        obj.style.display = "none";
        objname.src=img1;
    }
}

function openwindow(url,width,height)
{
	var top=(screen.height - height)/2;
	var left=(screen.width - width)/2;
	
	window.open(url,"","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no,left=0, top=0, width=" + width + ", height=" + height)
}

function checkEmail(str) 
{
    var at="@"
    var dot="."
    var lat=str.indexOf(at)
    var lstr=str.length
    var ldot=str.indexOf(dot)
    if (str.indexOf(at)==-1){
        return false
    }

    if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
        return false
    }

    if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
        return false
    }

    if (str.indexOf(at,(lat+1))!=-1){
        return false
    }

    if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
        return false
    }

    if (str.indexOf(dot,(lat+2))==-1){
        return false
    }

    if (str.indexOf(" ")!=-1){
        return false
    }
    return true					
}

function check_catalogue_vn()
{
    if (document.aspnetForm.optType.value=='')
	{
	    alert('Bạn cần chọn loại xe!');
	    document.aspnetForm.optType.focus();
	    return false;
	}
	
	if (document.aspnetForm.ctl00$ContentPlaceHolder1$txtCompany.value=='')
	{
	    alert('Bạn cần nhập địa chỉ công ty!');
	    document.aspnetForm.ctl00$ContentPlaceHolder1$txtCompany.focus();
	    return false;
	}
	
	if (document.aspnetForm.ctl00$ContentPlaceHolder1$txtFullname.value=='')
	{
	    alert('Bạn cần nhập họ và tên!');
	    document.aspnetForm.ctl00$ContentPlaceHolder1$txtFullname.focus();
	    return false;
	}
	
	if (document.aspnetForm.optAge.value=='')
	{
	    alert('Bạn cần chọn độ tuổi!');
	    document.aspnetForm.optAge.focus();
	    return false;
	}
	
	if (document.aspnetForm.optSex.value=='')
	{
	    alert('Bạn cần chọn giới tính!');
	    document.aspnetForm.optSex.focus();
	    return false;
	}
	
	if (document.aspnetForm.ctl00$ContentPlaceHolder1$txtEmail.value=='')
	{
	    alert('Bạn cần nhập địa chỉ email!');
	    document.aspnetForm.ctl00$ContentPlaceHolder1$txtEmail.focus();
	    return false;
	}
	else	
	    if(checkEmail(document.aspnetForm.ctl00$ContentPlaceHolder1$txtEmail.value)==false)
	    {
	        alert('Sai địa chỉ email!');
	        document.aspnetForm.ctl00$ContentPlaceHolder1$txtEmail.focus();
	        return false;
        }
    
    if (document.aspnetForm.ctl00$ContentPlaceHolder1$txtPhone1.value=='' && document.aspnetForm.ctl00$ContentPlaceHolder1$txtPhone2.value=='' && document.aspnetForm.ctl00$ContentPlaceHolder1$txtPhone3.value=='')
	{
	    alert('Bạn cần nhập điện thoại liên hệ!');
	    document.aspnetForm.ctl00$ContentPlaceHolder1$txtPhone1.focus();
	    return false;
	}
	
	if (document.aspnetForm.ctl00$ContentPlaceHolder1$txtAddress.value=='')
	{
	    alert('Bạn cần nhập địa chỉ liên lạc!');
	    document.aspnetForm.ctl00$ContentPlaceHolder1$txtAddress.focus();
	    return false;
	}
	
	if (document.aspnetForm.ctl00$ContentPlaceHolder1$txtStreet.value=='')
	{
	    alert('Bạn cần nhập địa chỉ tỉnh/thành phố!');
	    document.aspnetForm.ctl00$ContentPlaceHolder1$txtStreet.focus();
	    return false;
	}
	
    return true;
}

function check_catalogue_en()
{
    if (document.aspnetForm.optType.value=='')
	{
	    alert('Please select Car!');
	    document.aspnetForm.optType.focus();
	    return false;
	}
	
	if (document.aspnetForm.ctl00$ContentPlaceHolder1$txtCompany.value=='')
	{
	    alert('Please input company name!');
	    document.aspnetForm.ctl00$ContentPlaceHolder1$txtCompany.focus();
	    return false;
	}
	
	if (document.aspnetForm.ctl00$ContentPlaceHolder1$txtFullname.value=='')
	{
	    alert('Please input fullname!');
	    document.aspnetForm.ctl00$ContentPlaceHolder1$txtFullname.focus();
	    return false;
	}
	
	if (document.aspnetForm.optAge.value=='')
	{
	    alert('Please select!');
	    document.aspnetForm.optAge.focus();
	    return false;
	}
	
	if (document.aspnetForm.optSex.value=='')
	{
	    alert('Please select!');
	    document.aspnetForm.optSex.focus();
	    return false;
	}
	
	if (document.aspnetForm.ctl00$ContentPlaceHolder1$txtEmail.value=='')
	{
	    alert('Email!');
	    document.aspnetForm.ctl00$ContentPlaceHolder1$txtEmail.focus();
	    return false;
	}
	else	
	    if(checkEmail(document.aspnetForm.ctl00$ContentPlaceHolder1$txtEmail.value)==false)
	    {
	        alert('Error email!');
	        document.aspnetForm.ctl00$ContentPlaceHolder1$txtEmail.focus();
	        return false;
        }
    
    if (document.aspnetForm.ctl00$ContentPlaceHolder1$txtPhone1.value=='' && document.aspnetForm.ctl00$ContentPlaceHolder1$txtPhone2.value=='' && document.aspnetForm.ctl00$ContentPlaceHolder1$txtPhone3.value=='')
	{
	    alert('Phone number!');
	    document.aspnetForm.ctl00$ContentPlaceHolder1$txtPhone1.focus();
	    return false;
	}
	
	if (document.aspnetForm.ctl00$ContentPlaceHolder1$txtAddress.value=='')
	{
	    alert('Address!');
	    document.aspnetForm.ctl00$ContentPlaceHolder1$txtAddress.focus();
	    return false;
	}
	
	if (document.aspnetForm.ctl00$ContentPlaceHolder1$txtStreet.value=='')
	{
	    alert('Street!');
	    document.aspnetForm.ctl00$ContentPlaceHolder1$txtStreet.focus();
	    return false;
	}
	
    return true;
}

function check_faqs_vn()
{
    if (document.aspnetForm.ctl00$ContentPlaceHolder1$txtFullname.value=='')
	{
	    alert('Bạn cần nhập họ và tên!');
	    document.aspnetForm.ctl00$ContentPlaceHolder1$txtFullname.focus();
	    return false;
	}
	
	if (document.aspnetForm.ctl00$ContentPlaceHolder1$txtEmail.value=='')
	{
	    alert('Bạn cần nhập địa chỉ email!');
	    document.aspnetForm.ctl00$ContentPlaceHolder1$txtEmail.focus();
	    return false;
	}
	else	
	    if(checkEmail(document.aspnetForm.ctl00$ContentPlaceHolder1$txtEmail.value)==false)
	    {
	        alert('Sai địa chỉ email!');
	        document.aspnetForm.ctl00$ContentPlaceHolder1$txtEmail.focus();
	        return false;
        }
    
    if (document.aspnetForm.ctl00$ContentPlaceHolder1$txtContent.value=='')
	{
	    alert('Bạn cần nhập nội dung câu hỏi!');
	    document.aspnetForm.ctl00$ContentPlaceHolder1$txtContent.focus();
	    return false;
	}   
    return true;
}