// JavaScript Document
function getTheFocus(id)
		{
		document.getElementById(id).value="";		
		}
		
		
function checkTheValue(id)
{
		var val=document.getElementById(id).value;
		if(val=="")
			{
			document.getElementById(id).value=id.toUpperCase();
			}		
}
	

function ValidateForm(){
		//alert("hsdgvfshjkdc");
				var emailID=document.getElementById("email").value;
				var subject =document.getElementById("subject").value;
				var name = document.getElementById("name").value;
				var msg=document.getElementById("text").value;
				
				if ((emailID==null)||(emailID=="") ||(emailID=="EMAIL")){
					alert("Enter your Email Id");
					document.getElementById("email").focus();
					return false;
				}
				if ((subject==null)||(subject=="SUBJECT")){
						alert("Kindly select a subject");
						return false;
				}
				if ((name==null)||(name=="") ||(name=="NAME")){
					alert("Kindly enter your Name");
					document.getElementById("email").focus();
					return false;
				}
				
				if (echeck(emailID)==false){
					alert("Kindly enter proper e-mail Id");
					document.getElementById("email").value="";
					document.getElementById("email").focus();
					return false;
				}
				var url_comments = "php/send_email.php?uname="+name+"&emailid="+emailID+"&msg="+msg+"&subject="+subject;
				httpComments_D("GET",url_comments,true);
}

function httpComments_D(reqType,url_comments,asynch){
    //Mozilla-based browsers
    if(window.XMLHttpRequest){
        request = new XMLHttpRequest();
    } else if (window.ActiveXObject){
        request=new ActiveXObject("Msxml2.XMLHTTP");
        if (! request){
            request=new ActiveXObject("Microsoft.XMLHTTP");
        }
     }
    //the request could still be null if neither ActiveXObject
    //initializations succeeded
    if(request){
       initComments_D(reqType,url_comments,asynch);
    }  else {
        alert("Your browser does url_comments not permit the use of all "+
        "of this application's features!");}
}

function initComments_D(reqType,url_comments,bool){
    try{
        // Specify the function that will handle the HTTP response */
		request.onreadystatechange=handleComments_D;  
        request.open(reqType,url_comments,bool);
        request.send(null);
    } catch (errv) {
        alert(
                "The application cannot url_comments contact the server at the moment. "+
                "Please try again in a few seconds." );
    }
}

function handleComments_D(){
    try{
        if(request.readyState == 4){
            if(request.status == 200){
					var resp = request.responseText;
					if(resp==1)
					{
						document.getElementById("email").value="";
            document.getElementById("subject").value="";
            document.getElementById("name").value="";
            document.getElementById("text").value="";
            alert("Mail sent Sucessfully");
						//document.location='index.html';
					}
					else
					{
						alert("Mail sending Failed");
						//document.location='contact.html';
					}
				} else {
                //request.status is 503  if the application isn't available; 
                //500 if the application has a bug
                alert(
                        "A problem occurred with communicating handleComments_D between the RouteDetails XMLHttpRequest object and the server program.");
            }
        }//end outer if
    } catch (err)   {
        alert(err.name);
        alert("It does not appear that the handleComments_D server is available for this application details. Please"+
              " try again very soon. \nError: "+err.message);

    }
}

function echeck(str) {
			//alert ("STRING : "+str);
					var at="@";
					var dot=".";
					var lat=str.indexOf(at);
					var lstr=str.length;
					var ldot=str.indexOf(dot);
					if (str.indexOf(at)==-1){
					   //alert("Invalid E-mail ID");
					   return false;
					}
			
					if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
					   //alert("Invalid E-mail ID");
					   return false;
					}
			
					if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
						//alert("Invalid E-mail ID");
						return false;
					}
			
					 if (str.indexOf(at,(lat+1))!=-1){
						//alert("Invalid E-mail ID");
						return false;
					 }
			
					 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
						//alert("Invalid E-mail ID");
						return false;
					 }
			
					 if (str.indexOf(dot,(lat+2))==-1){
						//alert("Invalid E-mail ID");
						return false;
					 }
					
					 if (str.indexOf(" ")!=-1){
						//alert("Invalid E-mail ID");
						return false;
					 }
			
					 return true;				
				}
			