/**
 * ====================================================================
 * About
 * ====================================================================
 * UserEdit is an ECMAScript library acting as a cross-browser wrapper for generating the editing of user details for MobileRota.com.

 * @version 1
 * @author: David Clouter
/**
 * <p>UserEdit is a utility class. Provides "static" methods for EdGE XML RPC calls,
 * @constructor
 */

var UserEdit = Class.extend({
	construct:function() {
		this.userId=null;
		this.fname=null;
		this.lname=null;
		this.email=null;
		this.mobileNumber=null;
		this.postcode=null;
		this.country=null;
		this.subscribed=null;
		this.company=null;
		this.companyName=null;
		this.countryName=null;
		this.previa=null;
		this.companiesList=new Array();
		this.countriesIdList=new Array();
		this.countriesList=new Array();
		this.countriesCodeList=new Array();
		this.countryCode=null;
		this.compQuery=null;
		this.countryQuery=null;
		this.phoneType="7";


		this.passwordQuery=null;
		this.updateQuery=null;
		this.subscribeQuery=null;
		this.activateDate=null;

		this.pattern=null;
		this.patternName=null;
		this.patternId=null;
		this.startDay=null;
		this.shifts=null;
		this.months=null;
		this.days=null;
		this.stateholidays=null;
		this.holidays=null;

		this.shiftsIdArray=new Array();
		this.shiftsNameArray=new Array();

		this.oldCompanyName=null;
		this.existingShift=true;

		this.validMonths=null;
		this.validDays=null;
		this.expires=null;
		this.holidayQuery=null;
		this.holidaysArray=null;

		this.phonesArray=null;
		this.masterPhone=null;
		this.masterIntPhone=null;
		this.unsubscribedPhonesArray=new Array();
		this.addPhoneQuery=null;
		this.getPhonesQuery=null;
		this.editLocation=null;
		this.expiringPhone=false;
		this.phoneTypeList=new Array('Please Select','Standard Java','Android','Blackberry','Blackberry Touchscreen','IPhone - Coming Soon');
		this.phoneTypeIdList=new Array(null,'7','1','2','3','4');
	},


	launchChangePhone:function(mobileNumber,intMobileNumber,code,mainPhone,phoneType)
	{
		launchChangePhoneWarning(this,this.keptNumber,mobileNumber,intMobileNumber,code,this.changeNumber,mainPhone, phoneType);
	},


	activateLinks:function()
	{
		document.getElementById("user1").className="activeSection";
		document.getElementById("user1link").href="#";
		document.getElementById("user1link").onclick=delegate(this,this.showAccount);

		document.getElementById("user2").className="activeSection";
		document.getElementById("user2link").href="#";
		document.getElementById("user2link").onclick=delegate(this,this.showDetails);

		document.getElementById("user3").className="activeSection";
		document.getElementById("user3link").href="#";
		//document.getElementById("user3link").onclick=delegate(this,this.launchChangePhone);
		document.getElementById("user3link").onclick=delegate(this,this.editPhones);

		document.getElementById("user4").className="activeSection";
		document.getElementById("user4link").href="#";
		document.getElementById("user4link").onclick=delegate(this,this.changePassword);



		document.getElementById("user5").className="activeSection";

		if(this.subscribed==1) {
			document.getElementById("user5link").href="#";
			document.getElementById("user5link").onclick=delegate(this,this.unsubscribe);
		}else{
			document.getElementById("user5link").href="#";
			document.getElementById("user5link").innerHTML="Subscribe To NewsLetter";
			document.getElementById("user5link").onclick=delegate(this,this.subscribe);
		}

		document.getElementById("user6").className="activeSection";
		document.getElementById("user6link").href="#";
		document.getElementById("user6link").onclick=delegate(this,this.editShift);

		document.getElementById("user7").className="activeSection";
		document.getElementById("user7link").href="#";
		document.getElementById("user7link").onclick=delegate(this,this.editHolidays);


		for(var i=0;i < this.phonesArray.length;i++) {
			if(this.phonesArray[i].getAttribute("primary")=="1") {
				this.masterPhone=this.phonesArray[i].getAttribute("mobileNumber");
				this.masterIntPhone=this.phonesArray[i].getAttribute("intMobileNumber");
			}
			var expDate=convertStringToDate(this.phonesArray[i].getAttribute("expires"));
			if(days_between(new Date(),expDate) <= 28){
				this.expiringPhone=true;
				this.unsubscribedPhonesArray.push(this.phonesArray[i]);
			}
		}
		if(this.expiringPhone==true) {
			var li=document.createElement("li");
			li.className="inactiveSection";
			li.id="user8";
			li.innerHTML='<a class="listItem" id="user8link" style="color:#FF0000;font-weight:bold">Subscribe To MobileRota</a>';
			document.getElementById("phases").appendChild(li);
		}
	},

	activateSubscribe:function() {
		if(document.getElementById("user8")) {
			document.getElementById("user8").className="activeSection";
			document.getElementById("user8link").href="#";
			document.getElementById("user8link").onclick=delegate(this,this.subscribePage);
		}
	},


	getCompaniesList:function()
	{
		try{
			this.compQuery=new WebEngine();
			var query=createXmlElement("getCompaniesList");
			this.compQuery.handleXML=delegate(this,this.parseCompaniesList);
			this.compQuery.postRequest(query,"Loading Companies");
		}catch(error) {
			alert("here is the error :: "+error);
		}
	},

	parseCompaniesList:function(obj)
	{
		if(this.compQuery.responseXML !=null) {
			var companies=this.compQuery.responseXML.selectSingleNode("//getCompaniesListResponse");
			var companiesList=companies.getElementsByTagName("company");

			for(var i=0; i < companiesList.length;i++) {
				this.companiesList.push(companiesList[i].getAttribute("companyName"));
				if(companiesList[i].getAttribute("companyId")==this.company) {
					this.companyName=companiesList[i].getAttribute("companyName");
				}
			}
		}
		this.getCountriesList(this.getCompanyShifts);
	},

	getCountriesList:function()
	{
		this.countryQuery=new WebEngine();
		var query=createXmlElement("getCountriesList");
		this.countryQuery.handleXML=delegate(this,this.parseCountriesList);
		this.countryQuery.postRequest(query,"Loading Countries");
	},

	parseCountriesList:function()
	{

		if(this.countryQuery.responseXML !=null) {
			var countries=this.countryQuery.responseXML.selectSingleNode("//getCountriesListResponse");
			var countriesList=countries.getElementsByTagName("country");

			for(var i=0; i < countriesList.length;i++) {
				this.countriesIdList.push(countriesList[i].getAttribute("id"));
				this.countriesList.push(countriesList[i].getAttribute("name"));
				this.countriesCodeList.push(countriesList[i].getAttribute("code"));
				if(countriesList[i].getAttribute("id")==this.country) {
					this.countryName=countriesList[i].getAttribute("name");
				}
			}
		}
		this.getCompanyShifts();
	},

	getCompanyShifts:function()
	{
		this.companyQuery=new WebEngine();
		var query=createXmlElement("findShifts");
		query.setAttribute("companyName",this.companyName);
		this.companyQuery.handleXML=delegate(this,this.parseShifts);
		this.companyQuery.postRequest(query,"Loading Shift Information");
	},

	parseShifts:function()
	{
		this.companyShiftArray=new Array();
		this.shiftsIdArray=new Array();
		this.shiftsNameArray=new Array();
		this.shiftsIdArray.push("null");
			this.shiftsNameArray.push("Generate New Shift Pattern");
		if(this.companyQuery.responseXML) {
			var shifts=this.companyQuery.responseXML.getElementsByTagName("pattern");
			var shiftArray=new Array();
			for(var s=0 ;s < shifts.length; s++) {
				this.shiftsIdArray.push(shifts[s].getAttribute("patternId"));
				this.shiftsNameArray.push(shifts[s].getAttribute("patternname"));
			}/*End For Loop*/

		}
		this.parseLocation();
	},

	parseLocation:function() {

		switch(this.editLocation)
			{
			case "details":
				this.showDetails();
			break;
			case "phones":
				this.editPhones();
			break;
			case "password":
				this.changePassword();
			break;
			case "editShift":
				this.editShift();
			break;
			case "holidays":
				this.editHolidays();
			break;
			default:
				this.showAccount();
			break;
			}
	},

	subscribePage:function() {
		var payPalForm=new PayPalForm();
		payPalForm.validMonths=this.validMonths;
		payPalForm.unsubscribedPhonesArray=this.unsubscribedPhonesArray;
		payPalForm.masterPhone=this.masterIntPhone;




		var mainPhone=null;
		var mainPhoneValid=true;
		for(var i=0 ; i < this.unsubscribedPhonesArray.length;i++) {
			var expDate=convertStringToDate(this.unsubscribedPhonesArray[i].getAttribute("expires"));
			if(this.unsubscribedPhonesArray[i].getAttribute("primary")=="1") {
				mainPhone=this.unsubscribedPhonesArray[i];
				if(days_between(new Date(),expDate) <= 28) {
					mainPhoneValid=false;
				}
			}
		}

		payPalForm.mainPhone=mainPhone;
		payPalForm.mainPhoneValid=mainPhoneValid;
		payPalForm.includeCharities=true;
		payPalForm.renderForm();


	},







	showAccount:function()
	{
		document.getElementById("instructionsHeader").style.display="block";
		document.getElementById("instructionsPanel").style.display="block";
		document.getElementById("formPanel").innerHTML="";
		document.getElementById("instructionsHeader").innerHTML="Your Shift Pattern";

		var div=document.createElement("div");
		div.className="legend";
		div.style.marginLeft="1px";
		div.style.marginRight="1px";
		div.innerHTML="<div class='legendText' style='padding-left:5px;'>Your Account</div>";
		document.getElementById("formPanel").appendChild(div);

		var paddingDiv=document.createElement("div");
		paddingDiv.style.paddingLeft="0px";
		paddingDiv.style.paddingRight="0px";
		paddingDiv.style.border="solid 1px #E7E7E7";
		paddingDiv.style.marginRight="1px";
		paddingDiv.style.marginLeft="1px";



		var table=document.createElement("table");

		table.cellpadding="0";
		table.cellSpacing="0";
		table.width="370px";
		var tbody=document.createElement("tbody");

			var tr=document.createElement("tr");
		tr.className="clsOdd";
		var td=document.createElement("td");
		td.className="form_description";
		td.style.fontSize="12px";
		td.style.paddingLeft="5px";
		td.colSpan="2";
		td.innerHTML="<br/>Here are the details of your MobileRota Account<br/>&nbsp;";
		tr.appendChild(td);
		tbody.appendChild(tr);

		var tr=document.createElement("tr");
		var td=document.createElement("td");
		td.className="instructionsHeader";
		td.style.paddingLeft="5px";
		td.style.fontSize="12px";
		td.colSpan="2";
		td.innerHTML="User Details";
		tr.appendChild(td);
		tbody.appendChild(tr);

		var tr=document.createElement("tr");
		tr.className="clsOdd";
		var td=document.createElement("td");
		td.innerHTML="Name";
		tr.appendChild(td);
		var td=document.createElement("td");
		td.innerHTML=this.fname+" "+this.lname;
		tr.appendChild(td);
		tbody.appendChild(tr);

		var tr=document.createElement("tr");
		tr.className="clsEven";
		var td=document.createElement("td");
		td.innerHTML="Email";
		tr.appendChild(td);
		var td=document.createElement("td");
		td.innerHTML=this.email;
		tr.appendChild(td);
		tbody.appendChild(tr);

		var tr=document.createElement("tr");
		tr.className="clsOdd";
		var td=document.createElement("td");
		td.innerHTML="Post Code";
		tr.appendChild(td);
		var td=document.createElement("td");
		td.innerHTML=this.postcode;
		tr.appendChild(td);
		tbody.appendChild(tr);

		var tr=document.createElement("tr");
		tr.className="clsEven";
		var td=document.createElement("td");
		td.innerHTML="Country";
		tr.appendChild(td);
		var td=document.createElement("td");
		td.innerHTML=this.countryName;
		tr.appendChild(td);
		tbody.appendChild(tr);

		var tr=document.createElement("tr");
		tr.className="clsOdd";
		var td=document.createElement("td");
		td.innerHTML="Company";
		tr.appendChild(td);
		var td=document.createElement("td");
		td.innerHTML=this.companyName;
		tr.appendChild(td);
		tbody.appendChild(tr);

		var tr=document.createElement("tr");
		tr.className="clsEven";
		var td=document.createElement("td");
		td.innerHTML="Shift";
		tr.appendChild(td);
		var td=document.createElement("td");
		td.innerHTML=this.patternName;
		tr.appendChild(td);
		tbody.appendChild(tr);

		var tr=document.createElement("tr");
		var td=document.createElement("td");
		td.className="instructionsHeader";
		td.style.fontSize="12px";
		td.style.paddingLeft="5px";
		td.colSpan="2";
		td.innerHTML="Registered Phones";
		tr.appendChild(td);
		tbody.appendChild(tr);

		for(var i=0; i < this.phonesArray.length;i++) {
			var tr=document.createElement("tr");
			tr.className="clsOdd";
			var td=document.createElement("td");
			td.innerHTML=this.phonesArray[i].getAttribute("description");
			tr.appendChild(td);
			var td=document.createElement("td");
			td.innerHTML=this.phonesArray[i].getAttribute("intMobileNumber");
			tr.appendChild(td);
			tbody.appendChild(tr);
		}



		var tr=document.createElement("tr");
		var td=document.createElement("td");
		td.className="instructionsHeader";
		td.style.fontSize="12px";
		td.style.paddingLeft="5px";
		td.colSpan="2";
		td.innerHTML="Subscription Details";
		tr.appendChild(td);
		tbody.appendChild(tr);

		var tr=document.createElement("tr");
		tr.className="clsOdd";
		var td=document.createElement("td");
		td.innerHTML="Subscription Started";
		tr.appendChild(td);
		var td=document.createElement("td");
		td.innerHTML=this.activateDate;
		tr.appendChild(td);
		tbody.appendChild(tr);



		if(this.validDays !="null") {
			var tr=document.createElement("tr");
			tr.className="clsEven";
			var td=document.createElement("td");
			td.innerHTML="Trial Days Remaining";
			tr.appendChild(td);
			var td=document.createElement("td");
			td.innerHTML=this.validDays;
			tr.appendChild(td);
			tbody.appendChild(tr);

		}else{
			var tr=document.createElement("tr");
			tr.className="clsEven";
			var td=document.createElement("td");
			td.innerHTML="Months Remaining";
			tr.appendChild(td);
			var td=document.createElement("td");
			td.innerHTML=this.validMonths;
			tr.appendChild(td);
			tbody.appendChild(tr);


		}

		/*var tr=document.createElement("tr");
			tr.className="clsOdd";
			var td=document.createElement("td");
			td.innerHTML="Subscription Expires";
			tr.appendChild(td);
			var td=document.createElement("td");

			td.innerHTML=this.expires;
			tr.appendChild(td);
			tbody.appendChild(tr);*/



		table.appendChild(tbody);

		var tbody=document.createElement("tbody");
		var tr=document.createElement("tr");

		if(this.expiringPhone==true) {
			var td=document.createElement("td");
			td.colSpan="2";
			td.style.paddingLeft="5px";
			td.style.fontWeight="bold";
			td.innerHTML="<br />Some of your phones have not been upgraded to the full version<br /><br />To Get the full version of MobileRota ";
			var link=document.createElement("a");
			link.href="#";
			link.onclick=delegate(this,this.subscribePage);
			link.innerHTML="Please Click Here";
			td.appendChild(link);
			tr.appendChild(td);

			tbody.appendChild(tr);
			table.appendChild(tbody);
		}
		paddingDiv.appendChild(table);
		document.getElementById("formPanel").appendChild(paddingDiv);

		this.previa=new Preview();
		//prev.setStartDate(this.startDate);
		this.previa.setParent(document.getElementById("instructionsPanel"));
		this.previa.demoMode=false;
		this.previa.userId=this.userId;
		this.previa.companyName=this.companyName;
		this.previa.parentForm=this;
		this.previa.startDate=this.startDate;
		this.previa.patternName=this.patternName;
		this.previa.startDay=this.startDay;
		//previa.parseShifts(this.shifts);
		this.previa.parseMonths(this.months);
		this.previa.parseDays(this.days);
		this.previa.parseStateHolidays(this.stateholidays);
		this.previa.parseHolidays(this.holidays);

		if(this.pattern !=null) {
			this.previa.pattern=this.pattern.split("");
		}else{
			this.previa.pattern=new Array("m","m","a","a","e","e","X","X");
		}
		//alert("here is the pattern  : "+previa.pattern);
		this.previa.generatePreview(false);
	},

	showDetails:function()
	{
		this.editLocation="details";
		this.oldCompanyName=this.companyName;
		document.getElementById("formPanel").innerHTML="";
		document.getElementById("instructionsHeader").style.display="block";
		document.getElementById("instructionsPanel").style.display="block";
		document.getElementById("instructionsHeader").innerHTML="Enter Your Details";
		document.getElementById("instructionsPanel").innerHTML='<p style="padding-left:20px;">Fields shown in red are mandatory, and must be supplied to complete the registration process.</p><p style="padding-left:20px;"><strong>User Details</strong></p><p style="padding-left:20px;">We use these details purely to supply you with the MobileRota software.  Any personal information is securely encrypted, and will not be used to send unsolicited calls, texts or emails.  We will not share this information with any third parties<br />(see our <a href="terms.php">Privacy Policy</a> for more information).</p>';

		var containerDiv=document.createElement("div");
		containerDiv.style.width="455px";
		document.getElementById("formPanel").appendChild(containerDiv);
		this.formObject=new FormObject(this,containerDiv);
		this.formObject.form.submitText="Update your details";
		this.formObject.form.method="POST";
		this.formObject.form.close=false;
		this.formObject.form.action=delegate(this,this.submitUserForm);

		var fieldset=this.formObject.form.addFieldset("User","User Details","Please Enter Your Details");


		var item=this.formObject.form.addItem(fieldset);
		item.parent=fieldset;
		item.type="email";
		item.id="email";
		item.label="Email Address";
		item.value=this.email;
		item.required=true;

		var item=this.formObject.form.addItem(fieldset);
		item.parent=fieldset;
		item.type="text";
		item.id="fname";
		item.label="First Name";
		item.value=this.fname;
		item.required=true;

		var item=this.formObject.form.addItem(fieldset);
		item.parent=fieldset;
		item.type="text";
		item.id="lname";
		item.label="Last Name";
		item.value=this.lname;
		item.required=true;

		var item=this.formObject.form.addItem(fieldset);
		item.parent=fieldset;
		item.type="test";
		item.id="postcode";
		item.label="Zip/Post Code";
		item.value=this.postcode;
		item.required=true;

		//var item=this.formObject.form.addItem(fieldset);
		//item.parent=fieldset;
		//item.type="select";
		//item.id="country";
		//item.label="Country";
		//item.optVal=this.countriesIdList.join();
		//item.optDisp=this.countriesList.join();
		//item.value=this.country;
		//item.jsfunction=delegate(this,this.showCountryCode);

		var fieldset2=this.formObject.form.addFieldset("user4",null,"Please Enter Your Company Name");

		var item=this.formObject.form.addItem(fieldset2);
		item.parent=fieldset;
		item.type="autoComplete";
		item.id="companyName";
		item.label="Company/Organisation";
		item.value=this.companyName;
		item.optVal=this.companiesList.join();
		item.required=true;

		this.formObject.drawForm();
	    this.formObject.showForm();
	},


	submitUserForm:function()
	{
		this.fname=document.getElementById("fname").value;
		this.lname=document.getElementById("lname").value;
		//this.companyName=document.getElementById("companyName").value;
		this.email=document.getElementById("email").value;
		//this.country=document.getElementById("country").value;

		//var selected=document.getElementById("country").selectedIndex;
		//this.countryCode=this.countriesCodeList[selected];

		this.postcode=document.getElementById("postcode").value;
		this.companyName=document.getElementById("companyName").value;
		this.sendUpdateForm();

	},

	sendUpdateForm:function()
	{
			this.updateQuery=new WebEngine();
			var query=createXmlElement("updateUser");
			query.setAttribute("userId",this.userId);
			query.setAttribute("fname",this.fname);
			query.setAttribute("lname",this.lname);
			query.setAttribute("email",this.email);
			query.setAttribute("postcode",this.postcode);
			query.setAttribute("companyName",this.companyName);
			//query.setAttribute("country",this.country);
			//query.setAttribute("countryCode",this.countryCode);
			this.updateQuery.handleXML=delegate(this,this.userUpdated);
			this.updateQuery.postRequest(query,"Loading Companies");
	},

	userUpdated:function()
	{
		if(this.companyName != this.oldCompanyName) {
			this.existingShift=false;
			this.patternId=null;
			if(confirm("Your new user details have been updated successfully but as you have changed your company\n\nWould you like to edit you shift pattern")==true) {
				this.getCompanyShifts();
			}
		}else{
			alert("Your new user details have been updated successfully");
		}
	},



	changePassword:function()
	{
		document.getElementById("instructionsHeader").style.display="block";
		document.getElementById("instructionsPanel").style.display="block";
		document.getElementById("formPanel").innerHTML="";
		document.getElementById("instructionsHeader").innerHTML="Change your password";
		document.getElementById("instructionsPanel").innerHTML='<p style="padding-left:20px;">Please enter you new password and we will email you confirmation of your password change</p>';
		var containerDiv=document.createElement("div");
		containerDiv.style.width="455px";
		document.getElementById("formPanel").appendChild(containerDiv);
		this.formObject=new FormObject(this,containerDiv);
		this.formObject.form.submitText="Change your password";
		this.formObject.form.method="POST";
		this.formObject.form.close=false;
		this.formObject.form.action=delegate(this,this.submitPasswordForm);

		var fieldset=this.formObject.form.addFieldset("User","Change Password","Please Enter Your New Password");

		var item=this.formObject.form.addItem(fieldset);
			item.parent=fieldset;
			item.type="password";
			item.id="password";
			item.label="New Password";
			item.value="";
			item.required=true;

			var item=this.formObject.form.addItem(fieldset);
			item.parent=fieldset;
			item.type="password";
			item.id="password2";
			item.label="Re-enter New Password";
			item.value="";
			item.required=true;

		this.formObject.drawForm();
	    this.formObject.showForm();
	},

	submitPasswordForm:function()
	{
		var password=document.getElementById("password").value;
		var password2=document.getElementById("password2").value;

		if(password==password2) {
			this.passwordQuery=new WebEngine();
			var query=createXmlElement("changePassword");
			query.setAttribute("id",this.userId);
			query.setAttribute("password",password);
			query.setAttribute("email",this.email);
			this.passwordQuery.handleXML=delegate(this,this.passwordChanged);
			this.passwordQuery.postRequest(query,"Changing Password");
		}else{
			alert("The two passwords that you have entered do not match");
		}
	},

	passwordChanged:function()
	{
		alert("Password changed successfully\n\nYour new password has been emailed to you");
		this.passwordQuery=null;
	},

	keptNumber:function(mobileNumber,intMobileNumber,code,phoneType)
	{
		hideWarning();
		document.getElementById("instructionsHeader").style.display="block";
		document.getElementById("instructionsPanel").style.display="block";
		document.getElementById("formPanel").innerHTML="";
		document.getElementById("instructionsHeader").innerHTML="Send to my Existing Number";
		document.getElementById("instructionsPanel").innerHTML='';

		this.formObject=new FormObject(this,document.getElementById("formPanel"));
		this.formObject.form.submitText="Send";
		this.formObject.form.method="POST";
		this.formObject.form.close=false;
		this.formObject.form.action=delegate(this,this.submitNumberForm);

		var fieldset=this.formObject.form.addFieldset("User","Change Mobile Phone","<p>Resending MobileRota to your existing number will require a payment of &pound;"+resendPayment+" before the application is sent to your new phone</p>");
		
	var item=this.formObject.form.addItem(fieldset);
		item.parent=fieldset;
		item.type="select";
		item.id="mobileType";
		item.label="Phone Type";
		item.optVal=this.phoneTypeIdList.join();
		item.optDisp=this.phoneTypeList.join();
		item.value=phoneType;
		item.jsfunction=delegate(this,this.checkPhoneType);
		item.required=true;

		var item=this.formObject.form.addItem(fieldset);
		item.parent=fieldset;
		item.type="mobileNumber";
		item.id="oldMobileNumber";
		item.disabled=true;
		item.label="Mobile Number";
		item.extra=this.countryCode;
		item.value=mobileNumber;
		item.required=false;

		var item=this.formObject.form.addItem(fieldset);
		item.parent=fieldset;
		item.type="hidden";
		item.id="mobileNumber";
		item.label="New Mobile Number";
		item.extra=this.countryCode;
		item.value=mobileNumber;
		item.required=true;

		var item=this.formObject.form.addItem(fieldset);
		item.parent=fieldset;
		item.type="hidden";
		item.id="mobileNumber2";
		item.label="Re-enter New Mobile Number";
		item.extra=this.countryCode;
		item.value=mobileNumber;
		item.required=true;

		this.formObject.drawForm();
	    this.formObject.showForm();

	    	this.previa=new Preview();
		//prev.setStartDate(this.startDate);
		this.previa.setParent(document.getElementById("instructionsPanel"));
		this.previa.demoMode=false;
		this.previa.userId=this.userId;
		this.previa.companyName=this.companyName;
		this.previa.parentForm=this;
		this.previa.startDate=this.startDate;
		this.previa.patternName=this.patternName;
		this.previa.startDay=this.startDay;
		//previa.parseShifts(this.shifts);
		this.previa.parseMonths(this.months);
		this.previa.parseDays(this.days);
		this.previa.parseStateHolidays(this.stateholidays);
		this.previa.parseHolidays(this.holidays);

		if(this.pattern !=null) {
			this.previa.pattern=this.pattern.split("");
		}else{
			this.previa.pattern=new Array("m","m","a","a","e","e","X","X");
		}
		//alert("here is the pattern  : "+previa.pattern);
		this.previa.generatePreview(false);
		/*var payPalForm=new PayPalForm();
		payPalForm.includeCharities=false;
		payPalForm.subscriptionForm=false;
		payPalForm.validMonths=this.validMonths;
		payPalForm.oldNumber=mobileNumber;
		payPalForm.masterPhone=mobileNumber;
		payPalForm.intMasterPhone=intMobileNumber;
		payPalForm.renderForm();*/

	},

	submitNumberForm:function()
	{
		var payPalForm=new PayPalForm();
		payPalForm.includeCharities=false;
		payPalForm.subscriptionForm=false;
		var oldNumber=document.getElementById("oldMobileNumber").value;
		var newNumber=document.getElementById("mobileNumber").value;
		var newNumber2=document.getElementById("mobileNumber2").value;
		if(newNumber != newNumber2) {
			alert("The two mobile Numbers that you have entered do not match");
			return
		}else{
			payPalForm.oldNumber=oldNumber;
			payPalForm.masterPhone=newNumber;
			payPalForm.phoneType=document.getElementById("mobileType").value;
			var codeStr=this.countryCode.replace("+","");

			var char1=newNumber[0];
			strippedNumber=newNumber;
			if(char1=="0") {
				strippedNumber=newNumber.substr(1);
			}
			intNumber=codeStr+strippedNumber;
			payPalForm.intMasterPhone=intNumber;
			payPalForm.renderForm();
		}
	},



	showSubscriptionWarning:function() {





	},

	addPhone:function() {
		this.addPhoneForm();
	},


	addPhoneForm:function()
	{
		hideWarning();
		showMask();
		var d1=getScreenSize();
		var offsetX=parseInt(d1.w)/2-250;
		var offsetY=parseInt(d1.h)/2-200;

		var warning=document.createElement("div");
		warning.style.width="500px";
		warning.id="processContainer";
		warning.style.left=offsetX+"px";
		warning.style.top=(parseInt(document.body.scrollTop)+200)+"px";
		var bodyObj=document.createElement("div");
		bodyObj.style.textAlign="left";
		warning.appendChild(bodyObj);

		this.formObject=new FormObject(this,bodyObj);
		this.formObject.form.submitText="Add Additional Mobile Number";
		this.formObject.form.method="POST";
		this.formObject.form.close=true;
		this.formObject.form.action=delegate(this,this.submitNewPhoneForm);
		var message="<p>When you add a new Mobile Phone it will be synchronised to your account and will display the Shift details exactly as they appear on the Main Users phone.</p>";
		message+="<p>The trial version of the application will now be sent to your new phone for you to try but before it is fully functional you will need to subscribe via the 'Your Account' page.";
		message+="<p>The charge for any additional phones is a one-off payment of just &pound;1.99 each.</p>";

		

		var fieldset=this.formObject.form.addFieldset("User","Add Additional Mobile Phone",message);

		var item=this.formObject.form.addItem(fieldset);
		item.parent=fieldset;
		item.type="hidden";
		item.id="parentNumber";
		item.disabled=true;
		item.label="Master Mobile Number";
		item.value=this.phonesArray[0].getAttribute("mobileNumber");
		item.required=false;

		var item=this.formObject.form.addItem(fieldset);
		item.parent=fieldset;
		item.type="test";
		item.id="mobileDescription";
		item.label="Description";
		item.value="";
		item.required=true;

		var item=this.formObject.form.addItem(fieldset);
		item.parent=fieldset;
		item.type="select";
		item.id="mobileType";
		item.label="Phone Type";
		item.optVal=this.phoneTypeIdList.join();
		item.optDisp=this.phoneTypeList.join();
		item.value=this.phoneType;
		item.jsfunction=delegate(this,this.checkPhoneType);
		item.required=true;


		var item=this.formObject.form.addItem(fieldset);
		item.parent=fieldset;
		item.type="mobileNumber";
		item.id="mobileNumber";
		item.label="New Mobile Number";
		item.extra=this.countryCode;
		item.value=this.mobileNumber;
		item.required=true;

		var item=this.formObject.form.addItem(fieldset);
		item.parent=fieldset;
		item.type="mobileNumber";
		item.id="mobileNumber2";
		item.label="Re-enter New Mobile Number";
		item.extra=this.countryCode;
		item.value=this.mobileNumber;
		item.required=true;



		this.formObject.drawForm();
	    this.formObject.showForm();

		var div=document.createElement("div");
		div.innerHTML="&nbsp;";
		warning.appendChild(div);
		document.body.appendChild(warning);
		//this.showCountryCode();
	},

	checkPhoneType:function()
	{
		var selected=document.getElementById("mobileType").selectedIndex;
		this.phoneType=this.phoneTypeIdList[selected];

		if(this.phoneType.toLowerCase()=="iphone") {
			if(confirm("MobileRota does not yet support the IPhone\nDo you wish to continue registering so that we can inform you when an IPhone version is made available?")==false){
				alert("Thank you for visiting MobileRota.");
				window.location="index.php";
			}
		}
	},

	submitNewPhoneForm:function()
	{
		showMask2();
		showProcess("Adding phone",false);
		var masterPhone=document.getElementById("parentNumber").value;
		var number1=document.getElementById("mobileNumber").value;
		var number2=document.getElementById("mobileNumber2").value;
		var description=document.getElementById("mobileDescription").value;

		if(this.mobileNumber != this.mobileNumber2) {
			alert("the two mobile Numbers that you have enetered do not match");
			return
		}
		document.body.removeChild(document.getElementById("processContainer"));
		this.addPhoneQuery=new WebEngine();
		var query=createXmlElement("addPhone");
		query.setAttribute("userId",this.userId);
		query.setAttribute("phoneType",this.phoneType);
		query.setAttribute("mobileNumber",number1);
		query.setAttribute("description",description);
		this.addPhoneQuery.handleXML=delegate(this,this.newPhoneAdded);
		this.addPhoneQuery.postRequest(query,"Adding Mobile Phone");


		//window.location="paypal.php?action=changeNumber&email="+this.email;

		hideMask();

	},

	newPhoneAdded:function(obj){
		//this.getMobilePhones();
		if(this.addPhoneQuery.responseXML.selectSingleNode("//CompositeResponse").getAttribute("errorCode")=="10") {
			alert("A User with this mobile Telephone Number\nis already registered with MobileRota.com");
		}else{
			launchThankyouAdditionalWarning(this.email);
			//alert("At this point you would normally get paypal in order to activate this subscription before sending the phone but while we are in debug mode the phone has been automatically added as active");
		}
		hideMask();
		hideMask2();
		this.addPhoneQuery=null;
	},

	removePhone:function(mobileNumber)
	{
		if(confirm("Are you sure you want to deactivate this phone?\n\n If you proceed this phone will no longer be able to synchronise with your shift pattern\n\nAnd you will not then be able to add this phone number again without contacting MobileRota")==true) {
			this.addPhoneQuery=new WebEngine();
			var query=createXmlElement("removePhone");
			query.setAttribute("userId",this.userId);
			query.setAttribute("mobileNumber",mobileNumber);
			this.addPhoneQuery.handleXML=delegate(this,this.getMobilePhones);
			this.addPhoneQuery.postRequest(query,"Removing Mobile Phone");
		}
	},

	getMobilePhones:function()
	{
		this.getPhonesQuery=new WebEngine();
		var query=createXmlElement("getPhones");
		query.setAttribute("userId",this.userId);
		this.getPhonesQuery.handleXML=delegate(this,this.parsePhones);
		this.getPhonesQuery.postRequest(query,"Getting Mobile Phones");
	},

	parsePhones:function()
	{
		this.phonesArray=this.getPhonesQuery.responseXML.selectSingleNode("//CompositeResponse/getPhonesResponse/mobilephones").getElementsByTagName("phone");
		this.unsubscribedPhonesArray=new Array();
		for(var i=0;i < this.phonesArray.length;i++) {
			if(this.phonesArray[i].getAttribute("primary")=="1") {
				this.masterPhone=this.phonesArray[i].getAttribute("intMobileNumber")
			}
			var expDate=convertStringToDate(this.phonesArray[i].getAttribute("expires"));
			if(days_between(new Date(),expDate) <= 28){
				this.expiringPhone=true;
				this.unsubscribedPhonesArray.push(this.phonesArray[i]);
			}
		}
		this.editPhones();
	},

	changeNumber:function(mobileNumber,intMobileNumber,code)
	{
		hideWarning();
		document.getElementById("instructionsHeader").style.display="block";
		document.getElementById("instructionsPanel").style.display="block";
		document.getElementById("formPanel").innerHTML="";
		document.getElementById("instructionsHeader").innerHTML="Change your Mobile Number";
		document.getElementById("instructionsPanel").innerHTML='';

		this.formObject=new FormObject(this,document.getElementById("formPanel"));
		this.formObject.form.submitText="Change your Mobile Number";
		this.formObject.form.method="POST";
		this.formObject.form.close=false;
		this.formObject.form.action=delegate(this,this.submitNumberForm);

		var fieldset=this.formObject.form.addFieldset("User","Change Mobile Number","<p>MobileRota is licensed on a per number basis and therefore changing your number will require payment of &pound;"+resendPayment+" before the application is sent to your new phone</p><p>Please Enter Your New Mobile Number</p>");

		
	var item=this.formObject.form.addItem(fieldset);
		item.parent=fieldset;
		item.type="select";
		item.id="mobileType";
		item.label="Phone Type";
		item.optVal=this.phoneTypeIdList.join();
		item.optDisp=this.phoneTypeList.join();
		item.value=this.phoneType;
		item.jsfunction=delegate(this,this.checkPhoneType);
		item.required=true;

		var item=this.formObject.form.addItem(fieldset);
		item.parent=fieldset;
		item.type="mobileNumber";
		item.id="oldMobileNumber";
		item.disabled=true;
		item.label="Old Mobile Number";
		item.extra=this.countryCode;
		item.value=mobileNumber;
		item.required=false;

		var item=this.formObject.form.addItem(fieldset);
		item.parent=fieldset;
		item.type="mobileNumber";
		item.id="mobileNumber";
		item.label="New Mobile Number";
		item.extra=this.countryCode;
		item.value=this.mobileNumber;
		item.required=true;

		var item=this.formObject.form.addItem(fieldset);
		item.parent=fieldset;
		item.type="mobileNumber";
		item.id="mobileNumber2";
		item.label="Re-enter New Mobile Number";
		item.extra=this.countryCode;
		item.value=this.mobileNumber;
		item.required=true;

		this.formObject.drawForm();
	    this.formObject.showForm();

	    	this.previa=new Preview();
		//prev.setStartDate(this.startDate);
		this.previa.setParent(document.getElementById("instructionsPanel"));
		this.previa.demoMode=false;
		this.previa.userId=this.userId;
		this.previa.companyName=this.companyName;
		this.previa.parentForm=this;
		this.previa.startDate=this.startDate;
		this.previa.patternName=this.patternName;
		this.previa.startDay=this.startDay;
		//previa.parseShifts(this.shifts);
		this.previa.parseMonths(this.months);
		this.previa.parseDays(this.days);
		this.previa.parseStateHolidays(this.stateholidays);
		this.previa.parseHolidays(this.holidays);

		if(this.pattern !=null) {
			this.previa.pattern=this.pattern.split("");
		}else{
			this.previa.pattern=new Array("m","m","a","a","e","e","X","X");
		}
		//alert("here is the pattern  : "+previa.pattern);
		this.previa.generatePreview(false);
	},

	unsubscribe:function()
	{
		this.subscribed=0;
		this.subscribeQuery=new WebEngine();
		var query=createXmlElement("changeSubscription");
		query.setAttribute("email",this.email);
		query.setAttribute("value","false");
		this.subscribeQuery.handleXML=delegate(this,this.subscriptionChanged);
		this.subscribeQuery.postRequest(query,"Unsubscribing user");
	},

	subscribe:function()
	{
		this.subscribed=1;
		this.subscribeQuery=new WebEngine();
		var query=createXmlElement("changeSubscription");
		query.setAttribute("email",this.email);
		query.setAttribute("value","true");
		this.subscribeQuery.handleXML=delegate(this,this.subscriptionChanged);
		this.subscribeQuery.postRequest(query,"Unsubscribing user");
	},

	subscriptionChanged:function()
	{
		if(this.subscribed==1) {
			document.getElementById("user5link").href="#";
			document.getElementById("user5link").innerHTML="Unsubscribe From News Letter";
			document.getElementById("user5link").onclick=delegate(this,this.unsubscribe);
		}else{
			document.getElementById("user5link").href="#";
			document.getElementById("user5link").innerHTML="Subscribe To NewsLetter";
			document.getElementById("user5link").onclick=delegate(this,this.subscribe);
		}
	},

	editShift:function() {
		document.getElementById("formPanel").innerHTML="";
		document.getElementById("instructionsHeader").style.display="none";
		document.getElementById("instructionsPanel").style.display="none";

		this.previa=new Preview();
		this.previa.setParent(document.getElementById("formPanel"));
		var date=new Date();
		date.setDate(1);
		this.previa.callback=delegate(this,this.getLatestShifts);
		this.previa.parentForm=this;
		this.previa.existingPattern=this.existingShift;
		this.previa.userId=this.userId;
		this.previa.startDate=this.startDate;
		this.previa.startDay=this.startDay;
		this.previa.patternId=this.patternId;
		this.previa.patternName=this.patternName;
		this.previa.parseShifts(this.shifts);
		this.previa.parseMonths(this.months);
		this.previa.companyName=this.companyName;
		this.previa.parseDays(this.days);
		this.previa.parseStateHolidays(this.stateholidays);
		this.previa.parseHolidays(this.holidays);
		this.previa.shiftsId=this.shiftsIdArray;
		this.previa.shiftsNames=this.shiftsNameArray;
		this.previa.userId=this.userId;
		this.previa.callback=delegate(this,this.updatePattern);
		if(this.pattern !=null) {
			this.previa.pattern=this.pattern.split("");
		}else{
			this.previa.pattern=new Array("m","m","a","a","e","e","X","X");
		}
		this.previa.generatePreview(true);
	},

	updatePattern:function() {
		this.startDate=this.previa.startDate;
		this.startDay=this.previa.startDay;
		this.patternId=this.previa.patternId;
		this.patternName=this.previa.patternName;
		this.pattern=this.previa.pattern.join("");
	},


	addHolidayForma:function(holStart,holEnd,holName,holId) {

		showMask();
		var d1=getScreenSize();
		var offsetX=parseInt(d1.w)/2-200;
		var offsetY=parseInt(d1.h)/2-200;

		var warning=document.createElement("div");
		warning.style.width="400px";
		warning.id="processContainer";
		warning.style.left=offsetX+"px";
		warning.style.top=(parseInt(document.body.scrollTop)+200)+"px";
		var head=document.createElement("div");
		head.id="instructionsHeader";
		head.style.textAlign="left";
		head.className="instructionsHeader";
		head.innerHTML="Important Information";
		warning.appendChild(head);
		var bodyObj=document.createElement("div");
		bodyObj.style.textAlign="left";
		bodyObj.style.padding="10px";
		warning.appendChild(bodyObj);

		var holidayObject=new FormObject(this,bodyObj);
		holidayObject.className="nextButton";
		holidayObject.form.submitText="Add Holiday";
		holidayObject.form.method="POST";
		holidayObject.form.close=true;
		if(holId !=null) {
			holidayObject.form.action=delegate(this,this.submitUpdateHoliday);
		}else{
			holidayObject.form.action=delegate(this,this.submitAddHoliday);
		}
		var fieldset=holidayObject.form.addFieldset("User","Add Holiday","Please Enter Your Holiday Details");

		var item=holidayObject.form.addItem(fieldset);
		item.parent=fieldset;
			item.id="holidayId";
			item.type="text";
			if(holName !=null) {
				item.value=holId;
			}else{
				item.value=null;
			}
			item.required=true;

		var item=holidayObject.form.addItem(fieldset);
			item.parent=fieldset;
			item.id="holidayName";
			item.type="text";
			item.label="Description";
			if(holName !=null) {
				item.value=holName;
			}else{
				item.value="";
			}
			item.required=true;

		var item=holidayObject.form.addItem(fieldset);
			item.parent=fieldset;
			item.id="holStartDate";
			item.type="date";
			item.label="Start Date";
			if(holStart !=null) {
				item.value=holStart;
			}else{
				item.value=convertDatetoString(new Date());
			}
			item.required=true;

		var item=holidayObject.form.addItem(fieldset);
			item.parent=fieldset;
			item.id="holEndDate";
			item.type="date";
			item.label="End Date";
			if(holEnd !=null) {
				item.value=holEnd;
			}else{
				item.value=convertDatetoString(new Date());
			}
			item.required=true;

			holidayObject.drawForm();
	    	holidayObject.showForm();

			var div=document.createElement("div");
			div.innerHTML="&nbsp;";
			warning.appendChild(div);
			document.body.appendChild(warning);
	},

	addHolidayForm:function(holStart,holEnd,holName,holId) {

		showMask();
		var d1=getScreenSize();
		var offsetX=parseInt(d1.w)/2-200;
		var offsetY=parseInt(d1.h)/2-200;

		var warning=document.createElement("div");
		warning.style.width="400px";
		warning.id="processContainer";
		warning.style.left=offsetX+"px";
		warning.style.top=(parseInt(document.body.scrollTop)+200)+"px";
		var head=document.createElement("div");
		head.id="instructionsHeader";
		head.style.textAlign="left";
		head.className="instructionsHeader";
		var tabl=document.createElement("table");
		tabl.width="100%";
		tabl.cellPadding="0";
		tabl.cellSpacing="0";
		var tbod=document.createElement("tbody");
		var tra=document.createElement("tr");
		var tdo=document.createElement("td");
		tdo.width="100%";
		if(holId != null) {
			tdo.innerHTML="Edit Holiday";
		}else{
			tdo.innerHTML="Add Holiday";
		}
		tra.appendChild(tdo);
		var tdo=document.createElement("td");
		tdo.style.paddingRight="10px";
		tdo.innerHTML="<a href='javascript:closeForms();'><img src='images/design/close.gif' width='15' height='15'/></a>";
		tra.appendChild(tdo);
		tbod.appendChild(tra);
		tabl.appendChild(tbod);
		head.appendChild(tabl);
		warning.appendChild(head);
		var bodyObj=document.createElement("div");
		bodyObj.style.textAlign="left";
		bodyObj.style.padding="10px";
		warning.appendChild(bodyObj);

		var holidayObject=new FormObject(this,bodyObj);
		if(holId != null) {
			holidayObject.form.submitText="Update Holiday";
		}else{
			holidayObject.form.submitText="Add Holiday";
		}

		holidayObject.form.method="POST";
		holidayObject.form.close=false;

		if(holId !=null) {
			holidayObject.form.action=delegate(this,this.submitUpdateHoliday);
		}else{
			holidayObject.form.action=delegate(this,this.submitAddHoliday);
		}

		var fieldset=holidayObject.form.addFieldset("User",null,"Please Enter Your Holiday Details");

		var item=holidayObject.form.addItem(fieldset);
		item.parent=fieldset;
			item.id="holidayId";
			item.type="hidden";
			if(holName !=null) {
				item.value=holId;
			}else{
				item.value=null;
			}
			item.required=true;

		var item=holidayObject.form.addItem(fieldset);
			item.parent=fieldset;
			item.id="holidayName";
			item.type="text";
			//item.description="Give your pattern a name - e.g. D-Shift or Blue Watch etc";
			item.label="Description";
			if(holName !=null) {
				item.value=holName;
			}else{
				item.value="";
			}
			item.required=true;

		var item=holidayObject.form.addItem(fieldset);
			item.parent=fieldset;
			item.id="startDate";
			//item.description="Click on the calendar and choose a start date for your holiday";
			item.type="date";
			item.label="Start Date";
			if(holStart !=null) {
				item.value=holStart;
			}else{
				item.value=convertDatetoString(new Date());
			}
			item.required=true;

		var item=holidayObject.form.addItem(fieldset);
			item.parent=fieldset;
			item.id="endDate";
			//item.description="Click on the calendar and choose a end date for your holiday";
			item.type="date";
			item.label="End Date";
			if(holEnd !=null) {
				item.value=holEnd;
			}else{
				item.value=convertDatetoString(new Date());
			}
			item.required=true;

			holidayObject.drawForm();
	    	holidayObject.showForm();



				var div=document.createElement("div");
			div.innerHTML="&nbsp;";
			warning.appendChild(div);

			document.body.appendChild(warning);

	},

	submitAddHoliday:function() {
		var sDate=document.getElementById("startDate").value;
		var eDate=document.getElementById("endDate").value;
		var hName=document.getElementById("holidayName").value;
		this.holidayQuery=new WebEngine();
		var query=createXmlElement("addHoliday");
		query.setAttribute("userId",this.userId);
		query.setAttribute("startDate",reFormatDate(sDate));
		query.setAttribute("patternStartDate",this.startDate);

		var date1=convertStringToDate(sDate);
		var date2=convertStringToDate(eDate);

		var hLength=days_between(date1,date2);
		if(hLength==0) {
			hLength="single";
		}
		query.setAttribute("length",hLength);
		query.setAttribute("name",hName);
		this.holidayQuery.handleXML=delegate(this,this.holidayAdded);
		this.holidayQuery.postRequest(query,"Adding Holiday");

		this.hideWarning();
	},

	removeHoliday:function(id) {
		this.holidayQuery=new WebEngine();
		var query=createXmlElement("removeHoliday");
		query.setAttribute("userId",this.userId);
		query.setAttribute("holidayId",id);
		query.setAttribute("patternStartDate",this.startDate);
		this.holidayQuery.handleXML=delegate(this,this.holidayRemoved);
		this.holidayQuery.postRequest(query,"Removing Holiday");
	},

	holidayAdded:function() {
		var user=this.holidayQuery.responseXML.selectSingleNode("//CompositeResponse/addHolidayResponse");
		var holidays=this.holidayQuery.responseXML.selectSingleNode("//CompositeResponse/addHolidayResponse/holidays");
		this.holidays=user.getAttribute("holidays");
		this.holidaysArray=holidays.getElementsByTagName("holiday");
		this.editHolidays("added");
	},

	holidayRemoved:function() {
		var user=this.holidayQuery.responseXML.selectSingleNode("//CompositeResponse/removeHolidayResponse");
		var holidays=this.holidayQuery.responseXML.selectSingleNode("//CompositeResponse/removeHolidayResponse/holidays");
		this.holidays=user.getAttribute("holidays");
		this.holidaysArray=holidays.getElementsByTagName("holiday");
		this.editHolidays("removed");
	},

	holidayUpdated:function() {
		var user=this.holidayQuery.responseXML.selectSingleNode("//CompositeResponse/updateHolidayResponse");
		var holidays=this.holidayQuery.responseXML.selectSingleNode("//CompositeResponse/updateHolidayResponse/holidays");
		this.holidays=user.getAttribute("holidays");
		this.holidaysArray=holidays.getElementsByTagName("holiday");
		this.editHolidays("updated");
	},


	submitUpdateHoliday:function() {
		var hId=document.getElementById("holidayId").value;
		var sDate=document.getElementById("startDate").value;
		var eDate=document.getElementById("endDate").value;
		var hName=document.getElementById("holidayName").value;
		this.holidayQuery=new WebEngine();
		var query=createXmlElement("updateHoliday");
		query.setAttribute("userId",this.userId);
		query.setAttribute("holidayId",hId);
		query.setAttribute("startDate",reFormatDate(sDate));
		query.setAttribute("patternStartDate",this.startDate);

		var date1=convertStringToDate(sDate);
		var date2=convertStringToDate(eDate);

		var hLength=days_between(date1,date2);
		query.setAttribute("length",hLength);
		query.setAttribute("name",hName);
		this.holidayQuery.handleXML=delegate(this,this.holidayUpdated);
		this.holidayQuery.postRequest(query,"Updating Holiday");
		this.hideWarning();
	},

	hideWarning:function() {
		document.body.removeChild(document.getElementById("processContainer"));
		hideMask();
	},

	getUserHolidays:function() {


	},

	editPhones:function() {
		this.editLocation="phones";
		document.getElementById("instructionsHeader").style.display="block";
		document.getElementById("instructionsPanel").style.display="block";

		document.getElementById("instructionsHeader").innerHTML="Your Shift Pattern";
		document.getElementById("instructionsPanel").innerHTML='<p>Please Edit Your Registered Phones</p>';
		document.getElementById("formPanel").innerHTML="";

		var div=document.createElement("div");
		div.className="instructionsHeader";
		div.innerHTML="Edit Registered Phones";
		document.getElementById("formPanel").appendChild(div);



		if(this.phonesArray !=null) {
			var addButton=document.createElement("input");
				addButton.className="nextButtonGreen";
				addButton.style.width="100%";
				addButton.style.height="30px";
				addButton.style.marginTop="10px";
				addButton.style.fontSize="12px";
				addButton.style.fontWeight="bold";
				addButton.style.padding="5px";
				addButton.type="button";
				addButton.value="Add New Mobile Phone";
				addButton.onclick=delegate(this,this.addPhone);
				document.getElementById("formPanel").appendChild(addButton);
			for(var i=0 ; i < this.phonesArray.length;i++) {
				var hol=document.createElement("table");
				hol.style.width="370px";
				hol.cellSpacing="0";
				hol.className="holidayTable";
				var tbody=document.createElement("tbody");

				var tr=document.createElement("tr");
				var td=document.createElement("td");
				if(this.phonesArray[i].getAttribute("primary")=="1") {
					td.className="instructionsTableHeader";
				}else{
					td.className="instructionsHeaderPale";
				}

				td.style.fontSize="12px";

				td.innerHTML=this.phonesArray[i].getAttribute("description");
				tr.appendChild(td);

				if(this.phonesArray[i].getAttribute("primary") != "1") {
					td.colSpan="2";
					var td=document.createElement("td");
					td.className="instructionsHeaderPale";
					td.style.paddingLeft="5px";
					td.style.paddingRight="5px";
					td.width="15";
					td.align="right";
					var img=document.createElement("img");
					img.onmouseover=delegate(this,showTip,"Remove "+this.phonesArray[i].getAttribute("description")+" from your Registered Phones");
					img.style.cursor="pointer"
					img.height="15";
					img.src="images/icons/disable.gif";
					img.onclick=delegate(this,this.removePhone,this.phonesArray[i].getAttribute("mobileNumber"))
					td.appendChild(img);
					tr.appendChild(td);
				}else{
					td.colSpan="3";
				}


				tbody.appendChild(tr);

				var tr=document.createElement("tr");
				tr.className="clsOdd";
				var td=document.createElement("td");
				td.width="50%";
				td.style.paddingLeft="20px";
				td.innerHTML="Mobile Number";
				tr.appendChild(td);
				var td=document.createElement("td");
				td.colSpan="2";
				td.innerHTML=this.phonesArray[i].getAttribute("intMobileNumber");
				tr.appendChild(td);


				tbody.appendChild(tr);

				var tr=document.createElement("tr");
				tr.className="clsOdd";
				var td=document.createElement("td");
				td.width="50%";
				td.style.paddingLeft="20px";
				td.innerHTML="Type Of Phone";
				tr.appendChild(td);
				var td=document.createElement("td");
				td.colSpan="2";

				var typeIndex=0;
				for(var p =0 ; p < this.phoneTypeIdList.length; p++) {
					if(this.phoneTypeIdList[p]==this.phonesArray[i].getAttribute("phoneType")) {
						typeIndex=p;
					}
				}
				td.innerHTML=this.phoneTypeList[typeIndex];
				tr.appendChild(td);
				tbody.appendChild(tr);

				/*var tr=document.createElement("tr");
				tr.className="clsOdd";
				var td=document.createElement("td");
				td.width="50%";
				td.style.paddingLeft="20px";
				td.innerHTML="Model";
				tr.appendChild(td);
				var td=document.createElement("td");
				td.colSpan="2";
				td.innerHTML=this.phonesArray[i].getAttribute("model");
				tr.appendChild(td);
				tbody.appendChild(tr);*/

				/*var tr=document.createElement("tr");
				tr.className="clsOdd";
				var td=document.createElement("td");
				td.width="50%";
				td.style.paddingLeft="20px";
				td.innerHTML="Expires";
				tr.appendChild(td);
				var td=document.createElement("td");
				td.colSpan="2";
				td.innerHTML=this.phonesArray[i].getAttribute("expires");
				tr.appendChild(td);
				tbody.appendChild(tr);*/

				var tr=document.createElement("tr");
				tr.className="clsOdd";
				var td=document.createElement("td");
				td.width="50%";
				td.style.fontSize="12px";
				td.style.fontWeight="bold";
				td.style.paddingLeft="20px";
				td.className="nextButton";
				//td.innerHTML="Change Mobile Phone";
				//td.onclick=delegate(this,this.launchChangePhone,this.phonesArray[i].getAttribute("mobileNumber"))
				//tr.appendChild(td);
				var td=document.createElement("td");
				td.colSpan="3";
				td.className="nextButtonRed";
				td.style.paddingLeft="5px";
				td.style.paddingRight="5px";
				td.style.fontSize="12px";
				td.style.fontWeight="bold";
				td.style.cursor="pointer";
				td.style.textAlign="right";
				td.onclick=delegate(this,this.launchChangePhone,this.phonesArray[i].getAttribute("mobileNumber"),this.phonesArray[i].getAttribute("intMobileNumber"),this.countryCode,this.phonesArray[i].getAttribute("primary"),this.phonesArray[i].getAttribute("phoneType"));
				td.innerHTML="I have Changed/Reset my Handset - Please re-send MobileRota";
				// Change This Mobile Phone";
				tr.appendChild(td);
				tbody.appendChild(tr);

				hol.appendChild(tbody);
				document.getElementById("formPanel").appendChild(hol);


			}


		}

		var addButton=document.createElement("input");
		addButton.className="nextButtonGreen";
		addButton.style.width="100%";
		addButton.style.height="30px";
		addButton.style.fontSize="12px";
		addButton.style.fontWeight="bold";
		addButton.style.padding="5px";
		addButton.type="button";
		addButton.value="Add New Mobile Phone";
		addButton.onclick=delegate(this,this.addPhone);
		document.getElementById("formPanel").appendChild(addButton);

		this.previa=new Preview();
		this.previa.setParent(document.getElementById("instructionsPanel"));
		this.previa.demoMode=false;
		this.previa.userId=this.userId;
		this.previa.companyName=this.companyName;
		this.previa.parentForm=this;
		this.previa.startDate=this.startDate;
		this.previa.patternName=this.patternName;
		this.previa.startDay=this.startDay;
		this.previa.parseMonths(this.months);
		this.previa.parseDays(this.days);
		this.previa.parseStateHolidays(this.stateholidays);
		this.previa.parseHolidays(this.holidays);

		if(this.pattern !=null) {
			this.previa.pattern=this.pattern.split("");
		}else{
			this.previa.pattern=new Array("m","m","a","a","e","e","X","X");
		}
		this.previa.generatePreview(false);

	},


	editHolidays:function(description) {

		this.editLocation="holidays";
		document.getElementById("instructionsHeader").style.display="block";
		document.getElementById("instructionsPanel").style.display="block";

		document.getElementById("instructionsHeader").innerHTML="Your Shift Pattern";
		document.getElementById("instructionsPanel").innerHTML='<p>Please Edit Your Holdays</p>';
		document.getElementById("formPanel").innerHTML="";

		var div=document.createElement("div");
		div.className="instructionsHeader";
		div.innerHTML="Edit Holidays";
		document.getElementById("formPanel").appendChild(div);


		if(this.holidaysArray !=null) {
			var addButton=document.createElement("input");
			addButton.className="nextButtonGreen";
			addButton.style.width="100%";
			addButton.style.height="30px";
			addButton.style.fontSize="12px";
			addButton.style.fontWeight="bold";
			addButton.style.padding="5px";
			addButton.style.marginTop="20px";
			addButton.type="button";
			addButton.value="Add Holiday";
			addButton.onclick=delegate(this,this.addHolidayForm);
			document.getElementById("formPanel").appendChild(addButton);
			for(var i=0 ; i < this.holidaysArray.length;i++) {
				var hol=document.createElement("table");
				hol.style.width="370px";
				hol.className="holidayTable";
				var tbody=document.createElement("tbody");
				var tr=document.createElement("tr");
				var td=document.createElement("td");
				td.className="instructionsHeader";
				td.style.fontSize="12px";
				td.colSpan="6";
				td.innerHTML=this.holidaysArray[i].getAttribute("name");
				tr.appendChild(td);
				tbody.appendChild(tr);

				var tr=document.createElement("tr");
				var td=document.createElement("td");

				var dStr=formatSQLDate(this.holidaysArray[i].getAttribute("startDate"));
				var nDate=convertStringToDate(dStr);

				nDate.setDate(nDate.getDate()+parseInt(this.holidaysArray[i].getAttribute("length")));
				td.innerHTML=dStr;
				tr.appendChild(td);

				var td=document.createElement("td");
				td.innerHTML="<strong>-</strong>";
				tr.appendChild(td);

				var td=document.createElement("td");
				td.innerHTML=convertDatetoString(nDate);
				tr.appendChild(td);

				var td=document.createElement("td");
				td.innerHTML=" ";
				tr.appendChild(td);

				var td=document.createElement("td");
				var img=document.createElement("img");
				img.src="images/icons/edit3.gif";
				eval("img.onclick=function(){editHoliday("+this.holidaysArray[i].getAttribute("id")+",'"+this.holidaysArray[i].getAttribute("name")+"','"+formatSQLDate(this.holidaysArray[i].getAttribute("startDate"))+"','"+convertDatetoString(nDate)+"');};");
				td.appendChild(img);
				tr.appendChild(td);

				var td=document.createElement("td");
				var img=document.createElement("img");
				img.height="15";
				img.src="images/icons/disable.gif";
				eval("img.onclick=function(){removeHoliday("+this.holidaysArray[i].getAttribute("id")+");};");
				td.appendChild(img);
				tr.appendChild(td);
				tbody.appendChild(tr);
				hol.appendChild(tbody);
				document.getElementById("formPanel").appendChild(hol);
			}
		}
		var addButton=document.createElement("input");
		addButton.className="nextButtonGreen";
		addButton.style.width="100%";
		addButton.style.height="30px";
		addButton.style.fontSize="12px";
		addButton.style.fontWeight="bold";
		addButton.style.padding="5px";
		addButton.style.marginTop="20px";
		addButton.type="button";
		addButton.value="Add Holiday";
		addButton.onclick=delegate(this,this.addHolidayForm);
		document.getElementById("formPanel").appendChild(addButton);

		this.previa=new Preview();
		this.previa.setParent(document.getElementById("instructionsPanel"));
		this.previa.demoMode=false;
		this.previa.userId=this.userId;
		this.previa.companyName=this.companyName;
		this.previa.parentForm=this;
		this.previa.startDate=this.startDate;
		this.previa.patternName=this.patternName;
		this.previa.startDay=this.startDay;
		this.previa.parseMonths(this.months);
		this.previa.parseDays(this.days);
		this.previa.parseStateHolidays(this.stateholidays);
		this.previa.parseHolidays(this.holidays);

		if(this.pattern !=null) {
			this.previa.pattern=this.pattern.split("");
		}else{
			this.previa.pattern=new Array("m","m","a","a","e","e","X","X");
		}
		this.previa.generatePreview(false,true);

		if(description !=null) {
			launchSynchroniseHolidaysHelp(description);
		}
	},




	showCountryCode:function()
	{
		var selected=document.getElementById("country").selectedIndex;
		this.countryCode=this.countriesCodeList[selected];
		this.country=document.getElementById("country").value;
		if(document.getElementById("mobileNumberCode") !=null) {
			document.getElementById("mobileNumberCode").value=this.countryCode;
			document.getElementById("mobileNumber2Code").value=this.countryCode;
		}
	},

	shiftPatternSubmitted:function() {
		launchSynchroniseShiftHelp("updated");
	}
});

function removeHoliday(id) {
		if(confirm("Are You Sure you wish to remove this holiday")==true) {
			userEdit.removeHoliday(id);
		}
	}

function editHoliday(id,name,startDate,endDate) {
	showMask();
		userEdit.addHolidayForm(startDate,endDate,name,id);
	}

function closeForms() {
	hideMask();
	hideMask2();
	if(document.getElementById("processContainer") !=null) {
		document.body.removeChild(document.getElementById("processContainer"));
	}
	if(document.getElementById("warningContainer") !=null) {
		document.body.removeChild(document.getElementById("warningContainer"));
	}
}

function noWapEdit() {
	hideWarning();
}


