// bashvite.js - JavaScript Document

function xmlhttpPost(strURL,action,postStr) {
	var xmlHttpReq = false;
	var self = this;
	// Mozilla/Safari
	if (window.XMLHttpRequest) {
		self.xmlHttpReq = new XMLHttpRequest();
	}
	// IE
	else if (window.ActiveXObject) {
		self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
	}
	self.xmlHttpReq.open('POST', strURL, true);
	self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	self.xmlHttpReq.onreadystatechange = function() {
		if (self.xmlHttpReq.readyState == 4) {
			updatepage(self.xmlHttpReq.responseText,action);
		}
	}
	self.xmlHttpReq.send(postStr);
}

function xmlhttpPost2(strURL,action,postStr) {
	var xmlHttpReq2 = false;
	var self = this;
	// Mozilla/Safari
	if (window.XMLHttpRequest) {
		self.xmlHttpReq2 = new XMLHttpRequest();
	}
	// IE
	else if (window.ActiveXObject) {
		self.xmlHttpReq2 = new ActiveXObject("Microsoft.XMLHTTP");
	}
	self.xmlHttpReq2.open('POST', strURL, true);
	self.xmlHttpReq2.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	self.xmlHttpReq2.onreadystatechange = function() {
		if (self.xmlHttpReq2.readyState == 4) {
			updatepage(self.xmlHttpReq2.responseText,action);
		}
	}
	self.xmlHttpReq2.send(postStr);
}

function xmlhttpGet(strURL,action,getStr) {
	var xmlHttpReq = false;
	var self = this;
	// Mozilla/Safari
	if (window.XMLHttpRequest) {
		self.xmlHttpReq = new XMLHttpRequest();
	}
	// IE
	else if (window.ActiveXObject) {
		self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
	}
	self.xmlHttpReq.open('GET', strURL, true);
	self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	self.xmlHttpReq.onreadystatechange = function() {
		if (self.xmlHttpReq.readyState == 4) {
			updatepage(self.xmlHttpReq.responseText,action);
		}
	}
	self.xmlHttpReq.send(getStr);
}

function req1(strURL,action) {
	var xmlHttpReq1 = false;
	var self = this;
	// Mozilla/Safari
	if (window.XMLHttpRequest) {
		self.xmlHttpReq1 = new XMLHttpRequest();
	}
	// IE
	else if (window.ActiveXObject) {
		self.xmlHttpReq1 = new ActiveXObject("Microsoft.XMLHTTP");
	}
	self.xmlHttpReq1.open('POST', strURL, true);
	self.xmlHttpReq1.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	self.xmlHttpReq1.onreadystatechange = function() {
		if (self.xmlHttpReq1.readyState == 4) {
			updatepage(self.xmlHttpReq1.responseText,action);
		}
	}
	self.xmlHttpReq1.send();
}

function req2(strURL,action) {
	var xmlHttpReq2 = false;
	var self = this;
	// Mozilla/Safari
	if (window.XMLHttpRequest) {
		self.xmlHttpReq2 = new XMLHttpRequest();
	}
	// IE
	else if (window.ActiveXObject) {
		self.xmlHttpReq2 = new ActiveXObject("Microsoft.XMLHTTP");
	}
	self.xmlHttpReq2.open('POST', strURL, true);
	self.xmlHttpReq2.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	self.xmlHttpReq2.onreadystatechange = function() {
		if (self.xmlHttpReq2.readyState == 4) {
			updatepage(self.xmlHttpReq2.responseText,action);
		}
	}
	self.xmlHttpReq2.send();
}

function getreq1(strURL,action,getStr) {
	var xmlHttpReqg1 = false;
	var self = this;
	// Mozilla/Safari
	if (window.XMLHttpRequest) {
		self.xmlHttpReqg1 = new XMLHttpRequest();
	}
	// IE
	else if (window.ActiveXObject) {
		self.xmlHttpReqg1 = new ActiveXObject("Microsoft.XMLHTTP");
	}
	self.xmlHttpReqg1.open('GET', strURL, true);
	self.xmlHttpReqg1.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	self.xmlHttpReqg1.onreadystatechange = function() {
		if (self.xmlHttpReqg1.readyState == 4) {
			updatepage(self.xmlHttpReqg1.responseText,action);
		}
	}
	self.xmlHttpReqg1.send(getStr);
}

