function changeb()
{
document.getElementById("second").style.display='block';
document.getElementById("first").style.display='none';
}
function changeba()
{
document.getElementById("second").style.display='none';
document.getElementById("first").style.display='block';
}

function validate_form()
{
    var valid = true;

    if (document.getElementById("heardabout").value == "")
    {
        alert ( "Please let us know how you heard about us." );
        valid = false;
         changeba();
        return valid;
    }	
	
    if (document.getElementById("agreeterms").checked == false)
    {
        alert ( "You must agree to our terms and conditions in order to complete your order." );
        valid = false;
         changeba();
        return valid;
    }
    
    if (document.payform.fname.value == "" )
    {
        alert ( "Please enter your Full name" );
        valid = false;
        document.payform.fname.focus();
        changeba();
        return valid;

    }
    if (document.payform.address.value == "" )
    {
        alert ( "Please enter your Address" );
        document.payform.address.focus();
        valid = false;
         changeba();
        return valid;
    }

    if ( document.payform.city1.value == "" )
    {
        alert ( "Please enter your City" );
        document.payform.city1.focus();
        valid = false;
         changeba();
        return valid;
    }
    
    if ( document.payform.pickuplocation.value == "" )
    {
        alert ( "Please enter your pickup location" );
        document.payform.pickuplocation.focus();
        valid = false;
         changeba();
        return valid;
    }    

    if ( document.payform.city.value == "0" )
    {
        alert ( "Please enter your Pick up City" );
        document.payform.city.focus();
        valid = false;
         changeba();
        return false;
    }

    if ( document.payform.state.value == "" )
    {
        alert ( "Please enter your State" );
        document.payform.state.focus();
        valid = false;
         changeba();
        return valid;
    }
    if ( document.payform.dayofphone.value == "" )
    {
        alert ( "Please enter your Phone Number" );
        document.payform.dayofphone.focus();
        valid = false;
         changeba();
        return valid;
    }

    if ( document.payform.zip.value == "" )
    {
        alert ( "Please enter your zip/postal code" );
        document.payform.zip.focus();
        valid = false;
         changeba();
        return valid;
    }

    if ( document.payform.country.value == "" )
    {
        alert ( "Please enter your Country" );
        document.payform.country.focus();
        valid = false;
         changeba();
        return valid;
    }

    if ( document.payform.email.value == "" || document.payform.email.value == " ")
    {
        alert ( "Please enter your email address" );
        document.payform.email.focus();
        valid = false;
         changeba();
        return valid;
    }


    
mEmail = document.payform.email.value;
AtPos = mEmail.indexOf("@");
StopPos = mEmail.lastIndexOf(".")

if (AtPos == -1 || StopPos == -1)
{
alert ("Please enter a valid email address, common mistakes are missing the @ sign or the .com/.net etc" );
document.payform.email.focus();
valid = false;
 changeba();
return valid;
}

var str = document.payform.cardNo.value;

str = str.replace(/\s+/g,'');


    if ( str  == "" || str  == " " || str == "  " )
    {
        alert ( "Please enter your Credit Card Number" );
        document.payform.cardNo.focus();
        valid = false;
		 changeba();
        return valid;
    }


    if ( document.payform.cvv.value == "" || document.payform.cvv.value == " " || document.payform.cvv.value == "  ")
    {
        alert ( "Please enter your CVV code" );
        document.payform.cvv.focus();
        valid = false;
		 changeba();
        return valid;
    }
    if ( document.payform.ExpYear.value == "" )
    {
        alert ( "Please enter your credit card expiration year" );
        document.payform.ExpYear.focus();
        valid = false;
		 changeba();
        return valid;
    }
}





 function calcPrice()
 {
       var blut=1;
       var base= document.getElementById("base").value;
       var amnt=0;
 
 var x = document.getElementById("city").value;
  var y = document.getElementById("party").value;
 var cityprice = document.getElementById("cityid"+x).value;
 
    
 if (x == "Other")
 {
 var cost=0;
 document.getElementById("othercity").style.display='block';
 }
 else
 {
 document.getElementById("othercity").style.display='none';
var cost = Math.floor(cityprice);
 }

 
if (pnum >= 10)
{
cost = cost*2;

}
  


var amnt=y*base+cost;

 
 if(document.payform.days[1].checked)
 {
amnt = (amnt*2)-(10*y);
  }

 if(document.payform.days[2].checked)
 {
amnt = (amnt*3)-(15*y);
  }

 var result = amnt.toFixed(2);


 
var checktype = document.getElementById("ctype").value;

if (checktype == "1")
{
var thepeoples = y*document.getElementById("cpn").value;
result = result-thepeoples;
}
else
{
result = result-document.getElementById("cpn").value;
}

 result= result.toFixed(2);


var pnum = document.getElementById("party").value;

 
if (pnum >= 7)
{
document.getElementById("bigparty").style.display='block';

var newres = result*1.15;
result = newres.toFixed(2);
} 
else
{
document.getElementById("bigparty").style.display='none';
}

 if(document.payform.lunch[0].checked==1)
 {
  var lunch = y*15;
 }
  else
  {
   var lunch = 0;
  }
//alert(lunch);

var anewres = Number(result) + Number(lunch);

//alert(anewres);  

var thisresult = (anewres).toFixed(2);

//alert(thisresult);
 
 document.getElementById("cst").innerHTML="$" + " " + thisresult;
 document.getElementById("tcost").value=thisresult;
}
 
 
 

