var domainbase ="http://" + window.location.toString().split("//")[1].split("/")[0] + "/";
var siteurl = domainbase;
var base_url = domainbase; 

function showTab(type)
{
	switch(type)
	{
		case 'latest_project' :
		
		$("#latest_project_btn").attr("class","current");
		$("#customer_btn").attr("class","");
		$("#latestproject_tab").slideDown("slow");
		$("#customer_tab").hide();
		$("#latestproject_tab").show();
		
 

		
		break;
		
		case 'Customers' :
		
		$("#customer_btn").attr("class","current");
		$("#latest_project_btn").attr("class","");
		$("#customer_tab").slideDown("slow");
		$("#customer_tab").show();		
		$("#latestproject_tab").hide();
		
		
		break;
		
	} 
	 
} 

function validateQuickContact()
{
	if($("#first_name").val() =="First Name")
	{
		alert("Please enter first name.");		 
		$("#first_name").focus();
		return false;
		
	}
	if($("#last_name").val() =="Last Name")
	{
		alert("Please enter last name.");		
		$("#last_name").focus();
		return false;
		
	}  
	if (echeck($("#email").val())==false)
	{
		$("#email").select();
		$("#email").focus()
		return false;
	}
	if($("#contact").val() =="Contact No")
	{
		alert("Please enter contact no.");
		 
		$("#contact").focus();
		return false;
		
	} 
	if($("#message").val() =="Message")
	{
		alert("Please enter message.");
		 
		$("#message").focus();
		return false;		
	}  
	
}

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){
   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					
} 

function clearText(elemtent_id , val)
{

	if($('#'+elemtent_id).val() == val)
	{
		$('#'+elemtent_id).attr("value","");
	}
}
function unclearText(elemtent_id , val)
{

	if($('#'+elemtent_id).val() == "")
	{
		$('#'+elemtent_id).attr("value",val);
	}
}

function sendMail()
{
	if(validateQuickContact() != false){
		$("#send").attr("disabled","disabled");
		$("#send").attr("value","Processing ...");
	 
 $.post(siteurl+"mail.php",{ first_name: $("#first_name").val(), last_name: $("#last_name").val(), email: $("#email").val() , contact: $("#contact").val() , message: $("#message").val() , pg: $("#pg").val() },
	function(data){
		 
	  	if(data=="1")
	  	{
	  		$("#msg").html('Message has been sent.');
	  		$("#first_name").attr("value","First Name");
	  		$("#last_name").attr("value","Last Name");
	  		$("#email").attr("value","Email");
	  		$("#contact").attr("value","Contact No");
	  		$("#message").attr("value","Message");
	  		
	  		$("#send").attr("disabled","");
			$("#send").attr("value","Send Details");
			
			
	  	}
	  	else if(data=="0")
	  	{
	  		$("#msg").html('Failed to send.');
	  	}
	   
	}
   ); 
	}
} 

function agileClick(str)
{
	 
	 if(str == "Yes")	  
	 	$("#aglie_specify").show();
	 if(str == "No")   
	  	$("#aglie_specify").hide();
	  
	
}
function validateQuestionnaire()
{
	if($("#fname").val() =="")
	{
		alert("Please enter first name.");
		$("#fname").focus();
		return false;		
	}
	
	if($("#lname").val() =="")
	{
		alert("Please enter last name.");
	 
		$("#lname").focus();
		return false;		
	}
	
	if($("#address").val() =="")
	{
		alert("Please enter address.");
	 
		$("#address").focus();
		return false;		
	}
	
	
	if($("#state").val() =="")
	{
		alert("Please select state.");
	 
		$("#state").focus();
		return false;		
	}
	
	if($("#country").val() =="")
	{
		alert("Please select country.");
	 
		$("#country").focus();
		return false;		
	}
	
	if (echeck($("#emailid").val())==false)
	{
		$("#emailid").select();
		$("#emailid").focus()
		return false;
	} 
	 
	if($("#purpose").val() =="")
	{
		alert("Please enter purpose of the project.");
	 
		$("#purpose").focus();
		return false;		
	} 
	
	if($("#commission").val() =="")
	{
		alert("Please select commission.");	 
		$("#commission").focus();
		return false;		
	} 
	if($("#budget").val() =="")
	{
		alert("Please enter project budget.");	 
		$("#budget").focus();
		return false;		
	} 
	if($("#capcha").val() =="")
	{
		alert("Please enter valid code.");	 
		$("#capcha").focus();
		return false;		
	} 
	
	
}
function questionnaire_submit()
{
	if(validateQuestionnaire() != false){
		$("#send_quest").attr("disabled","disabled");
		$("#send_quest").attr("value","Processing ...");
	 
 	   $.post(siteurl+"questAjax.php",
		{ 
			fname	: $("#fname").val(), 
			lname	: $("#lname").val(), 
			address	: $("#address").val(),
			city	: $("#city").val(),
			state	: $("#state").val(),
			country	: $("#country").val(),		
			email	: $("#emailid").val(),
			website	: $("#website").val(),
			phone	: $("#phone").val(),
			agile	: $("#aglie").val(), 
			agileprocess	: $("#specify").val(), 
			purpose	: $("#purpose").val(), 
			commission	: $("#commission").val(), 
			budget	: $("#budget").val(), 
			capcha	: $("#capcha").val()
	   },
	  function(data){	
	 
	  	if(data =="1")
	  	{ 
	  		$("#send_quest").attr("disabled","");
			$("#send_quest").attr("value","Submit");	
				
	  		$("#questionnaire_tbl").hide();
	  		$("#quest_msg").html("<p>Thank you "+$("#fname").val()+" for filling up the introduction form. You will receive the questionnaire in the email id you have specified. Do note that the questionnaire is an attempt to give us a good understanding of the project requirements. If there are any additional information that you would like to add, please feel free to make the necessary modifications. Please mail the completed worksheet to quote@interberry.com and allow us 3 business days for a response.</p>");
	  			
			
	  	}
	  	else if(data=="0")
	  	{
	  		$("#questionnaire_tbl").show();
	  		$("#msg").html('Failed to send.');
	  	}
	  	else if(data=="capcha_error")
	  	{
	  		alert('Not Valid Code');
	  		return false;
	  	}
	}); 
  }
	
}