function updatepage(str,action) {
// alert(str); alert(action);

var refreshUI = "YES";

	if (action == "NULL") {
		refreshUI = "NO";
	} else
    if (action == "UPDATEATTENDEEINFO") {
		refreshUI = "NO";
	    refreshAttendeeInfo(0);
 	} else
     if (action == "SHOWATTENDEEINFO") {
 		var divdata = document.getElementById("DIVUPDATE");
 	} else
 	if (action == "ADDPARTYCOMMENT") {
 	   showComments(0);
 	   document.getElementById("partycomment").value = '';
 	   refreshUI = "NO";
 	} else
 	if (action == "SHOWCOMMENTS") {
 	   var divdata = document.getElementById("DIVPARTYCOMMENTS");
 	} else
    if (action == "SHOWATTENDEEINFO") {
		var divdata = document.getElementById("DIVUPDATE");
	} else
	if (action == "ADDPARTYCOMMENT") {
	   showComments(0);
	   document.getElementById("partycomment").value = '';
	   refreshUI = "NO";
	} else
	if (action == "SHOWCOMMENTS") {
	   var divdata = document.getElementById("DIVPARTYCOMMENTS");
	} else
	if (action == "SENDCONFEMAIL") {
	    var divdata = document.getElementById("DIVHOMEMESSAGE");
	} else
	if (action == "CREATEPARTYINVITE" || action == "CREATESURVEY") {
		if (str.substring(0,5) == "ERROR") {
		   var divdata = document.getElementById("DIVHOMEMESSAGE");
		   str = str.substring(5);
	    } else {
		   var divdata = document.getElementById("body");
		}
	} else
	if (action == "MEMBERLOGIN2") {
		if (str.substring(0,16) == "<META HTTP-EQUIV") {
		   refreshUI = "NO";
		   document.location = 'index.php';
		} else {
		var divdata = document.getElementById("diverror");
						  }
	} else
	if (action == "USERLOGIN" || action == "USERLOGOUT") {
		if (str.substring(0,5) == "ERROR") {
		   var divdata = document.getElementById("DIVHOMEMESSAGE");
		   str = str.substring(5);
	    } else {
			refreshUI = "NO";
			document.location = "index.php";
		}
	} else
	if (action == "UPDATEPARTYINVITE") {
		refreshUI = "NO";
		showMyInvites('UPDATE_SUCCESS');
	} else
	if (action == "COPYOLDINVITEE") {
		if (str == "SUCCESS") {
			refreshUI = "NO";
			var pStr = "op=COPYINVITEE2&prevaction=" + action;
			xmlhttpPost("bvcopyinvitees.php","COPYOLDINVITEE2",pStr);    	
		} else {
		   var divdata = document.getElementById("DIVHOMEMESSAGE");
		}
	} else
	if (action == "COPYINVITEE2") {
		var divdata = document.getElementById("DIVINVITEECOPY");
	} else
	if (action == "INSERTPARTYINVITE" || action == "ADDINVITEE" || action == "REMOVEINVITEE") {
		if (str == "SUCCESS") {
			refreshUI = "NO";
			var pStr = "op=INSERTPARTYINVITE2&prevaction=" + action;
			xmlhttpPost("bvcreateinvite2.php","INSERTPARTYINVITE2",pStr);    	
		} else {
		   var divdata = document.getElementById("DIVHOMEMESSAGE");
		}
	} else
	if (action == "INSERTSURVEY") {
		if (str == "SUCCESS") {
			refreshUI = "NO";
			var pStr = "op=CREATESURVEYQNS&prevaction=" + action;
			xmlhttpPost("bvcreatesurveyqns.php","CREATESURVEYQNS",pStr);    	
		} else {
		   var divdata = document.getElementById("DIVHOMEMESSAGE");
		}
	} else
	if (action == "INSERTNEWQUESTION") {
		if (str == "SUCCESS") {
			refreshUI = "NO";
			var pStr = "op=CREATESURVEYQNS&prevaction=" + action;
			xmlhttpPost("bvcreatesurveyqns.php","CREATESURVEYQNS",pStr);    	
		} else {
		   var divdata = document.getElementById("DIVHOMEMESSAGE");
		}
	} else
	if (action == "UPDATEINVITEE") {
		var divdata = document.getElementById("DIVINVITEEAREA");
	} else
	if (action == "REMOVEINVITEECOPY") {
		if (str == "SUCCESS") {
			refreshUI = "NO";
			var pStr = "op=COPYINVITEE2&prevaction=" + action;
			xmlhttpPost("bvcopyinvitees.php","COPYOLDINVITEE2",pStr); 	
		} else {
		   var divdata = document.getElementById("DIVHOMEMESSAGE");
		}
	} else
	if (action == "ADDITEM" || action == "REMOVEITEM") {
		if (str == "SUCCESS") {
			refreshUI = "NO";
			xmlhttpPost("bvcreateitemlist.php","CREATEITEMLIST","op=CREATEITEMLIST");    	
		} else {
		   var divdata = document.getElementById("DIVHOMEMESSAGE");
		}
	} else
	if (action == "REFRESHATTENDEEINFO") {
		var divdata = document.getElementById("DIVDATA");
	} else
	if (action == "UPDATEOTHERINVITEEINFO") {
		var divdata = document.getElementById("DIVATTENDEEINFO");
	} else
	if (action == "SHOWEMAILS"  || action == "SENDPARTYINVITES") {
		var divdata = document.getElementById("DIVEMAILCONTENT");
	}
	else {
		var divdata = document.getElementById("body");
	}
	
 		//loadingImage("ajaxloadimage",false);   //============================================================================
    if (refreshUI == "YES") { // REFRESH THE REGION ONLY IF REFRESHUI SET TO "YES"
		divdata.innerHTML = str;
		divdata.style.display = "";
	}
	else return flase;

    //============================================================================


}

