<!--
// Ajax functions...

function getXMLHTTPRequest() {
    try {
        req = new XMLHttpRequest();
    } 
		catch(err1) {
        try {
            req = new ActiveXObject("Msxml2.XMLHTTP");
        } 
				catch (err2) {
            try {
                req = new ActiveXObject("Microsoft.XMLHTTP");
            }
						catch (err3) {
                req = false;
            }
        }
    }
    return req;
}

var http = getXMLHTTPRequest();

function timestamp(){
    var currentTime = new Date();
    var year = currentTime.getFullYear();
    var month = currentTime.getMonth() + 1;
    var day = currentTime.getDate();
    var hour = currentTime.getHours();
    var minute = currentTime.getMinutes();
    var second = currentTime.getSeconds();
    if (month < 10){
        month = "0" + month;
    }
    if (day < 10){
        day = "0" + day;
    }
    if (hour < 10){
        hour = "0" + hour;
    }
    if (minute < 10){
        minute = "0" + minute;
    }
    if (second < 10){
        second = "0" + second;
    }
		return(year + "" + month + "" + day + "" + hour + "" + minute + "" + second);
}

function useHttpResponse(type, div, loading) {
   if (http.readyState == 4) {
    if(http.status == 200) {
		   if (type == 'text'){
			     // Return simple text output
           var myText = http.responseText;
           document.getElementById(div).innerHTML = myText;
			 }
			 if (type == 'alert'){
			     // Return an alert box
           var myText = http.responseText;
           alert(myText);
					 window.location.reload();
			 }
			 if (type == 'refresh'){
			     // Just refresh the page
					 window.location.reload();
			 }
			 if (type == 'xml'){
			     // Return XML
					 
			 }
			 if (type == 'none'){
			     // Return nothing
			 }
    }
  } 
	else {
	    if(loading == true){
          document.getElementById(div).innerHTML = '<div align="center"><img src="./images/loading.gif"></div>';
      }
	}
}

/* Function doCallback
*  parameters;
*  formName - the id of our form
*  validate - array of id's of fields we want to validate (false if none, 'all' if all)
*  doAjax - php script if yes, false if no
*  callbackType - text, alert, xml, none
*  div - div to update if callback is text/xml
*/    

function doCallback(formName, validate, doAjax, callbackType, div){
    // Remove last element (always should be a button)
    var formLength = (document.getElementById(formName).elements.length)-1;
    // Validate required fields if we wanna 
		if(validate != false){
		    if(validate == 'all'){
				    // Validate everything in the form
				    for(i=0; i<=formLength; i++){
						    var isEmail = document.getElementById(formName).elements[i].id.search(/email/);
								var isPassword = document.getElementById(formName).elements[i].id.search(/password/);
								if(isEmail != -1){
							      // If we detect an email, perform a check on it
										if(isValidEmail(document.getElementById(formName).elements[i].value) == false){
										    alert("Please enter a valid email.");										
										    return false;
										}
								}
								else if(isPassword != -1){
							      // If we detect a password, perform a check on it
										if(document.getElementById(formName).elements[i].value.length < 6){
										    alert("Passwords must be at least 6 characters in length.");										
										    return false;
										}
								}
						    else if(document.getElementById(formName).elements[i].value == ''){
								    alert("Please make sure to fill out all required fields.");
										return false;
								}
								
						}
				}
				else{
				    // Only validate those fields specified in the array
    		    for(x=0; x<validate.length; x++){
						    var isEmail = document.getElementById(formName).elements[x].id.search(/email/);
								var isPassword = document.getElementById(formName).elements[x].id.search(/password/);
								if(isEmail != -1){
							      // If we detect an email, perform a check on it
										if(isValidEmail(document.getElementById(formName).elements[x].value) == false){
										    alert("Please enter a valid email.");										
										    return false;
										}
								}
								else if(isPassword != -1){
							      // If we detect a password, perform a check on it
										if(document.getElementById(formName).elements[x].value.length < 6){
										    alert("Passwords must be at least 6 characters in length.");										
										    return false;
										}
								}
    		        else if(document.getElementById(validate[x]).value == ''){
    				        alert("Please make sure to fill out all required fields.");
    						    return false;
    				    }
    		    }
				}
		}	  
		// Process ajax if we wanna
    if(doAjax != false){
	      myTimeStamp = timestamp();
        var modurl = doAjax + "?time=" + myTimeStamp;
				for(i=0; i<formLength; i++){
				    modurl += "&" + document.getElementById(formName).elements[i].id + "=" + document.getElementById(formName).elements[i].value;
				}
				http.open("POST", modurl, true);
	      http.onreadystatechange = function() {useHttpResponse(callbackType, div, false);};
        http.send('');
		}
		else{
		    return true;
		}
}


function addToCart(id, tickets, div, ticketNumbers, collect, alertPop){ 
    if(alertPop == 1){
        alert('You will automatically be allocated the BEST SEATS we have available.');
    }
		tickets = parseInt(tickets);
    ticketNumbers = parseInt(ticketNumbers);
    if(tickets > ticketNumbers){
        if(ticketNumbers == 1){
            alert("There is only " + ticketNumbers + " ticket left for this show.");
        }
        else{
            alert("There are only " + ticketNumbers + " tickets left for this show.");
        }
				return false;
    }
    if(tickets == '0' || tickets == ''){
		    alert("Please enter the amount of tickets you require for this show");
				return false;
		}
		else{
        myTimeStamp = timestamp();
		    document.getElementById(div).tickets.value = '0';
        var modurl = "./data/cart/additem.php" + "?time=" + myTimeStamp + "&id=" + id + "&tickets=" + tickets + "&collect=" + collect;
        http.open("POST", modurl, true);
        http.onreadystatechange = function() {useHttpResponse('text', 'cartContents', true);};
        //http.send(null);
				http.send('');
		}  
}

function emptyCart(sess){
    myTimeStamp = timestamp();
    var modurl = "./data/cart/emptycart.php" + "?time=" + myTimeStamp + "&sess=" + sess;
    http.open("POST", modurl, true);
    http.onreadystatechange = function() {useHttpResponse('text', 'cartContents', true);};
    //http.send(null);
		http.send('');  
}

// Check for a valid email
function isValidEmail(str) {
    return (str.indexOf(".") > 0) && (str.indexOf("@") > 0);
}


-->