// JavaScript Document

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function view_product(aId){
 	MM_openBrWindow('product.php?id=' + aId,'','width=521,height=724');
}

function validate_order(){
	var tValidatedOK = true
	var tMessage = "The following field(s) are required:\n"
	
	tForm = document.getElementById("cart_form")

	 
	if (tForm.fullname.value  == ""){
		tMessage += "          You must enter your Name\n"
		tValidatedOK = false
	}
	
	if (tForm.email.value  == ""){
		tMessage += "          You must enter your Email Address\n"
		tValidatedOK = false
	}
			
	if(tValidatedOK == false){
		alert(tMessage)
	} else {
	
		tForm.submit()
	}
	
}

function validate_frmsubscribe(){
	var tValidatedOK = true
	var tMessage = "The following field(s) are required:\n"
	
	tForm = document.getElementById("frmsubscribe")

	 
	if (tForm.name.value  == ""){
		tMessage += "          You must enter your Name\n"
		tValidatedOK = false
	}
	 
	if (tForm.email.value  == ""){
		tMessage += "          You must enter your Email Address\n"
		tValidatedOK = false
	}
			
	if(tValidatedOK == false){
		alert(tMessage)
	} else {
		tForm.submit()
	}
	
}



function GetXmlHttpObject(){ 
	var objXMLHttp = null
	if (window.XMLHttpRequest){
		objXMLHttp = new XMLHttpRequest()
	} else if (window.ActiveXObject) {
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
	}
	return objXMLHttp
} 

function AJAX_handler(aRequestURL, aData, aStateChangeHandler){
	xmlHttp = GetXmlHttpObject()
		
	if (xmlHttp==null){
		alert ("Browser does not support HTTP Request")
		return
	} 
	
	xmlHttp.onreadystatechange = aStateChangeHandler
	xmlHttp.open("POST",aRequestURL,true)
	xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
	xmlHttp.send(aData + "&ajax_uid=" + Math.random())	
}

function AJAX_response(){
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
		return xmlHttp.responseText
	}
}

function validate_event_4_buy_ticket(){
	var tValidatedOK = true
	var tMessage = "The following field(s) are required:\n"
	
	tForm = document.frmticketdetails
	name = tForm.first_name.value + " " +  tForm.last_name.value
	email = tForm.email.value
	phone = tForm.phone.value
	msg = tForm.msg.value
	qty = tForm.qty.value
	if (tForm.first_name.value  == ""){
		tMessage += "          Your First Name\n"
		tValidatedOK = false
	}
	
	if (tForm.last_name.value  == ""){
		tMessage += "          Your Last Name\n"
		tValidatedOK = false
	}
	
	if (tForm.email.value  == ""){
		tMessage += "          Your Email Address\n"
		tValidatedOK = false
	}
	
	if (tForm.phone.value  == ""){
		tMessage += "          Your Phone Number\n"
		tValidatedOK = false
	}
			
			
	if(tValidatedOK == false){
		alert(tMessage)
	} else {
		document.getElementById('event_ticket_buttons').style.display = "none";
		document.getElementById('event_processing').style.display = "block";
	 
		AJAX_handler("our-events-4-submitted.php","qty=" + qty + "&name=" + name + "&email=" + email + "&phone=" + phone + "&msg=" + msg, validated_event_4_ajax_done);
		 
	}
	
}

function validated_event_4_ajax_done(){
	if(AJAX_response() != undefined){
		document.getElementById('ppf').innerHTML = AJAX_response();
		document.paypal_form.submit() 
	}
}


function validate_event_1_buy_ticket(aQty){
	var tValidatedOK = true
	var tMessage = "The following field(s) are required:\n"
	
	tForm = document.frmticketdetails
	name = tForm.name.value
	email = tForm.email.value
	phone = tForm.phone.value
	msg = tForm.msg.value
	
	if (tForm.name.value  == ""){
		tMessage += "          Your Name\n"
		tValidatedOK = false
	}
	
	if (tForm.email.value  == ""){
		tMessage += "          Your Email Address\n"
		tValidatedOK = false
	}
	
	if (tForm.phone.value  == ""){
		tMessage += "          Your Phone Number\n"
		tValidatedOK = false
	}
			
			
	if(tValidatedOK == false){
		alert(tMessage)
	} else {
		document.getElementById('event_ticket_buttons').style.display = "none";
		document.getElementById('event_processing').style.display = "block";
		
		if(aQty == 1){
			AJAX_handler("our-events-1-submitted.php","qty=1&name=" + name + "&email=" + email + "&phone=" + phone + "&msg=" + msg, validated_event_1_buy_1_ticket);
		}
		if(aQty == 2){
			AJAX_handler("our-events-1-submitted.php","qty=2&name=" + name + "&email=" + email + "&phone=" + phone + "&msg=" + msg, validated_event_1_buy_2_ticket);
		}
	}
	
	
}

function validated_event_1_buy_1_ticket(){
	if(AJAX_response() != undefined){
		document.frmPayPal1ticket.submit()
	}
}

function validated_event_1_buy_2_ticket(){
	if(AJAX_response() != undefined){
	
		document.frmPayPal2ticket.submit()
	}
}

function intouch(){
	document.write('<a href="');
	document.write('mailto:');
	document.write('teamvisure');
	document.write('@');
	document.write('yahoo.com');
	document.write('">email us now &gt;');
	document.write('</a>');
}




function validate_shop(){
	var tValidatedOK = true
	var tMessage = "The following field(s) are required:\n"
	
	tForm = document.frmshop
	name = tForm.name.value
	street_1 = tForm.street_1.value
	street_2 = tForm.street_2.value
	suburb = tForm.suburb.value
	postcode = tForm.postcode.value
	email = tForm.email.value
	phone = tForm.phone.value
 
	if(tForm.payment[0].checked){
		payment = 1
	} else {
		payment = 2
	}
	qty = "";
	 for(i = 1; i <= 35; i++){
		tqty=0
		if( document.getElementById("qty_" + i) != null){
			 tqty = parseInt(document.getElementById("qty_" + i).value) 
		}
		qty = qty + tqty
		
		if(i < 35){
			qty = qty + ","
		}
	 }
	  
	
	if (tForm.name.value  == ""){
		tMessage += "          Your Name\n"
		tValidatedOK = false
	}
	
	if (tForm.street_1.value  == ""){
		tMessage += "          Your Street Address\n"
		tValidatedOK = false
	}
	
	if (tForm.suburb.value  == ""){
		tMessage += "          Your Suburb/Town\n"
		tValidatedOK = false
	}
	
	if (tForm.postcode.value  == ""){
		tMessage += "          Your Postcode\n"
		tValidatedOK = false
	}
	
	if (tForm.email.value  == ""){
		tMessage += "          Your Email Address\n"
		tValidatedOK = false
	}
	
 	
			
	if(tValidatedOK == false){
		alert(tMessage)
	} else {
		document.getElementById('shop_buttons').style.display = "none";
		document.getElementById('shop_processing').style.display = "block";
		qry = "qty=" + qty + "&name=" + name + "&street_1=" + street_1 + "&street_2=" + street_2 + "&suburb=" + suburb + "&postcode=" + postcode + "&email=" + email + "&phone=" + phone + "&payment=" + payment;
	 
		AJAX_handler("our-shop-submitted.php",qry, validated_shop_ajax_done);
		 
	}
	
}

function validated_shop_ajax_done(){
	if(AJAX_response() != undefined){
	 	//	alert( AJAX_response())
		document.getElementById('ppf').innerHTML = AJAX_response();
	 	document.paypal_form.submit() 
	}
}