function goHome() {
		refreshUI = "NO";
		document.location = "index.php";
}

function required(colvalue,colname) {
	if (colvalue == '' || colvalue == null) {
		alert("Please enter " + colname + ".");
		return false;
	}
	return true;
}

function validateEmailv2(email)
{
// a very simple email validation checking. 
// you can add more complex email checking if it helps 
    if(email.length <= 0)
	{
	  return true;
	}
    var splitted = email.match("^(.+)@(.+)$");
    if(splitted == null) return false;
    if(splitted[1] != null )
    {
      var regexp_user=/^\"?[\w-_\.]*\"?$/;
      if(splitted[1].match(regexp_user) == null) return false;
    }
    if(splitted[2] != null)
    {
      var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,4}$/;
      if(splitted[2].match(regexp_domain) == null) 
      {
	    var regexp_ip =/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;
	    if(splitted[2].match(regexp_ip) == null) return false;
      }// if
      return true;
    }
return false;
}

function cancelTask(divId) {
	document.getElementById(divId).style.display = "none";
}

function borderRed(col) {
	document.getElementById(col).style.borderColor="red";
	document.getElementById(col).focus();
}

function borderGreen(col) {
	document.getElementById(col).style.borderColor="green";
}

function init_content() {
	loadingImage("DIVVIDEO",true);
}

//function set_title(title) {
//	document.getElementById("divpagetitle").innerHTML = title;
//}


function loadingImage(displaydiv,displayflag) {
	var imgdiv = document.getElementById(displaydiv);
	if (displayflag) {
		imgdiv.innerHTML = '<img src="images/indicator_white.gif" alt="Loading Page" width="16" height="16" />';
		imgdiv.style.display = "";
	}
	else {
		imgdiv.innerHTML = "";
	}
}

function createPartyInvite() {
	if (document.getElementById("body").style.display == "none")
	    document.getElementById("body").style.display = "";
	xmlhttpPost("bvcreateinvite.php","CREATEPARTYINVITE","op=CREATEPARTYINVITE");  
}

function createsurvey() {
	if (document.getElementById("body").style.display == "none")
	    document.getElementById("body").style.display = "";
	xmlhttpPost("bvcreatesurvey.php","CREATESURVEY","op=CREATESURVEY");    	  	
}

function showMyInvites() {
	if (document.getElementById("body").style.display == "none")
	document.getElementById("body").style.display = "";
	xmlhttpPost("bvshowinvites.php","SHOWMYINVITES","op=SHOWMYINVITES");   
}

function showMyInvites(action) {
	var pStr = "op=SHOWMYINVITES&action=" + action;
	xmlhttpPost("bvshowinvites.php","SHOWMYINVITES",pStr);  
}

