﻿    // JScript File

    function ShowPop(id)
    {
        document.getElementById(id).style.visibility = "visible";
    }

    function HidePop(id)
    {
        document.getElementById(id).style.visibility = "hidden";
    }
    
        function OpenProductsAndServicesWindow() {
        var newwindow = window.open('http://www.videohometours.com/services.html', 'Products','width=670,height=500,toolbar=0,menubar=0,scrollbars=1,resizable=1');
    }
    
    function MM_preloadImages() { //v3.0
      var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
        var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
        if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
    }

    function MM_findObj(n, d) { //v4.01
      var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
        d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
      if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
      for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
      if(!x && d.getElementById) x=d.getElementById(n); return x;
    }

    function MM_swapImage() { //v3.0
      var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
       if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
    }

    function MM_swapImgRestore() { //v3.0
      var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
    }

    function MM_showHideLayers() 
    { //v6.0
        var i,p,v,obj,args=MM_showHideLayers.arguments;
        for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
        if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
        obj.visibility=v; }
    }
    
    function MM_reloadPage(init) 
    {  //reloads the window if Nav4 resized
        if (init==true) with (navigator) {
            if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
                document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; 
            }
        }
        else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
    }

    function OpenProductsAndServicesWindow() {
        var newwindow = window.open('http://www.videohometours.com/services.html', 'Products','width=670,height=500,toolbar=0,menubar=0,scrollbars=1,resizable=1');
    }

    function OpenPayAtCloseWindow() {
        var newwindow = window.open('arvida_pac.htm', 'PayAtClose','width=440,height=400,toolbar=0,menubar=0,scrollbars=1,resizable=1');
    }

    function open1() {
        popup = window.open('http://www.vht.com/grandtour','fulltext','toolbar=no,menubar=no,location=no,directories=no,status=no,scrollbars=no,resizable=no,copyhistory=no,width=775,height=610');     
        if (popup != null) {
            if (popup.opener == null) {
                popup.opener = self;
            }
            popup.location.href = 'http://www.vht.com/grandtour';
        }
    }

    function open2() {
        popup = window.open('http://tours4.vht.com/vt/std/vhttour.aspx?ListingID=1117603','fulltext','toolbar=no,menubar=no,location=no,directories=no,status=no,scrollbars=no,resizable=no,copyhistory=no,width=675,height=600');     
        if (popup != null) {
            if (popup.opener == null) {
                popup.opener = self;
            }
            popup.location.href = 'http://tours4.vht.com/vt/std/vhttour.aspx?ListingID=1117603';                       
        }
    }
    
    function open3() {
        popup = window.open('http://tours3.vht.com/vt/std/vhttour_wmp.aspx?ListingID=1055603','fulltext','toolbar=no,menubar=no,location=no,directories=no,status=no,scrollbars=no,resizable=no,copyhistory=no,width=600,height=620');     
        if (popup != null) {
            if (popup.opener == null) {
                popup.opener = self;
            }
            popup.location.href = 'http://tours4.vht.com/vt/std/vhttour.aspx?ListingID=1117605';
        }
    }
    
    function open4() {
        popup = window.open('http://tours4.vht.com/vt/std/vhttour.aspx?ListingID=1117607','fulltext','toolbar=no,menubar=no,location=no,directories=no,status=no,scrollbars=no,resizable=no,copyhistory=no,width=675,height=600');     
        if (popup != null) {
            if (popup.opener == null) {
                popup.opener = self;
            }
            popup.location.href = 'http://tours4.vht.com/vt/std/vhttour.aspx?ListingID=1117607';
        }
    }

    function SetQueryFields() 
    {
        document.FORMA.rowguid.value = getQueryVariable('rowguid');
        document.FORMA.AgentFirstName.value = getQueryVariable('AgentFirstName');
        document.FORMA.AgentLastName.value = getQueryVariable('AgentLastName');
        document.FORMA.AgentEmail.value = getQueryVariable('AgentEmail');
        if (getQueryVariable('CompanyName') != '' ) {
           document.FORMA.CompanyName.value = getQueryVariable('CompanyName');
        }
        document.FORMA.OfficeAddress1.value = getQueryVariable('OfficeAddress1');
        document.FORMA.OfficeCity.value = getQueryVariable('OfficeCity');
        document.FORMA.OfficeState.value = getQueryVariable('OfficeState');
        document.FORMA.OfficeZip.value = getQueryVariable('OfficeZip');
        document.FORMA.Phone1.value = getQueryVariable('Phone1');
        document.FORMA.Phone2.value = getQueryVariable('Phone2');
        document.FORMA.Phone3.value = getQueryVariable('Phone3');
                
        var elePropertyID1 = document.getElementById('id');
        var elePropertyID2 = document.getElementById('id2');       
        var elePropertyAddress = document.getElementById('PropertyAddress1');       
        var elePropertyAddress2 = document.getElementById('PropertyAddress2');       
        var elePropertyCity = document.getElementById('PropertyCity');       
        var elePropertyState = document.getElementById('PropertyState');       
        var elePropertyZip = document.getElementById('PropertyZip');       
        var elePropertyBeds = document.getElementById('beds');       
        var elePropertyBaths = document.getElementById('baths');       
        var elePropertyPrice = document.getElementById('price');       
        var elePropertyType = document.getElementById('PropertyType');       
        var elePropertyCommunity = document.getElementById('commname');       
        var elePropertyComments = document.getElementById('comments');       
        var eleAddlComments = document.getElementById('AddlComments');       

        if (elePropertyID1 != null) {
            elePropertyID1.value = getQueryVariable('PropertyID1');
        }
        
        if (elePropertyID2 != null) {
            elePropertyID2.value = getQueryVariable('PropertyID2');
        }
        
        if (elePropertyAddress != null) {
            elePropertyAddress.value = getQueryVariable('PropertyAddress');
        }
        
        if (elePropertyAddress2 != null) {
            elePropertyAddress2.value = getQueryVariable('PropertyUnit');
        }
        
        if (elePropertyCity != null) {
            elePropertyCity.value = getQueryVariable('PropertyCity');
        }
        
        if (elePropertyState != null) {
            elePropertyState.value = getQueryVariable('PropertyState');
        }
        
        if (elePropertyZip != null) {
            elePropertyZip.value = getQueryVariable('PropertyZip');
        }
        
        if (elePropertyBeds != null) {
            elePropertyBeds.value = getQueryVariable('PropertyBeds');
        }

        if (elePropertyBaths != null) {
            elePropertyBaths.value = getQueryVariable('PropertyBaths');
        }
        
        if (elePropertyPrice != null) {
            elePropertyPrice.value = getQueryVariable('PropertyListPrice');
        }
        
        if (elePropertyType != null) {
            elePropertyType.value = getQueryVariable('PropertyType');
        }
        
        if (elePropertyCommunity != null) {
            elePropertyCommunity.value = getQueryVariable('PropertyDevelopment');
        }
        
        if (elePropertyComments != null) {
            elePropertyComments.value = getQueryVariable('PropertyNotes');
        }
        
        if (eleAddlComments != null) {
            eleAddlComments.value = getQueryVariable('AdditionalNotes');
        }
    }

    function getQueryVariable(variable) {
        var query = window.location.search.substring(1);
        var vars = query.split("&");
        for (var i=0;i<vars.length;i++) {
            var pair = vars[i].split("=");
            if (pair[0] == variable) {
                return unescape(pair[1]);
            }
        } 
        return '';
        alert('Query Variable ' + variable + ' not found');
        <!-- alert('Query Variable ' + variable + ' not found'); -->   
    }    
    
    function ValidateCCOrderForm() {  
        if ((document.FORMA.optCC_BillMyCC.checked == false)
             && (document.FORMA.optCC_EnterCC.checked == false)
             && (document.FORMA.optCC_BillMyOfficeCC.checked == false)) {
            alert("At least one billing option must be selected.");
            document.FORMA.optCC_BillMyCC.focus();
        }        
        else {
            ValidateOrderForm();
        }
    }
    
    function ValidateCC2OrderForm() {  
        if ((document.FORMA.optCC_BillMyCC.checked == false)
             && (document.FORMA.optCC_EnterCC.checked == false)) {
            alert("At least one billing option must be selected.");
            document.FORMA.optCC_BillMyCC.focus();
        }        
        else {
            ValidateOrderForm();
        }
    }

    function ValidateOrderForm() {

        txt=document.FORMA.AgentEmail.value;
        
        // Validate Agent First Name.
        if (document.FORMA.AgentFirstName.value.length == 0) {
            alert("Please complete the First Name field.");
            document.FORMA.AgentFirstName.focus();
        }
        else if (document.FORMA.AgentFirstName.value.length < 1) {
            alert("First Name must contain at least 1 character.");
            document.FORMA.AgentFirstName.focus();
        }
        else if (document.FORMA.AgentFirstName.value.length > 50) {
            alert("First Name cannot be greater than 50 characters.");
            document.FORMA.AgentFirstName.focus();
        }
        
        // Validate Agent Last Name.
        else if (document.FORMA.AgentLastName.value.length == 0) {
            alert("Please complete the Last Name field.");
            document.FORMA.AgentLastName.focus();
        }
        else if (document.FORMA.AgentLastName.value.length < 1) {
            alert("Last Name must contain at least 1 character.");
            document.FORMA.AgentLastName.focus();
        }
        else if (document.FORMA.AgentLastName.value.length > 50) {
            alert("Last Name cannot be greater than 50 characters.");
            document.FORMA.AgentLastName.focus();
        }
        
        // Validate Email Address.
        else if (document.FORMA.AgentEmail.value.length == 0) {
            alert("Please complete the e-mail address field.");
            document.FORMA.AgentEmail.focus();
        }
        else if (document.FORMA.AgentEmail.value.length < 2) {
            alert("Agent Email must contain at least 2 characters.");
            document.FORMA.AgentLastName.focus();
        }
        else if (document.FORMA.AgentEmail.value.length > 100) {
            alert("Agent Email cannot be greater than 100 characters.");
            document.FORMA.AgentLastName.focus();
        }        
        /* @ sign test */
        else if (txt.indexOf("@")<2) {
            alert("Please enter a valid Email Address");
            document.FORMA.AgentEmail.focus()
        }
        
        // Validate Company Name.        
        else if (document.FORMA.CompanyName.value.length == 0) {
            alert("Please complete the Company Name field.");
            document.FORMA.AgentLastName.focus();
        }
        else if (document.FORMA.CompanyName.value.length < 2) {
            alert("Company Name must contain at least 2 characters.");
            document.FORMA.AgentLastName.focus();
        }
        else if (document.FORMA.CompanyName.value.length > 100) {
            alert("Company Name cannot be greater than 100 characters.");
            document.FORMA.AgentLastName.focus();
        }
        
        // Validate Street Address.
        else if (document.FORMA.PropertyAddress1.value.length == 0) {
            alert("Please complete the Street Address field.");
            document.FORMA.PropertyAddress1.focus();
        }
        else if (document.FORMA.PropertyAddress1.value.length < 2) {
            alert("Street Address must contain at least 2 characters.");
            document.FORMA.PropertyAddress1.focus();
        }
        else if (document.FORMA.PropertyAddress1.value.length > 100) {
            alert("Street Address cannot be greater than 100 characters.");
            document.FORMA.PropertyAddress1.focus();
        }
        
        // Validate City.
        else if (document.FORMA.PropertyCity.value.length == 0) {
            alert("Please complete the City field.");
            document.FORMA.PropertyCity.focus();
        }
        else if (document.FORMA.PropertyCity.value.length < 1) {
            alert("Property City must contain at least 1 character.");
            document.FORMA.PropertyCity.focus();
        }
        else if (document.FORMA.PropertyCity.value.length > 50) {
            alert("Property City cannot be greater than 50 characters.");
            document.FORMA.PropertyCity.focus();
        }
               
        // Validate State.
        else if (document.FORMA.PropertyState.value.length == 0) {
            alert("Please complete the State field.");
            document.FORMA.PropertyState.focus();
        }
        else if (document.FORMA.PropertyState.value.length < 2) {
            alert("Property State must contain at least 2 characters.");
            document.FORMA.PropertyState.focus();
        }
        else if (document.FORMA.PropertyState.value.length > 2) {
            alert("Property State cannot be greater than 2 characters.");
            document.FORMA.PropertyState.focus();
        }
        else if (ValidState(document.FORMA.PropertyState.value) == false) {
            alert("Please enter a valid state abbreviation.");
            document.FORMA.PropertyState.focus();
        }
        
        // Validate Zip Code.
        else if (document.FORMA.PropertyZip.value.length == 0) {
            alert("Please complete the Zip Code field.");
            document.FORMA.PropertyZip.focus();
        }
        else if (document.FORMA.PropertyZip.value.length < 5) {
            alert("Zip Code must contain at least 5 characters.");
            document.FORMA.PropertyZip.focus();
        }
        else if (document.FORMA.PropertyZip.value.length > 7) {
            alert("Zip Code cannot be greater than 7 characters.");
            document.FORMA.PropertyZip.focus();
        }
        
        // Submit form if all is good.
        else {
            document.FORMA.submit();
        }
        
        // Make sure a state is valid.
        function ValidState(sstate) {
            sstates = "wa|or|ca|ak|nv|id|ut|az|hi|mt|wy|" +
		            "co|nm|nd|sd|ne|ks|ok|tx|mn|ia|mo|" +
		            "ar|la|wi|il|ms|mi|in|ky|tn|al|fl|" +
		            "ga|sc|nc|oh|wv|va|pa|ny|vt|me|nh|" +
		            "ma|ri|ct|nj|de|md|dc|" +
					"ab|bc|mb|nb|nf|ns|nt|nu|on|pe|qc|sk|yt|";

            if (sstates.indexOf(sstate.toLowerCase() + "|") > -1) {
                return true;
            }

            return false;
        }
        
    }
    
    function ValidateYourTourOrderForm() {
        var pkgCnt = 0;  
        if (document.FORMA.PROD296.checked == true) {
            pkgCnt = pkgCnt + 1;
            }
        if (document.FORMA.PROD299.checked == true) {
            pkgCnt = pkgCnt + 1;
            }
        if (document.FORMA.PROD319.checked == true) {
            pkgCnt = pkgCnt + 1;
            }
        if (document.FORMA.PROD321.checked == true) {
            pkgCnt = pkgCnt + 1;
            }
        if (document.FORMA.PROD320.checked == true) {
            pkgCnt = pkgCnt + 1;
            }
        if (document.FORMA.PROD322.checked == true) {
            pkgCnt = pkgCnt + 1;
            }
            
        if (pkgCnt > 1) {
            alert("Please select only one YourTOUR option.");
        }
        else if (pkgCnt < 1) {
            alert("Please select at least one YourTOUR option.");
        }
        else {
            ValidateOrderForm();
        }
    }
