﻿
        function autoShowHideText(obj)
        {
            if(obj.id == "txtNameHome")
            {
                if(obj.value == "Your Name")
                {
                    obj.value = "";
                    obj.style.color = "#000000";
                    return;
                }
                if(obj.value == "")
                {
                    obj.style.color = "#999999";
                    obj.value = "Your Name";
                    return;
                }
            }
            
            if(obj.id == "txtCompanyNameHome")
            {
                if(obj.value == "Company Name")
                {
                    obj.value = "";
                    obj.style.color = "#000000";
                    return;
                }
                if(obj.value == "")
                {
                    obj.style.color = "#999999";
                    obj.value = "Company Name";
                    return;
                }
            }
            
            if(obj.id == "txtEmailHome")
            {
                if(obj.value == "Your Email")
                {
                    obj.value = "";
                    obj.style.color = "#000000";
                    return;
                }
                if(obj.value == "")
                {
                    obj.style.color = "#999999";
                    obj.value = "Your Email";
                    return;
                }
            }
            
            if(obj.id == "txtPhoneNoHome")
            {
                if(obj.value == "Your Tel./Mob. No.")
                {
                    obj.value = "";
                    obj.style.color = "#000000";
                    return;
                }
                if(obj.value == "")
                {
                    obj.style.color = "#999999";
                    obj.value = "Your Tel./Mob. No.";
                    return;
                }
            }
            
            
            
            
        }


        function chkPatternNew(obj,fieldName,pattern)
        {
                    var filter  = pattern;
                    if(!filter.test(obj.value))
                    {
                      return false;
                    }
                    else
                    {
                      
                      return true;
                    }
        }
        function chkEmptyNew(obj,fieldName)
        {
           if(obj.value == "")
                {
                    return false;
                 }
                 else
                 {
                    return true;
                 }
        }
        function chkLengthNew(obj,fieldName,minLen,maxLen)
        {
                    var min = parseInt(minLen);
                    var max = parseInt(maxLen);
                    
                    if(obj.value.length < min || obj.value.length > max)
                    {
                      return false;
                    }
                    else
                    {
                      return true;
                    }
              }

              function CreateXmlHttpRequest() {
                  try {
                      myrequest = new XMLHttpRequest();
                  } catch (trymicrosoft) {
                      try {
                          myrequest = new ActiveXObject("Msxml2.XMLHTTP");
                      } catch (othermicrosoft) {
                          try {
                              myrequest = new ActiveXObject("Microsoft.XMLHTTP");
                          } catch (failed) {
                              myrequest = false;
                          }
                      }
                  }

                  if (!myrequest)
                      alert("Error initializing XMLHttpRequest!");

                  request = myrequest;
              }
        function ValidateMeetingHome()
        {
            var obj = document.getElementById("txtNameHome");
                var flag = true;
                var paramName = "";
                if(obj.value == "" || obj.value == "Your Name")
                {
                    alert('Please provide your name');
                    obj.focus();
                    //document.getElementById("errorDiv").innerHTML = "Please provide your name";
                    paramName = "txtNameHome";
                    return false;
                    flag = false;
                }
                else if(!chkPatternNew(obj,"Name",/^\s*([A-Z]|[a-z])/)) {


                    alert('Please provide proper name');
                    obj.focus();
                   // document.getElementById("errorDiv").innerHTML = "Please provide proper name.";
                    paramName = "txtNameHome";
                    return false;
                    flag = false;
                }
                else if(obj.value.length > 49)
                {
                    alert('Name not exceed 50 charaters');
                    obj.focus();
                    //document.getElementById("errorDiv").innerHTML = "Name not exceed 50 charaters.";
                    paramName = "txtNameHome";
                    return false;
                    flag = false;
                }

                obj = document.getElementById("txtCompanyNameHome");
                if(obj.value == "" || obj.value == "Company Name")
                {
                    if(paramName == "") {
                        alert('Please provide your company name');
                        paramName = "txtCompanyNameHome";
                        obj.focus();
                        return false;
                      //  document.getElementById("errorDiv").innerHTML = "Please provide your company name";
                    }
                    flag = false;
                }
                else if(obj.value.length > 500)
                {
                    if(paramName == "") {
                        alert('Company name can not exceed 500 charaters.');
                        paramName = "txtCompanyNameHome";
                        obj.focus();
                        return false;
                        //document.getElementById("errorDiv").innerHTML = "Company name can not exceed 500 charaters.";
                    }
                    flag = false;
                }

                var obj = document.getElementById("txtEmailHome");
                if(obj.value == "" || obj.value == "Your Email")
                {
                    if(paramName == "")
                    {
                        paramName = "txtEmailHome";
                        alert('Please provide your email address');
                        obj.focus();
                        return false;
                        //document.getElementById("errorDiv").innerHTML = "Please provide your email address";
                    }
                    flag = false;
                }
                else if(!chkPatternNew(obj,"email address",/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/))
                {
                    if(paramName == "")
                    {
                        paramName = "txtEmailHome";
                        alert('Please provide proper email address.');
                        obj.focus();
                        return false;
                        //document.getElementById("errorDiv").innerHTML = "Please provide proper email address.";
                    }
                    flag = false;
                }
                else if(obj.value.length > 500)
                {
                    if(paramName == "")
                    {
                        paramName = "txtEmailHome";
                        alert('Email address can not exceed 500 charaters.');
                        obj.focus();
                        return false;
                        //document.getElementById("errorDiv").innerHTML = "Email address can not exceed 500 charaters.";
                    }
                    flag = false;
                }

                var obj = document.getElementById("txtPhoneNoHome");
                if(obj.value == "" || obj.value == "Your Tel./Mob. No.")
                {
                    if(paramName == "")
                    {
                        paramName = "txtPhoneNoHome";
                        alert('Please provide your Tel./Mob. No.');
                        obj.focus();
                        return false;
                        //document.getElementById("errorDiv").innerHTML = "Please provide your Tel./Mob. No.";
                    }
                    flag = false;
                }
                else if(obj.value.length > 500)
                {
                    if(paramName == "")
                    {
                        paramName = "txtPhoneNoHome";
                        alert('Tel./Mob. No. cant not exceed 500 charaters.');
                        obj.focus();
                        return false;
                        //document.getElementById("errorDiv").innerHTML = " Tel./Mob. No. cant not exceed 500 charaters.";
                    }
                    flag = false;
                }


                obj = document.getElementById('ddlSource');
                if(obj.options[obj.options.selectedIndex].value == "")
                {
                   if(paramName == "")
                    {
                        paramName = "ddlSource";
                        alert('Select where did you hear about us?');
                        obj.focus();
                        return false;
//                        document.getElementById("errorDiv").innerHTML = "";
//                        document.getElementById("errorDiv").innerHTML = "Select where did you hear about us?";
                    }
                    flag = false;
                 }
                       
               if(obj.options[obj.options.selectedIndex].value == "Other Source")
                {
//                    document.getElementById("ddlSource").style.display = "none";
//                    document.getElementById("txtOtherSource").style.display = "block";
                    if (document.getElementById("txtotherSource").value == "")
                    {
                        if(paramName == "")
                        {
                            paramName = "txtOtherSource";
                            alert('Provide where did you hear about us?');
                            obj.focus();
                            return false;
//                            document.getElementById("errorDiv").innerHTML = "Provide where did you hear about us?";
                        }
                        flag = false;
                    }
               }
                
                if(!flag)
                {
//                    document.getElementById("m").style.paddingBottom = "64px";
//                    document.getElementById("errorDiv").style.display = "block";
//                    document.getElementById(paramName).focus();
                }
                else
                {
//                    document.getElementById("m").style.paddingBottom = "51px";
//                    document.getElementById("errorDiv").style.display = "none";
                    sendEmailRequest('/RequestMeetingFormPost.aspx');
                }
                 return false;
        }


        function showLoading()
        {
            document.getElementById("formDiv").style.display = "none";
            document.getElementById("loading").style.display = "block";
        }

        function sendEmailRequest(url)
        {
                //var txt 
                var txtNameHome = document.getElementById('txtNameHome').value;        
                var txtCompanyNameHome = document.getElementById('txtCompanyNameHome').value;
                var txtEmailHome = document.getElementById('txtEmailHome').value;
                var txtPhoneNoHome = document.getElementById('txtPhoneNoHome').value;
                var ddlSource = document.getElementById('ddlSource');
                var txtSource = document.getElementById('txtotherSource');
                var source = "";
                if (ddlSource.options[ddlSource.options.selectedIndex].value != "Other Source") 
                {
                     source = ddlSource.options[ddlSource.options.selectedIndex].value;
                 }
                  else 
                {
                     source = txtSource.value;
                }
                CreateXmlHttpRequest();
                url += "?type=request.send&txtNameHome=" + txtNameHome + "&txtCompanyNameHome=" + txtCompanyNameHome + "&txtEmailHome=" + txtEmailHome + "&txtPhoneNoHome=" + txtPhoneNoHome + "&ddlSource=" + source;
                showLoading();                
                request.onreadystatechange = emailSendRequest;
                request.open("GET", url, true);
                request.send(null);
        }

        function disableLoading()
        {
            document.getElementById("formDiv").style.display = "block";
            document.getElementById("loading").style.display = "none";
        }

        function emailSendRequest() {
            if (request.readyState == 4) {
                if (request.status == 200) {
                    if (request.responseText == 'unauthorized') {
                        // document.getElementById("m").style.paddingBottom = "32px";
                        //document.getElementById("errorDiv").style.innerHTML = "Please provide required details";
                        //document.getElementById("errorDiv").style.display = "block";
                        //disableLoading();
                        return;
                    }
                    else {
                        disableLoading();
                        ResetDivRequest('Thanks');
                        //      document.getElementById("m").style.paddingBottom = "14px";
                        //     document.getElementById("errorDiv").style.display = "none";
                    }
                    //                   
                    
                }
                else {
                    //  alert(request.status);
                }
            }
        }

            function ResetDivRequest(whichone)
            {
                if(whichone == "Thanks")
                {
                    var requestDiv = document.getElementById('formDiv');
                    requestDiv.innerHTML = "";
                    requestDiv.innerHTML = "<div class='clear'></div><div style='color:#fff;height:125px;margin:0px;padding:0px;'>Thank you.<br/><br/>Your details have been sent to Traffic Online Media Solutions. We will be back in-touch shortly to discuss the details of your request.<br/><br/></div>";
					requestDiv.innerHTML += "<script type='text/javascript'>var google_conversion_id = 991129727;var google_conversion_language = 'en';var google_conversion_format = '2';var google_conversion_color = 'ffffff';var google_conversion_label = 'rR3tCPGerAIQ_-DN2AM';var google_conversion_value = 0;</script>";
                    requestDiv.innerHTML += "<script type='text/javascript' src='http://www.googleadservices.com/pagead/conversion.js'></script>";
                    requestDiv.innerHTML += "<noscript><div style='display:inline;'><img height='1' width='1' style='border-style:none;' alt='' src='http://www.googleadservices.com/pagead/conversion/991129727/?label=rR3tCPGerAIQ_-DN2AM&amp;guid=ON&amp;script=0'/></div></noscript>";
					requestDiv.style.padding = "0px 0px 16px 0px";
		         }
            }
            
                
                
 function ChangeSource(obj)
{
    if(obj.options[obj.options.selectedIndex].value == "Other Source")
   {
         document.getElementById("ddlSource").style.display = "none";
         document.getElementById("txtOtherSource").style.display = "block";
         document.getElementById("txtOtherSource").focus();
   }
   else
   {
        document.getElementById("txtOtherSource").style.display = "none";
        document.getElementById("ddlSource").style.display = "block";
        document.getElementById("ddlSource").focus();
   }
}