function showMySurveys() {
	if (document.getElementById("body").style.display == "none")
	document.getElementById("body").style.display = "";
	xmlhttpPost("bvshowsurveys.php","SHOWMYSURVEYS","op=SHOWMYSURVEYS");   
}

function showMySurveys(action) {
	var pStr = "op=SHOWMYSURVEYS&action=" + action;
	xmlhttpPost("bvshowsurveys.php","SHOWMYSURVEYS",pStr);  
}


function manageInvitees(inviteid) {
	var pStr = "op=MANAGEINVITEES&inviteid=" + inviteid;
	xmlhttpPost("bvcreateinvite2.php","INSERTPARTYINVITE2",pStr);
}

function manageQuestions(surveyid) {
	var pStr = "op=CREATESURVEYQNS&surveyid=" + surveyid;
	xmlhttpPost("bvcreatesurveyqns.php","CREATESURVEYQNS",pStr);
}

function addInvitee() {
	var inviteeid = document.getElementById("inviteeid").value;
	var inviteefirstname = document.getElementById("inviteefirstname").value;
	var inviteelastname = document.getElementById("inviteelastname").value;
	var emailaddress = document.getElementById("emailaddress").value;
	var ccemailaddress = document.getElementById("ccemailaddress").value;
	var homephone    = document.getElementById("homephone").value;
	var mobilephone  = document.getElementById("mobilephone").value;
	var notifyupdates= document.getElementById("notifyupdates").value;
	var allowadmin   = document.getElementById("allowadmin").value;
	var host   = document.getElementById("host").value;

	if (!required(inviteefirstname,"Invitee First Name")) {
		borderRed("inviteefirstname");
		return;
	} else borderGreen("inviteefirstname");

	if (!required(emailaddress,"Invitee Email Address")) {
		borderRed("emailaddress");
		return;
	}

	if (!validateEmailv2(emailaddress)) {
	   alert("Enter your email address in the correct format.");
	   borderRed("emailaddress");
	   return;
	} else borderGreen("emailaddress");

	if (ccemailaddress != null && !validateEmailv2(ccemailaddress)) {
	   alert("Enter your second email address in the correct format.");
	   borderRed("ccemailaddress");
	   return;
	} else borderGreen("ccemailaddress");

    var pStr = "op=ADDINVITEE&inviteefirstname=" + inviteefirstname +
	           "&inviteelastname=" + inviteelastname +
	           "&emailaddress=" + emailaddress +
	           "&ccemailaddress=" + ccemailaddress +
	           "&homephone=" + homephone +
	           "&mobilephone=" + mobilephone +
	           "&notifyupdates=" + notifyupdates +
	           "&allowadmin=" + allowadmin +
	           "&host=" + host +
			   "&inviteeid=" + inviteeid;

	xmlhttpPost("bvcreateinvite2.php","ADDINVITEE",pStr);    	
}

function removeInvitee(inviteeid) {
	var pStr = "op=REMOVEINVITEE&inviteeid=" + inviteeid;
	xmlhttpPost("bvcreateinvite2.php","REMOVEINVITEE",pStr);
}

function updateInvitee(inviteeid) {
	var pStr = "op=UPDATEINVITEE&inviteeid=" + inviteeid;
	xmlhttpPost("bvcreateinvite2.php","UPDATEINVITEE",pStr);
}

function removeInviteeCopy(inviteeid) {
	var pStr = "op=REMOVEINVITEE&inviteeid=" + inviteeid;
	xmlhttpPost("bvcreateinvite2.php","REMOVEINVITEECOPY",pStr);
}

function respondInvite(inviteid) {
	var pStr = "op=RESPONDINVITE&inviteid=" + inviteid;
	xmlhttpPost("respondinvite.php","RESPONDINVITE",pStr);
}