function specific() {  
    document.getElementById("specific").style.display='block';
}
function nospecific() {  
    document.getElementById("specific").style.display='none';
}



function showhear() {  

	if (document.getElementById("showmorehear").checked == true) 
	{
	document.getElementById("morehear").style.display='block';
	}
	else 
	{ 
	document.getElementById("morehear").style.display='none';
	}  
}

function showpass() {  
	document.getElementById("passinfo").style.display='block';
}
function hidepass() {  
	document.getElementById("passinfo").style.display='none';
}

 function addlunch() {  
	document.getElementById("addinlunch").style.display='block';
}
function nolunch() {  
	document.getElementById("addinlunch").style.display='none';
}


function updateregion(id,region,price)
{
document.getElementById("base").value = price;
document.getElementById("goregion").value = region;
document.getElementById("setregion").value = id;
//calcPrice();
}

 


 function getXMLHTTP() { //fuction to return the xml http object
 		var xmlhttp=false;	
 		try{
 			xmlhttp=new XMLHttpRequest();
 		}
 		catch(e)	{		
 			try{			
 				xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
 			}
 			catch(e){
 				try{
 				xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 				}
 				catch(e1){
 					xmlhttp=false;
 				}
 			}
 		}
 		 	
 		return xmlhttp;
 	}
 	
 	
 	
 	function getCity(strURL) {		


 		var req = getXMLHTTP();

	var url = "/wp-content/themes/wineline/findcity.php?region=" + strURL + "&date="+Date();
 		
 		if (req) {
 			
 			req.onreadystatechange = function() {
 				if (req.readyState == 4) {
 					// only if "OK"
 					if (req.status == 200) {						
 						document.getElementById('citydiv').innerHTML=req.responseText;						
 					} else {
 						alert("There was a problem while using XMLHTTP:\n" + req.statusText);
 					}
 				}				
 			}			
 			req.open("GET", url, true);
 			req.send(null);
 		}



var url = "/wp-content/themes/wineline/findloop.php?region=" + strURL + "&date="+Date();
 	 		var req3 = getXMLHTTP();
	
 		if (req3) {
 			
 			req3.onreadystatechange = function() {
 				if (req3.readyState == 4) {
 					// only if "OK"
 					if (req3.status == 200) {						
 						document.getElementById('loopdiv').innerHTML=req3.responseText;						
 					} else {
 						alert("There was a problem while using XMLHTTP:\n" + req3.statusText);
 					}
 				}				
 			}			
 			req3.open("GET", url, true);
 			req3.send(null);
 		}

 				
 	}
 
 function getSeats() {		

var tmonth = document.getElementById("tmonth").value;
var tday =  document.getElementById("tday").value;
var tyear =  document.getElementById("tyear").value;
var setregion = document.getElementById("setregion").value;
  
 var url = "/wp-content/themes/wineline/findseats.php?tmonth="+ tmonth + "&tday="+ tday + "&tyear="+ tyear + "&region=" + setregion + "&date="+Date();

var req2 = getXMLHTTP();
 	
  		if (req2) {
  			
  			req2.onreadystatechange = function() {
  				if (req2.readyState == 4) {
  					// only if "OK"
  					if (req2.status == 200) {						
  						document.getElementById('seatdiv').innerHTML=req2.responseText;						
  					} else {
  						alert("There was a problem while using XMLHTTP:\n" + req2.statusText);
  					}
  				}				
  			}			
  			req2.open("GET", url, true);
  			req2.send(null);
 		}
 		
} 	

function sethear()
{
document.getElementById("heardabout").value = "set";	
}
