//Validate E-mail

function validate_form(thisform)
{
     //Comment field must be filled out.
     var checkComment = document.myform1.txtComment.value;        
     if (checkComment === ""){
         return false;
     }
     else {
            
         Resolution();
        
         //Check out comments
      	 var strComment = document.myform1.txtComment.value;  	
         var commentRemoveLeft = strComment.replace(/</g,"");
  	 var commentRemoveRight = commentRemoveLeft.replace(/>/g,""); 
        
         document.myform1.txtComment.value = commentRemoveRight;
     }  


    //How much time customer use to fill out schema?
    var sTime = $('txtStartTime').value;
    FinishTime();
    var fTime = $('txtFinishTime').value;
    var diffTime = fTime - sTime;

    
    // 10 seconds to fill out schema
    if (( diffTime < 10 ) || (checkComment === "")) {
        
        return false;
    }
    else {
                       
        var emailAlert = $('txtAlert').value;      
        with (thisform)
        {
            //if (validate_email(txtEmail,"Email must be filled out!")==false)
            if (validate_email(txtEmail, emailAlert )==false)
            	{txtEmail.focus();return false;}           	
        }  
    }
      
}


function validate_email(field,alerttxt)
{
    with (field)
    {
        apos=value.indexOf("@");
  		dotpos=value.lastIndexOf(".");
  		if (apos<1||dotpos-apos<2)
    		{alert(alerttxt);return false;}
  		else {return true;}
  	}
}
// Finish validate E-mail


//StartTime and FinishTime functions
function StartTime()
{
    var currentTime = new Date();

    var sTime   = currentTime.getTime()
    var hours   = currentTime.getHours();
    var minutes = currentTime.getMinutes();
    if (minutes < 10) {
    	minutes = "0" + minutes;
    }

    var seconds = currentTime.getSeconds();
    if (seconds < 10) {
    	seconds = "0" + seconds;
    }

    var startTime = hours + "" + minutes + "" + seconds;
    document.myform1.txtStartTime.value = startTime;
}

function FinishTime() {

    var currentTime2 = new Date();

    var fTime  =  currentTime2.getTime();
    var fHours =  currentTime2.getHours();
	var fMinutes = currentTime2.getMinutes();
    if (fMinutes < 10 ) {
    	fMinutes = "0" + fMinutes;
    }

    var fSeconds = currentTime2.getSeconds();
    if (fSeconds < 10 ) {
    	fSeconds = "0" + fSeconds;
    }
    var finishTime = fHours + "" + fMinutes + "" + fSeconds;
    document.myform1.txtFinishTime.value = finishTime;
}




function showEmailField(data)
{
    //alert("Start1");
    //To block spam ...
    StartTime();

        if (data.length==0)
        {
    	document.getElementById("emailField").innerHTML="";
    	return;
  	}
  	if (window.XMLHttpRequest)
  	{
    	// code for IE7+, Firefox, Chrome, Opera, Safari
    	xmlhttp=new XMLHttpRequest();
  	}
  	else
  	{
    	// code for IE6, IE5
    	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  	}
  	xmlhttp.onreadystatechange=function()
  	{
    	    if (xmlhttp.readyState==4 && xmlhttp.status==200)
    	    {
      		//alert(xmlhttp.responseText);
      		document.getElementById("emailField").innerHTML=xmlhttp.responseText;
    	    }
  	}
  	xmlhttp.open("GET","getajax.php?email=" +$('emailText').value,true);
  	xmlhttp.send();
}



function Resolution() {
    var resolution = screen.width +"x"+ screen.height;
    document.myform1.txtResolution.value = resolution;
}



function removeTags()
{
        
        Resolution();
        
  	//Check out username if it was written with i.e.  js script etc. to hack inn to database
  	var strUser = document.myform1.txtUserName.value;
  	var userRemoveLeft = strUser.replace(/</g,"");
  	var userRemoveRight = userRemoveLeft.replace(/>/g,"");


  	//Check out email
  	var strEmail = document.myform1.txtEmail.value;
  	if ( strEmail != "" ) {  	
  	    var emailRemoveLeft = strEmail.replace(/</g,"");
  	    var emailRemoveRight = emailRemoveLeft.replace(/>/g,"");
  	    
  	    document.myform1.txtEmail.value = emailRemoveRight; 	
  	}
 	
  	document.myform1.txtUserName.value = userRemoveRight;
 	
}