function submitNewInvite() {
	var partytitle = document.getElementById("partytitle").value;
	var partydesc  = document.getElementById("partydesc").value;
	var partydate  = document.getElementById("partydate").value;
	var respondbydate  = document.getElementById("respondbydate").value;
	var partytime  = document.getElementById("timehour").value + ":" +
	                 document.getElementById("timeminutes").value;
	var ampm       = document.getElementById("ampm").value;
	var imagefile  = document.getElementById("imagefile").value;
	var partylocation = document.getElementById("partylocation").value;
	var country    = document.getElementById("country").value;
	var partycity  = document.getElementById("partycity").value;
	var partystate  = document.getElementById("partystate").value;
	var zipcode    = document.getElementById("zipcode").value;
	var partylocationdesc = document.getElementById("partylocationdesc").value;
	var showmap = document.getElementById("showmap").value;
	var useitemlist = document.getElementById("useitemlist").value;

	if (!required(partytitle,"Party Title")) {
		borderRed("partytitle");
		return;
	} else borderGreen("partytitle");

	if (!required(partydate,"Party Date")) {
		borderRed("partydate");
		return;
	} else borderGreen("partydate");

	if (!required(partytime,"Party Time")) {
		borderRed("timehour");
		return;
	} else borderGreen("timehour");

	if (!required(ampm,"AM / PM")) {
		borderRed("ampm");
		return;
	} else borderGreen("ampm");

	if (!required(partylocation,"Street Address")) {
		borderRed("partylocation");
		return;
	} else borderGreen("partylocation");

	if (!required(partycity,"City")) {
		borderRed("partycity");
		return;
	} else borderGreen("partycity");

	if (!required(partystate,"State")) {
		borderRed("partystate");
		return;
	} else borderGreen("partystate");

	if (!required(zipcode,"Zip Code / Postal Code")) {
		borderRed("zipcode");
		return;
	} else borderGreen("zipcode");

    if (!required(country,"Country")) {
		borderRed("country");
		return;
	} else borderGreen("country");

	partytitle = escape(partytitle);
	partydesc  = escape(partydesc);
	partylocation = escape(partylocation);
	partylocationdesc = escape(partylocationdesc);
	
    var pStr = "op=INSERTPARTYINVITE&partytitle=" + partytitle +
	           "&partydesc=" + partydesc +
	           "&partydate=" + partydate +
	           "&partytime=" + partytime +
			   "&respondbydate=" + respondbydate +
	           "&ampm=" + ampm +
	           "&imagefile=" + imagefile +
	           "&partylocation=" + partylocation +
	           "&country=" + country +
	           "&partycity=" + partycity +
	           "&partystate=" + partystate +
	           "&zipcode=" + zipcode +
	           "&partylocationdesc=" + partylocationdesc +
	           "&showmap=" + showmap +
			   "&useitemlist=" + useitemlist;

	xmlhttpPost("bvcreateinvite.php","INSERTPARTYINVITE",pStr);    	
}

function submitNewSurvey() {
	var surveytitle = escape(document.getElementById("surveytitle").value);
	var surveydesc  = escape(document.getElementById("surveydesc").value);
	var expirydate  = document.getElementById("expirydate").value;
	var logoposition  = document.getElementById("logoposition").value;
	var layoutstyle  = document.getElementById("layoutstyle").value;
	var showquestionnumbers = document.getElementById("showquestionnumbers").value;
	var showpagenumbers = document.getElementById("showpagenumbers").value;
	var showrequired = document.getElementById("showrequired").value;
	var no_of_buttons = document.getElementById("no_of_buttons").value;
    var logotype="X";
	if (document.logotypeform.logotype[0].checked) {
		 logotype = 'IMAGE';
	     var logofile = document.getElementById("logofile").value;
	}
	if (document.logotypeform.logotype[1].checked) {
		logotype = 'URL';
	   var logofile = document.getElementById("logourl").value;
	}
	
	if (!required(surveytitle,"Survey Title")) {
		borderRed("surveytitle");
		return;
	} else borderGreen("surveytitle");

	if (!required(surveydesc,"Survey Description")) {
		borderRed("surveydesc");
		return;
	} else borderGreen("surveydesc");

    var pStr = "op=INSERTSURVEY&surveytitle=" + surveytitle +
	           "&surveydesc=" + surveydesc +
	           "&expirydate=" + expirydate +
	           "&logotype=" + logotype +
			   "&logofile=" + logofile +
	           "&logoposition=" + logoposition +
	           "&layoutstyle=" + layoutstyle +
	           "&showquestionnumbers=" + showquestionnumbers +
	           "&showpagenumbers=" + showpagenumbers +
	           "&showrequired=" + showrequired +
	           "&no_of_buttons=" + no_of_buttons;
			   
	xmlhttpPost("bvcreatesurvey.php","INSERTSURVEY",pStr);   
}

