﻿
        function autoHide(obj)
        {
            if(obj.id == "Name")
            {
                if(obj.value == "Your Name")
                {
                    obj.value = "";
                    obj.style.fontStyle = "normal";
                    obj.style.color = "#000000";
                    return;
                }
                if(obj.value == "")
                {
                    obj.value = "Your Name";
                    obj.style.fontStyle = "italic";
                    obj.style.color = "#CCCCCC";
                    return;
                }
            }
            
            if(obj.id == "Email")
            {
                if(obj.value == "Your Email")
                {
                    obj.value = "";
                    obj.style.fontStyle = "normal";
                    obj.style.color = "#000000";
                    return;
                }
                if(obj.value == "")
                {
                    obj.value = "Your Email";
                    obj.style.fontStyle = "italic";
                    obj.style.color = "#CCCCCC";
                    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 == "" || obj.value == "Your Name" || obj.value == "Your Email")
                {
                    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 Validate()
        {
                var obj = document.getElementById("Name");
                if(obj.value == "" || obj.value == "Your Name")
                {
                    document.getElementById("nameError").style.display = "block";
                    obj.focus();
                    return false;
                }
                else if(!chkPatternNew(obj,"Name",/^\s*([A-Z]|[a-z])/))
                {
                    document.getElementById("nameError").style.display = "block";
                    document.getElementById("nameError").innerHTML = "";
                    document.getElementById("nameError").innerHTML = "Please provide proper full name.";
                    obj.focus();
                    return false;
                }
                else if(obj.value.length > 49)
                {
                    document.getElementById("nameError").style.display = "block";
                    document.getElementById("nameError").innerHTML = "";
                    document.getElementById("nameError").innerHTML = "Name not exceed 50 charaters.";
                    obj.focus();
                    return false;
                }
                else
                {
                    document.getElementById("nameError").style.display = "none";
                }
                
                var obj = document.getElementById("Email");
                if(obj.value == "" || obj.value == "Your Email")
                {
                    document.getElementById("emailError").style.display = "block";
                    obj.focus();
                    return false;
                }
                else if(!chkPatternNew(obj,"email address",/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/))
                {
                    document.getElementById("emailError").style.display = "block";
                    document.getElementById("emailError").innerHTML = "";
                    document.getElementById("emailError").innerHTML = "Please provide proper email address.";
                    obj.focus();
                    return false;
                }
                else if(obj.value.length > 49)
                {
                    document.getElementById("emailError").style.display = "block";
                    document.getElementById("emailError").innerHTML = "";
                    document.getElementById("emailError").innerHTML = "Email not exceed 50 charaters.";
                    obj.focus();
                    return false;
                }
                else
                {
                    document.getElementById("emailError").style.display = "none";
                }
                                                
                 sendEmailRequest('/formpost.aspx');
                 return false; 
        }


        function showLoading()
        {
            document.getElementById("subscribe").style.display = "none";
            document.getElementById("loading").style.display = "block";
        }

        function sendEmailRequest(url)
        {
                //var txt 
                var txtTo = "";
                var txtYourName = document.getElementById('Name').value;        
                var txtYourEmail = document.getElementById('Email').value;
                                             
                CreateXmlHttpRequest();
               
                url+="?type=request.subscribe&txtYourName="+txtYourName+"&txtYourEmail="+txtYourEmail;
                showLoading();                
                request.onreadystatechange = emailSendRequest;
                request.open("GET", url, true);
                request.send(null);
        }

        function disableLoading()
        {
            document.getElementById("subscribe").style.display = "block";
            document.getElementById("loading").style.display = "none";
        }

        function emailSendRequest()
        {
            if(request.readyState == 4)
            {
                if(request.status == 200)
                {
                    if(request.responseText == 'unauthorized')
                    {
                    alert('Email address aleady in use');
                    disableLoading();
                    return;
                    }
                    disableLoading();
                    ResetDivRequest('Thanks');   
                }
                else
                {
                    alert(request.status);
                }
            }
        }

            function ResetDivRequest(whichone)
            {
                if(whichone == "Thanks")
                {
                    var requestDiv = document.getElementById('subscribe');
                    requestDiv.innerHTML = "";
                    var html = "";
                    html += "<div style='color:#999999;font-size:11px;font-weight:bold;height:85px;background-color:#ffffff;margin:0px;padding:0px;padding-top:57px;padding-left:15px;border:10px solid #f4f4f4;'>Thank you for subscribing to our newsletter.</div></div>";
                    html += "<script language='javascript' type='text/javascript'>";
                    var axel = Math.random();
                    var a = axel * 10000000000000;
                    html += "<IFRAME SRC='http://fls.doubleclick.net/activityi;src=2613339;type=count275;cat=012en209;u1=Sorouh;u3=NA;u4=NA;u5=NA;u8=NA;u9=NA;u10=NA;ord=1;num='"+ a + "'?' WIDTH=1 HEIGHT=1 FRAMEBORDER=0></IFRAME>";
                    html += "</script>";
                    html += "<noscript>";
                    html += "<IFRAME SRC='http://fls.doubleclick.net/activityi;src=2613339;type=count275;cat=012en209;u1=Sorouh;u3=NA;u4=NA;u5=NA;u8=NA;u9=NA;u10=NA;ord=1;num='"+ a + "'?' WIDTH=1 HEIGHT=1 FRAMEBORDER=0></IFRAME>";
                    html += "</noscript>";
                    requestDiv.innerHTML = html;
                    
                 }
            }
            
                