function registerAccount() {
	var username  = document.getElementById("username").value;
	var useremail = document.getElementById("useremail").value;
	var p1        = document.getElementById("pswd1").value;
	var p2        = document.getElementById("pswd2").value;
	var agreeterms = document.getElementById("agreeterms").value;

	if (!required(username,"your name")) {
		borderRed("username");
		return;
	} else borderGreen("username");

	if (!required(useremail,"email address")) {
		borderRed("useremail");
		return;
	}
	if (!validateEmailv2(useremail)) {
	   alert("Enter your email address in the correct format.");
	   borderRed("useremail");
	   return;
	}
	borderGreen("useremail");
	
	if (!required(p1,"password")) {
		borderRed("pswd1");
		return;
	}
	
	if (!required(p2,"password")) {
		borderRed("pswd2");
		return;
	}

	if (!document.getElementById("agreeterms").checked) {
		alert('You must agree terms and conditions to register.');
		borderRed("agreeterms");
		return;
	}

	if (p1 != p2) {
	   	alert("Your passwords do not match. Please re-enter same passwords.");
		document.getElementById("pswd1").value = "";
		document.getElementById("pswd2").value = "";
		borderRed("pswd2");
		borderRed("pswd1");
		return;
	}
	borderGreen("pswd1");
	borderGreen("pswd2");
	
	var pStr = "op=REGISTERACCOUNT&uname=" + username +
			   "&password1=" + p1 +
			   "&email=" + useremail;

	xmlhttpPost("bashregister.php","REGISTERACCOUNT",pStr);

}

function showRegisterScreen() {
	xmlhttpPost("bashregister.php","SHOWREGISTRATIONFORM","op=SHOWREGISTRATIONFORM");
}

function bashLogin() {
	var emailaddress = document.getElementById("emailaddress").value;
	var pswd123 = document.getElementById("pswd123").value;

    if (!required(emailaddress,"your registered email address")) {
		borderRed("emailaddress");
		return;
	} else borderGreen("emailaddress");

	if (!required(pswd123,"password")) {
		borderRed("pswd123");
		return;
	}
	
	var pStr = "op=USERLOGIN&emailaddress=" + emailaddress + "&pswd123=" + pswd123;
	
	xmlhttpPost("userlogin.php","USERLOGIN",pStr);
}

function logout() {
	xmlhttpPost("bashlogout.php","USERLOGOUT","");
}

function sendRegistrationConfEmail() {
	xmlhttpPost("bashregister.php","SENDCONFEMAIL","op=SENDCONFEMAIL");
}

function showAttendeeInfo(attendeeId) {
   var pStr = "op=SHOWATTENDEEINFO&id=" + attendeeId;
   xmlhttpPost("party_functions.php","SHOWATTENDEEINFO",pStr);
}

function refreshAttendeeInfo(eviteid) {
   var pStr = "op=REFRESHATTENDEEINFO&id=" + eviteid;
   xmlhttpPost("party_functions.php","REFRESHATTENDEEINFO",pStr);
}

function addPartyComment(inviteid) {
   if (document.getElementById("partycomment").value == '') {
       alert('Enter a comment or suggestion before clicking Submit.');
	   document.getElementById("partycomment").style.borderColor="red";
	   document.getElementById("partycomment").focus();
	   return;
   }
   var pStr = "op=ADDPARTYCOMMENT&inviteid=" + inviteid +
              "&comment=" + document.getElementById("partycomment").value;
   xmlhttpPost("party_functions.php","ADDPARTYCOMMENT",pStr);
}

function showComments(inviteid) {
   var pStr = "op=SHOWCOMMENTS&inviteid=" + inviteid;
   xmlhttpPost("party_functions.php","SHOWCOMMENTS",pStr);
}

function updateAttendeeInfo(attendeeId) {
	   var notify = (document.getElementById("notifyupdates").checked)?'Y':'N';
	   var pStr = "op=UPDATEATTENDEEINFO&id=" + attendeeId +
				   "&response=" + document.getElementById("response").value +
				   "&adults=" + document.getElementById("adults").value +
				   "&children=" + document.getElementById("children").value +
				   "&food=" + document.getElementById("food").value +
				   "&itemtobring=" + document.getElementById("itemtobring").value +
				   "&notify=" + notify;
	   xmlhttpPost("party_functions.php","UPDATEATTENDEEINFO",pStr);
}

function sendPartyInvites(inviteid) {
	var answer = confirm("This action will send email notifications to all the invitees in this invite those not responded. Press OK button to send email now or press Cancel button." );
	if (answer) {
	   var pStr = "op=SENDPARTYINVITES&inviteid=" + inviteid;
	   xmlhttpPost("party_functions.php","SENDPARTYINVITES",pStr);
	}
}

function showEmails(inviteid,allflag) {
   var pStr = "op=SHOWEMAILS&inviteid=" + inviteid + "&allflag=" + allflag;
   xmlhttpPost("party_functions.php","SHOWEMAILS",pStr);
}

function manageEmails(inviteid) {
   var pStr = "op=MANAGEEMAILS&inviteid=" + inviteid;
   xmlhttpPost("bvemails.php","MANAGEEMAILS",pStr);
}

function populateRespondBy() {
	if (!document.getElementById("respondbydate").value) {
		document.getElementById("respondbydate").value = document.getElementById("partydate").value;
	}
}

function validateRespondBy() {
	var partydate=document.getElementById("partydate").value;
	var respondbydate=document.getElementById("respondbydate").value;
	
}

function createItemList(inviteid) {
	var pStr = "op=CREATEITEMLIST&inviteid=" + inviteid;
	xmlhttpPost("bvcreateitemlist.php","CREATEITEMLIST",pStr);
}

function copyInvitees(inviteid) {
	var pStr = "op=COPYOLDINVITEES&inviteid=" + inviteid;
	xmlhttpPost("bvcopyinvitees.php","COPYOLDINVITEES",pStr);
}

function copyInvitee(inviteeid) {
	var pStr = "op=COPYOLDINVITEE&inviteeid=" + inviteeid;
	xmlhttpPost("bvcopyinvitees.php","COPYOLDINVITEE",pStr);
}

function addItem() {
	var itemname = document.getElementById("itemname").value;
	var itemcount = document.getElementById("itemcount").value;

	if (!required(itemname,"Item Name")) {
		borderRed("itemname");
		return;
	} else borderGreen("itemname");

    var pStr = "op=ADDITEM&itemname=" + itemname +
	           "&itemcount=" + itemcount;

	xmlhttpPost("bvcreateitemlist.php","ADDITEM",pStr);    	
}

function removeItem(itemid) {
	var pStr = "op=REMOVEITEM&itemid=" + itemid;
	xmlhttpPost("bvcreateitemlist.php","REMOVEITEM",pStr);
}

function updateInvite(inviteid) {
	var pStr = "op=UPDATEINVITE&inviteid=" + inviteid;
	xmlhttpPost("bvupdateinvite.php","UPDATEINVITE",pStr);
}

function submitUpdatedInvite() {
	var partytitle = document.getElementById("partytitle").value;
	var partydesc  = document.getElementById("partydesc").value;
	var partydate  = document.getElementById("partydate").value;
	var respondbydate  = document.getElementById("respondbydate").value;
	var partytime  = document.getElementById("timehour").value + ":" +
	                 document.getElementById("timeminutes").value;
	var ampm       = document.getElementById("ampm").value;
	var imagefile  = document.getElementById("imagefile").value;
	var partylocation = document.getElementById("partylocation").value;
	var partycity  = document.getElementById("partycity").value;
	var partystate  = document.getElementById("partystate").value;
	var zipcode    = document.getElementById("zipcode").value;
	var partylocationdesc = document.getElementById("partylocationdesc").value;
	var showmap = document.getElementById("showmap").value;
	var useitemlist = document.getElementById("useitemlist").value;

	if (!required(partytitle,"Party Title")) {
		borderRed("partytitle");
		return;
	} else borderGreen("partytitle");

	if (!required(partydate,"Party Date")) {
		borderRed("partydate");
		return;
	} else borderGreen("partydate");

	if (!required(partytime,"Party Time")) {
		borderRed("timehour");
		return;
	} else borderGreen("timehour");

	if (!required(ampm,"AM / PM")) {
		borderRed("ampm");
		return;
	} else borderGreen("ampm");

	if (!required(partylocation,"Street Address")) {
		borderRed("partylocation");
		return;
	} else borderGreen("partylocation");

	if (!required(partycity,"City")) {
		borderRed("partycity");
		return;
	} else borderGreen("partycity");

	if (!required(partystate,"State")) {
		borderRed("partystate");
		return;
	} else borderGreen("partystate");

	if (!required(zipcode,"Zip Code / Postal Code")) {
		borderRed("zipcode");
		return;
	} else borderGreen("zipcode");

    var pStr = "op=UPDATEPARTYINVITE&partytitle=" + partytitle +
	           "&partydesc=" + partydesc +
	           "&partydate=" + partydate +
	           "&partytime=" + partytime +
			   "&respondbydate=" + respondbydate +
	           "&ampm=" + ampm +
	           "&imagefile=" + imagefile +
	           "&partylocation=" + partylocation +
	           "&partycity=" + partycity +
	           "&partystate=" + partystate +
	           "&zipcode=" + zipcode +
	           "&partylocationdesc=" + partylocationdesc +
	           "&showmap=" + showmap +
			   "&useitemlist=" + useitemlist;

	xmlhttpPost("bvupdateinvite.php","UPDATEPARTYINVITE",pStr);    	
}

function updateOtherInviteeInfo(inviteeid) {
	var pStr = "op=UPDATEOTHERINVITEEINFO&inviteeid=" + inviteeid;
	xmlhttpPost("party_functions.php","UPDATEOTHERINVITEEINFO",pStr);
}

function deleteInvite(inviteid,invitetitle) {

	var answer = confirm("This action will delete invite '" + escape(invitetitle) + "' , all the invitees, messages and items created for the invite. The invitee information will still be retained to help you for future invites. Press OK button to delete the invite or click Cancel button." );
	if (answer) {
		var pStr = "op=DELETEINVITE&inviteid=" + inviteid;
		xmlhttpPost("party_functions.php","DELETEINVITE",pStr);
	}
}

function changeLogoType(type) {
  if (type == 'IMAGE') {
     document.getElementById("DIVLOGOTYPEIMAGE").style.display = "block";
     document.getElementById("DIVLOGOTYPEURL").style.display = "none";
  } else {
     document.getElementById("DIVLOGOTYPEIMAGE").style.display = "none";
     document.getElementById("DIVLOGOTYPEURL").style.display = "block";
  }
}

function createSurveyQuestion() {
	xmlhttpPost("bvcreateqn.php","CREATENEWQUESTION","op=CREATENEWQUESTION");
}

function submitNewQuestion() {
	var qnumber = document.getElementById("qnumber").value;
	var qname = escape(document.getElementById("qname").value);
	var qprompt = escape(document.getElementById("qprompt").value);
	var qadditionaltext = escape(document.getElementById("qadditionaltext").value);
	var qrequired = document.getElementById("qrequired").value;
	var displaytype = document.getElementById("displaytype").value;
	var displaywidth = 60; //document.getElementById("displaywidth").value;
	var displayheight = 1; //document.getElementById("displayheight").value;
	var qlist = document.getElementById("qlist").value;
	
	if (!required(qnumber,"Question Number")) { borderRed("qnumber"); return; } else borderGreen("qnumber");
	if (!required(qname,"Question Name"))     { borderRed("qname"); return;   } else borderGreen("qname");
	if (!required(qprompt,"Question Prompt")) { borderRed("qprompt"); return; } else borderGreen("qprompt");

    var pStr = "op=INSERTNEWQUESTION&qnumber=" + qnumber +
	           "&qname=" + qname +
	           "&qprompt=" + qprompt +
			   "&qadditionaltext=" + qadditionaltext +
	           "&qrequired=" + qrequired +
	           "&displaytype=" + displaytype +
	           "&displaywidth=" + displaywidth +
	           "&displayheight=" + displayheight +
	           "&qlist=" + qlist;
			   
	xmlhttpPost("bvcreateqn.php","INSERTNEWQUESTION",pStr);   	
}

//===========================================================================
function show_album_content(albumid) {
	var pStr = "op=SHOWALBUMCONTENT&albumid=" + albumid;
	xmlhttpPost("spjalbums.php","SHOWALBUMCONTENT",pStr);
}

function showHide(divname) {
	if (document.getElementById(divname).style.display == "none")
	    document.getElementById(divname).style.display = "";
	else
	    document.getElementById(divname).style.display = "none";
}

function comingSoon() {
	document.getElementById("body").innerHTML='<center><img src="images/comingSoon.jpg" border="0" /></center>';
	document.getElementById("body").style.display = "";
}
