var panelCounter		= 0;
var modalWait;
var myPanel;
var myBasket			= new Object();
var intX				= 150;
var intY				= 10;

intX					= calculateCenterPosition();

function setMyPanel(divID)
{
	try
	{				
		var panelHeader	= 'Nyoki Handmade London';
		var panelBody	= '';
		var panelFooter	= '<span class="pageFoot" style="align:left">Copyright &#169; 2011 Nyoki! All rights reserved.</span>';
		var currentMarkup;
		
		currentMarkup=divID;
		panelBody = document.getElementById(divID);
		showMyPanel(panelHeader,panelBody,panelFooter,'620px');	
	}
	catch(err)
	{
		alert('setMyPanel() Error\n'+err.message);
	}
}

function setMyLargePanel(divID,panelWidth)
{
	try
	{				
		var panelHeader	= 'Nyoki Handmade London';
		var panelBody	= '';
		var panelFooter	= '<span class="pageFoot" style="align:left">Copyright &#169; 2011 Nyoki! All rights reserved.</span>';
		var currentMarkup;
		
		currentMarkup=divID;
		panelBody = YAHOO.util.Dom.get(divID);
		
		intX = calculateCenterPosition(1050);
		showMyPanel(panelHeader,panelBody,panelFooter,panelWidth);	
		intX = calculateCenterPosition();
	}
	catch(err)
	{
		alert('setMyPanel() Error\n'+err.message);
	}
}

function showMyPanel(panelHeader,panelBody,panelFooter,panelWidth)
{
	try
	{
		panelCounter++;
		var tempPanelName="panel"+panelCounter;
		myPanel = new YAHOO.widget.Panel(tempPanelName,{ 
				                                            	width: panelWidth, 
				                                              	xy: [intX, intY], 
				                                              	close: true, 
				                                              	draggable: false, 
				                                              	zindex:4,
				                                              	modal: true,
				                                              	visible: false,
																dragOnly: true,
																effect:{effect:YAHOO.widget.ContainerEffect.FADE,duration:0.25}
				                                         } 
										 );
											 
		//Add key listener (Escape button) to the panel. By tapping the Esc button the displayed panel is closed.
		var kl = new YAHOO.util.KeyListener(document, { keys:27 }, {fn:myPanel.hide,scope:myPanel,correctScope:true},"keyup");
		myPanel.cfg.queueProperty("keylisteners", kl);
		
		myPanel.setHeader(panelHeader);
		myPanel.setBody(panelBody);
		myPanel.setFooter(panelFooter);
		myPanel.render(document.body);
		myPanel.show();
	}
	catch(e)
	{
		alert('showMyPanel() Error\n'+e.message)
	}
}

function showYesNoDialog(txtHeader,txtText,ID) 
{
	try
	{
		var myDialog
		
		// Define various event handlers for Dialog
		var handleYes = function() 
		{
			try
			{
				removeBasketItem(ID);
				myDialog.hide();
				//removeItem(item);
			}
			catch(e)
			{
				alert('handleYes() Error:\n'+e.message);
			}
		};
		
		var handleNo = function() 
		{
			try
			{
				myDialog.hide();
			}
			catch(e)
			{
				alert('handleNo() Error:\n'+e.message);
			}
		};
	 
		// Instantiate the Dialog
		myDialog = new YAHOO.widget.SimpleDialog("deleteItem", 
																		 { 
																		 	width: "300px",
																		   	fixedcenter: true,
																		   	visible: false,
																			modal: true,
																		   	draggable: true,
																		   	close: true,
																			modal: true,
																		   	text: txtText,
																		   	icon: YAHOO.widget.SimpleDialog.ICON_HELP,
																		   	constraintoviewport: true,
																		   	buttons: [	{ text:"Yes", handler:handleYes, isDefault:true },
																					  	{ text:"No",  handler:handleNo } ]
																		 } 
													 );
		myDialog.setHeader(txtHeader);
		
		// Render the Dialog
		myDialog.render(document.body);
		
		myDialog.show();
	} 
	catch(e)
	{
		alert('showYesNoDialog() Error:\n'+e.message);
	}
}

function generateMenu()
{
	try
	{
		var oMainMenu = new YAHOO.widget.Menu
		(
	        "products", 
	        {
	            position: "static", 
	            hidedelay: 750, 
	            lazyload: false, 
	            effect: 
				{ 
	                effect: YAHOO.widget.ContainerEffect.FADE,
	                duration: 0
	            } 
	        }
	    );
	
	    oMainMenu.render();
	}
	catch(e)
	{
		alert('generateMenu() Error:\n'+e.message);
	}
}

function generateMenubar()
{
	try
	{
		var oMainMenu = new YAHOO.widget.MenuBar
		(
	        "products", 
	        {
	            autosubmenudisplay: true, 
				position: "static", 
	            hidedelay: 750, 
	            lazyload: false, 
	            effect: 
				{ 
	                effect: YAHOO.widget.ContainerEffect.FADE,
	                duration: 0
	            } 
	        }
	    );
	
	    oMainMenu.render();
	}
	catch(e)
	{
		alert('generateMenu() Error:\n'+e.message);
	}
}

function generatePaginator()
{
	try
	{
		// Set up the application under the YAHOO.example namespace
		var Ex = YAHOO.namespace('nyoki');
		 
		Ex.content    = YAHOO.util.Dom.get('content');
		 
		Ex.handlePagination = function (state) 
		{
		    // Show the appropriate content for the requested page
		    Ex.content.className = 'page' + state.page;
		    
		    // Update the Paginator's state, confirming change
		    Ex.paginator.setState(state);
		};
		 
		// Create the Paginator widget and subscribe to its changeRequest event
		Ex.paginator = new YAHOO.widget.Paginator({
		    
			alwaysVisible : false,
			rowsPerPage : 1,
		    totalRecords : Ex.content.getElementsByTagName('div').length,
		    containers : 'paging',
			
			template : "{PreviousPageLink} {PageLinks} {NextPageLink}",
		    previousPageLinkLabel : "&lt;",
		    nextPageLinkLabel : "&gt;"
			
		});
		 
		Ex.paginator.subscribe('changeRequest', Ex.handlePagination);
		 
		// Render the Paginator into the configured container(s)
		Ex.paginator.render();
	} 
	catch(e){}
}

function displayItem(category,subcategory)
{
	try
	{
		var strUrl = strPath+"displayItem.php";
		var postData =	{	
							"category":category,
							"subcategory":subcategory,
							"action":"display"
						};
						
		postwith(strUrl,postData,'GET');
	}
	catch(e){}
}

function showItem(category,subcategory,item)
{
	try
	{
		var strUrl = strPath+"item.php";
		var postData =	{	
							"category":category,
							"subcategory":subcategory,
							"item":item
						};
						
		postwith(strUrl,postData,'GET');
	}
	catch(e){}
}

function displayBasket()
{
	try
	{
		var strUrl = strPath+"shoppingBasket.php";
		var postData =	{	
							"action":"display"
						};
						
		postwith(strUrl,postData,'POST');
	}
	catch(e){}
}

function register()
{
	try
	{
		var strUrl = strPath+"registration.php";
		var postData =	{	
							"action":"display"							
						};
						
		postwith(strUrl,postData,'GET');
	}
	catch(e){}
}

function login()
{
	try
	{
		var strUrl = strPath+"loggingin.php";
		var postData =	{	
							"action":"display"
						};
						
		postwith(strUrl,postData,'GET');
	}
	catch(e){}
}

function logout()
{
	try
	{
		var strUrl = strPath+"loggingin.php";
		var postData =	{	
							"action":"logOut"
						};
						
		postwith(strUrl,postData,'GET');
	}
	catch(e){}
}

function myAccount()
{
	try
	{
		var strUrl = "https://www.nyoki.co.uk/resources/myAccount.php";
		var postData =	{	
							"action":"display"
						};
						
		postwith(strUrl,postData,'GET');
	}
	catch(e){}
}

function addToBasket(itemID)
{
	try
	{
		var eleQty	= document.getElementById('itxt'+itemID);
		var chackSize		= false;
		var checkColor 		= false;
		var selectedSize 	= '';		
		var selectedColor	= '';
		
		try
		{
			var eleSize	= document.getElementById('selSize'+itemID);
			//Test the object
			eleSize.selectedIndex
			chackSize = true;
		}
		catch(e)
		{
			chackSize	= false;
		}
		
		try
		{
			var eleColor	= document.getElementById('selColor'+itemID);
			//Test the object
			eleColor.selectedIndex
			checkColor = true;
		}
		catch(e)
		{
			checkColor	= false;
		}
		
		if(chackSize)
		{
			if(eleSize.selectedIndex == 0)
			{
				eleSize.focus();
				warning = document.getElementById('warningSize');
				displayBlock(warning);
				return;
			}
			else
			{
				selectedSize = eleSize.options[eleSize.selectedIndex].value;
			}
		}
		
		if(checkColor)
		{
			if(eleColor.selectedIndex == 0)
			{
				eleColor.focus();
				warning = document.getElementById('warningColor');
				displayBlock(warning);
				return;
			}
			else
			{
				selectedColor = eleColor.options[eleColor.selectedIndex].value;
			}
		}
		
		var qty		= eleQty.value;
		
		var eleForm	= document.forms['form'+itemID];// getElementById('form'+itemID);
		var price	= eleForm.itemPrice.value;
		var name	= eleForm.itemName.value;
		var img		= eleForm.itemIMG.value;	
		var size	= selectedSize;
		var color	= selectedColor;
		
		if(!isInt(qty))
		{
			eleQty.value	= 1;
			qty				= 1;
		}		
		
		myBasket = new BasketItem(itemID,qty,price,name,img,size,color);
		//alert(strMyBasket)
		
		updateBasket(myBasket);
	}
	catch(e)
	{
		alert('addToBasket():\n'+e.message)
	}
}

function updateBasket(myBasket)
{
	try
	{
		var strUrl = strPath+"shoppingBasket.php";
		var postData = {
							"itemID":strRTrim(myBasket.itemID),
							"itemName":myBasket.itemName,
							"itemQty":myBasket.itemQty,
							"itemPrice":myBasket.itemPrice,
							"itemIMG":myBasket.itemIMG,
							"itemSize":myBasket.itemSize,
							"itemColor":myBasket.itemColor,
							"action":"add"
						}
		postwith(strUrl,postData,'POST');
	}
	catch(e)
	{
		alert('updateBasket():\n'+e.message);
	}
}

function updateBasketQTY()
{
	try
	{
		var strUrl = strPath+"shoppingBasket.php";
		var postData =	{	
							"action":"update"
						};
		
		
		var formObj = document.forms["frmBasket"];
		
		for (var i=0, len=formObj.elements.length; i<len; i++)
		{
			var element=formObj.elements[i];
			
			if(element.name.substr(0,4)=='iqty')
			{
				var item = strRTrim(element.name.substr(4,element.name.length));
				
				var itemQTY = element.value;
				
				if(!isInt(itemQTY))
				{
					element.value = 1;
					itemQTY = 1;
				}
				else if(itemQTY < 1)
				{
					element.value = 1;
					itemQTY = 1;
				}
				
				postData[item]=itemQTY;
			}
		}
		
		postwith(strUrl,postData,'POST');
	}
	catch(e)
	{
		alert('updateBasketQTY():\n'+e.message);
	}
}

function removeBasketItem(Id)
{
	try
	{
		var strUrl = strPath+"shoppingBasket.php";
		var postData =	{	
							"ID":Id,
							"action":"remove"
						};
		
		postwith(strUrl,postData,'GET');
	}
	catch(e)
	{
		alert('removeBasketItem():\n'+e.message);
	}
}

function checkout()
{
	try
	{
		var strUrl = strPath+"checkout.php";
		
		var postData =	{
							action:"display"
						};
		
		postwith(strUrl,postData,'POST');
	}
	catch(e)
	{
		alert('checkout():\n'+e.message);
	}
}

/**
 * Function takes the URL of the target page and an associative 
 * array of name/values paires and POSTs the data to the supplied 
 * URL by dynamically creating a form and then submitting it.
 * To insert a link into a page just use a normal anchor tag in the HTML and call the function.
 * <a href="javascript:postwith('post.aspx',{user:'peter',cc:'aus'})">click</a>
 * 
 * @param {URL} goTo String representing the URL.
 * @param {Object} postData Name value pair parameters.
 * @param {String}postMethod POST or GET, default POST.
 * @return {void}
 */
function postwith (goTo,postData,postMethod) 
{
	if(postMethod == 'undefined')
	{
		postMethod = 'POST';
	}
	
	var myForm = document.createElement("form");
	myForm.method=postMethod ;
	myForm.action = goTo ;
	
	for (var k in postData) 
	{
		var myInput = document.createElement("input") ;
		myInput.setAttribute("name", k) ;
		myInput.setAttribute("value", postData[k]);
		myForm.appendChild(myInput) ;
	}
	
	document.body.appendChild(myForm) ;
	myForm.submit() ;
	document.body.removeChild(myForm) ;
}

/**
 * Cunstractor
 */
function BasketItem()
{
	var a=arguments;
	var idx=0;
	
	this.itemID		= a[idx++];
	this.itemQty	= a[idx++];
	this.itemPrice	= a[idx++];
	this.itemName	= a[idx++];
	this.itemIMG	= a[idx++];
	this.itemSize	= a[idx++];
	this.itemColor = a[idx++];
}

function goT0(action)
{
	try
	{
		switch(action)
		{
			case 'babyshow':
				window.open('http://www.thebabyshow.co.uk/excel-london/company-page/?exhibitorid=14211')
			break;
		}
	}
	catch(e)
	{
		alert('goT0() Error:\n'+e.message)
	}
}

function calculateCenterPosition(intWidth)
{
	if(!intWidth)
	{
		intWidth = 620;
	}
	
	var windowInnerWidth;
	var windowInnerHeight;
	
	// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
	if (typeof window.innerWidth != 'undefined')
	{
		windowInnerWidth = window.innerWidth;
		windowInnerHeight = window.innerHeight;
	}
	// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
	else if (typeof document.documentElement != 'undefined' && 
			  typeof document.documentElement.clientWidth != 'undefined' && 
			  document.documentElement.clientWidth != 0)
	{
		windowInnerWidth = document.documentElement.clientWidth;
		windowInnerHeight = document.documentElement.clientHeight;
	}
	// older versions of IE
	else
	{
		windowInnerWidth = document.getElementsByTagName('body')[0].clientWidth;
		windowInnerHeight = document.getElementsByTagName('body')[0].clientHeight;
	}	
	
	if(windowInnerWidth>intWidth)
	{
		intWorkingVar = parseInt(windowInnerWidth - intWidth);
		
		intWorkingVar = parseInt(intWorkingVar/2);
	}
	else
	{
		intWorkingVar = 150
	}
	
	return intWorkingVar;
}

function showErrorMessage(domElel)
{
	domElel.style.display = 'inline';
	domElel.style.visibility = 'visible';
}

function hideErrorMessage(domElel)
{
	domElel.style.display = 'none';
	domElel.style.visibility = 'hidden';
}

function validateUserLogin()
{
	try
	{
		var userName 		= document.getElementById('txtEmail');
		var userPassword	= document.getElementById('txtPassword');
		var returnValue		= true;
		
		/*Check Username*/
		if(!isNotEmpty(userName.value))
		{
			showErrorMessage(document.getElementById('emailError'));
			returnValue = false;
		}
		else
		{
			if(!isEmail(userName.value))
			{
				showErrorMessage(document.getElementById('emailError'));
				returnValue = false;
			}
			else
			{
				hideErrorMessage(document.getElementById('emailError'));
			}					
		}
		
		/*Check Password*/
		if(!isNotEmpty(userPassword.value))
		{
			showErrorMessage(document.getElementById('passwordError'));
			returnValue = false;
		}
		else
		{
			if(!isAlphanumeric(userPassword.value))
			{
				showErrorMessage(document.getElementById('passwordError'));
				returnValue = false;
			}
			else
			{
				/*Check thee legth between 6 and 32 chars*/
				if(userPassword.value.length >= 6 && userPassword.value.length <= 12)
				{
					hideErrorMessage(document.getElementById('passwordError'));
				}
				else
				{
					showErrorMessage(document.getElementById('passwordError'));
					returnValue = false;
				}
			}					
		}
		
		if(returnValue)
		{
			var loginForm = document.getElementById('login');
			loginForm.submit();
		}
	}
	catch(e)
	{
		alert('validateUserLogin(): Error\n'+e.message)
	}
}

function validateRegistration()
{
	try
	{
		var title 		= document.getElementById('selSalutation');
		var name 		= document.getElementById('txtFirstname');
		var surname 	= document.getElementById('txtLastname');
		var email 		= document.getElementById('txtEmail');
		var phone		= document.getElementById('txtPhone1');
		
		var address1 	= document.getElementById("txtAddress1");
		var address2 	= document.getElementById("txtAddress1");
		var city 		= document.getElementById("txtCity");
		var postCode 	= document.getElementById("txtPostCode");
		var country 	= document.getElementById("txtCountry");
		
		var password 	= document.getElementById('txtPassword');
		var password2 	= document.getElementById('txtPassword2');
		var returnValue	= true;
		
		/*Check Salutation*/
		if(title.selectedIndex==0)
		{
			showErrorMessage(document.getElementById('SalutationError'));
			returnValue = false;
		}
		else
		{
			hideErrorMessage(document.getElementById('SalutationError'));
		}
		
		/*Check Fisrt Name*/
		if(!isNotEmpty(name.value))
		{
			showErrorMessage(document.getElementById('nameError'));
			returnValue = false;
		}
		else
		{
			if(!isString(name.value))
			{
				showErrorMessage(document.getElementById('nameError'));
				returnValue = false;
			}
			else
			{
				hideErrorMessage(document.getElementById('nameError'));
			}
		}
		
		/*Check Last Name*/
		if(!isNotEmpty(surname.value))
		{
			showErrorMessage(document.getElementById('surnameError'));
			returnValue = false;
		}
		else
		{
			if(!isString(surname.value))
			{
				showErrorMessage(document.getElementById('surnameError'));
				returnValue = false;
			}
			else
			{
				hideErrorMessage(document.getElementById('surnameError'));
			}
		}
		
		/*Check Email*/
		if(!isNotEmpty(email.value))
		{
			showErrorMessage(document.getElementById('emailError'));
			returnValue = false;
		}
		else
		{
			if(!isEmail(email.value))
			{
				showErrorMessage(document.getElementById('emailError'));
				returnValue = false;
			}
			else
			{
				hideErrorMessage(document.getElementById('emailError'));
			}					
		}
		
		/*Check Telephone*/
		if(isNotEmpty(phone.value))
		{
			if(!isPhoneNumber(phone.value))
			{
				showErrorMessage(document.getElementById('telephoneError'));
				returnValue = false;
			}
			else
			{
				hideErrorMessage(document.getElementById('telephoneError'));
				phone.value = isPhoneNumber(phone.value);
			}					
		}
		
		/*Cheeck Address1*/
		if(!isNotEmpty(address1.value))
		{
			showErrorMessage(document.getElementById('address1Error'));
			returnValue = false;
		}
		else
		{
			if(!isAddress(address1.value))
			{
				showErrorMessage(document.getElementById('address1Error'));
				returnValue = false;
			}
			else
			{
				hideErrorMessage(document.getElementById('address1Error'));
			}
		}
		
		/*Cheeck Address2*/
		if(isNotEmpty(address2.value))
		{
			if(!isAddress(address2.value))
			{
				showErrorMessage(document.getElementById('address2Error'));
				returnValue = false;
			}
			else
			{
				hideErrorMessage(document.getElementById('address2Error'));
			}
		}
		
		/*Cheeck City*/
		if(!isNotEmpty(city.value))
		{
			showErrorMessage(document.getElementById('cityError'));
			returnValue = false;
		}
		else
		{
			if(!isString(city.value))
			{
				showErrorMessage(document.getElementById('cityError'));
				returnValue = false;
			}
			else
			{
				hideErrorMessage(document.getElementById('cityError'));
			}
		}
		
		/*Cheeck PostCode*/
		if(!isNotEmpty(postCode.value))
		{
			showErrorMessage(document.getElementById('postCodeError'));
			returnValue = false;
		}
		else
		{
			if(!isPostcode(postCode.value))
			{
				showErrorMessage(document.getElementById('postCodeError'));
				returnValue = false;
			}
			else
			{
				hideErrorMessage(document.getElementById('postCodeError'));
			}
		}
				
		/*Check Password*/
		if(!isNotEmpty(password.value))
		{
			showErrorMessage(document.getElementById('passwordError'));
			returnValue = false;
		}
		else
		{
			if(!isAlphanumeric(password.value))
			{
				showErrorMessage(document.getElementById('passwordError'));
				returnValue = false;
			}
			else
			{
				/*Check the legth between 6 and 32 chars*/
				if(password.value.length >= 6 && password.value.length <= 12)
				{
					hideErrorMessage(document.getElementById('passwordError'));
				}
				else
				{
					showErrorMessage(document.getElementById('passwordError'));
					returnValue = false;
				}
			}					
		}
		
		/*Check Password2*/
		if(!isNotEmpty(password2.value))
		{
			showErrorMessage(document.getElementById('passwordError2'));
			returnValue = false;
		}
		else
		{
			if(!isAlphanumeric(password2.value))
			{
				showErrorMessage(document.getElementById('passwordError2'));
				returnValue = false;
			}
			else
			{
				/*Check the legth between 6 and 32 chars*/
				if(password2.value.length >= 6 && password2.value.length <= 12)
				{
					/*Check if password and password2 are the same*/
					if(password2.value == password.value)
					{
						hideErrorMessage(document.getElementById('passwordError2'));
					}
					else
					{
						showErrorMessage(document.getElementById('passwordError2'));
						returnValue = false;
					}
				}
				else
				{
					showErrorMessage(document.getElementById('passwordError2'));
					returnValue = false;
				}
			}						
		}
		
		if(returnValue)
		{
			var registerForm = document.getElementById('registration');
			registerForm.submit();
		}
	}
	catch(e)
	{
		alert('validateRegistration(): Error\n'+e.message)
	}
}

function validateAccountChange()
{
	try
	{
		var title 		= document.getElementById('selSalutation');
		var name 		= document.getElementById('txtFirstname');
		var surname 	= document.getElementById('txtLastname');
		var email 		= document.getElementById('txtEmail');
		var phone		= document.getElementById('txtPhone1');
		
		var address1 	= document.getElementById("txtAddress1");
		var address2 	= document.getElementById("txtAddress1");
		var city 		= document.getElementById("txtCity");
		var postCode 	= document.getElementById("txtPostCode");
		var country 	= document.getElementById("txtCountry");
		
		var password 	= document.getElementById('txtPassword');
		var password2 	= document.getElementById('txtPassword2');
		var returnValue	= true;
		
		/*Check Salutation*/
		if(title.selectedIndex==0)
		{
			showErrorMessage(document.getElementById('SalutationError'));
			returnValue = false;
		}
		else
		{
			hideErrorMessage(document.getElementById('SalutationError'));
		}
		
		/*Check Fisrt Name*/
		if(!isNotEmpty(name.value))
		{
			showErrorMessage(document.getElementById('nameError'));
			returnValue = false;
		}
		else
		{
			if(!isString(name.value))
			{
				showErrorMessage(document.getElementById('nameError'));
				returnValue = false;
			}
			else
			{
				hideErrorMessage(document.getElementById('nameError'));
			}
		}
		
		/*Check Last Name*/
		if(!isNotEmpty(surname.value))
		{
			showErrorMessage(document.getElementById('surnameError'));
			returnValue = false;
		}
		else
		{
			if(!isString(surname.value))
			{
				showErrorMessage(document.getElementById('surnameError'));
				returnValue = false;
			}
			else
			{
				hideErrorMessage(document.getElementById('surnameError'));
			}
		}
		
		/*Check Email*/
		if(!isNotEmpty(email.value))
		{
			showErrorMessage(document.getElementById('emailError'));
			returnValue = false;
		}
		else
		{
			if(!isEmail(email.value))
			{
				showErrorMessage(document.getElementById('emailError'));
				returnValue = false;
			}
			else
			{
				hideErrorMessage(document.getElementById('emailError'));
			}					
		}
		
		/*Check Telephone*/
		if(isNotEmpty(phone.value))
		{
			if(!isPhoneNumber(phone.value))
			{
				showErrorMessage(document.getElementById('telephoneError'));
				returnValue = false;
			}
			else
			{
				hideErrorMessage(document.getElementById('telephoneError'));
				phone.value = isPhoneNumber(phone.value);
			}					
		}
		
		/*Cheeck Address1*/
		if(!isNotEmpty(address1.value))
		{
			showErrorMessage(document.getElementById('address1Error'));
			returnValue = false;
		}
		else
		{
			if(!isAddress(address1.value))
			{
				showErrorMessage(document.getElementById('address1Error'));
				returnValue = false;
			}
			else
			{
				hideErrorMessage(document.getElementById('address1Error'));
			}
		}
		
		/*Cheeck Address2*/
		if(isNotEmpty(address2.value))
		{
			if(!isAddress(address2.value))
			{
				showErrorMessage(document.getElementById('address2Error'));
				returnValue = false;
			}
			else
			{
				hideErrorMessage(document.getElementById('address2Error'));
			}
		}
		
		/*Cheeck City*/
		if(!isNotEmpty(city.value))
		{
			showErrorMessage(document.getElementById('cityError'));
			returnValue = false;
		}
		else
		{
			if(!isString(city.value))
			{
				showErrorMessage(document.getElementById('cityError'));
				returnValue = false;
			}
			else
			{
				hideErrorMessage(document.getElementById('cityError'));
			}
		}
		
		/*Cheeck PostCode*/
		if(!isNotEmpty(postCode.value))
		{
			showErrorMessage(document.getElementById('postCodeError'));
			returnValue = false;
		}
		else
		{
			if(!isPostcode(postCode.value))
			{
				showErrorMessage(document.getElementById('postCodeError'));
				returnValue = false;
			}
			else
			{
				hideErrorMessage(document.getElementById('postCodeError'));
			}
		}
				
		/*Check Password*/
		if(isNotEmpty(password.value))
		{			
			/*Check Password*/
			if(!isAlphanumeric(password.value))
			{
				showErrorMessage(document.getElementById('passwordError'));
				returnValue = false;
			}
			else
			{
				/*Check the legth between 6 and 32 chars*/
				if(password.value.length >= 6 && password.value.length <= 12)
				{
					hideErrorMessage(document.getElementById('passwordError'));
				}
				else
				{
					showErrorMessage(document.getElementById('passwordError'));
					returnValue = false;
				}
			}
			
			/*Check Password2*/
			if(!isAlphanumeric(password2.value))
			{
				showErrorMessage(document.getElementById('passwordError2'));
				returnValue = false;
			}
			else
			{
				/*Check the legth between 6 and 32 chars*/
				if(password2.value.length >= 6 && password2.value.length <= 12)
				{
					/*Check if password and password2 are the same*/
					if(password2.value == password.value)
					{
						hideErrorMessage(document.getElementById('passwordError2'));
					}
					else
					{
						showErrorMessage(document.getElementById('passwordError2'));
						returnValue = false;
					}
				}
				else
				{
					showErrorMessage(document.getElementById('passwordError2'));
					returnValue = false;
				}
			}
		}
		
		if(returnValue)
		{
			var registerForm = document.getElementById('registration');
			registerForm.submit();
		}
	}
	catch(e)
	{
		alert('validateAccountChange(): Error\n'+e.message)
	}
}

function validatePaymentInfo()
{
	try
	{
		var title 		= document.getElementById('selSalutation');
		var name 		= document.getElementById('txtFirstname');
		var surname 	= document.getElementById('txtLastname');
		var email 		= document.getElementById('txtEmail');
		var phone		= document.getElementById('txtPhone1');
		
		var address1 	= document.getElementById("txtAddress1");
		var address2 	= document.getElementById("txtAddress1");
		var city 		= document.getElementById("txtCity");
		var postCode 	= document.getElementById("txtPostCode");
		var country 	= document.getElementById("txtCountry");
		
		var cardType 	= document.getElementById("selCardType");
		var cardNumber 	= document.getElementById("txtCardNumber");
		var expMonth 	= document.getElementById("selExpDateMonth");
		var expYear 	= document.getElementById("selExpDateYear");
		var cvn 		= document.getElementById("txtCVN");
		
		var password 	= document.getElementById('txtPassword');
		var password2 	= document.getElementById('txtPassword2');
		var returnValue	= true;
		
		/*Check Salutation*/
		if(title.selectedIndex==0)
		{
			showErrorMessage(document.getElementById('SalutationError'));
			returnValue = false;
		}
		else
		{
			hideErrorMessage(document.getElementById('SalutationError'));
		}
		
		/*Check Fisrt Name*/
		if(!isNotEmpty(name.value))
		{
			showErrorMessage(document.getElementById('nameError'));
			returnValue = false;
		}
		else
		{
			if(!isString(name.value))
			{
				showErrorMessage(document.getElementById('nameError'));
				returnValue = false;
			}
			else
			{
				hideErrorMessage(document.getElementById('nameError'));
			}
		}
		
		/*Check Last Name*/
		if(!isNotEmpty(surname.value))
		{
			showErrorMessage(document.getElementById('surnameError'));
			returnValue = false;
		}
		else
		{
			if(!isString(surname.value))
			{
				showErrorMessage(document.getElementById('surnameError'));
				returnValue = false;
			}
			else
			{
				hideErrorMessage(document.getElementById('surnameError'));
			}
		}
		
		/*Check Email*/
		if(!isNotEmpty(email.value))
		{
			showErrorMessage(document.getElementById('emailError'));
			returnValue = false;
		}
		else
		{
			if(!isEmail(email.value))
			{
				showErrorMessage(document.getElementById('emailError'));
				returnValue = false;
			}
			else
			{
				hideErrorMessage(document.getElementById('emailError'));
			}					
		}
		
		/*Check Telephone*/
		if(isNotEmpty(phone.value))
		{
			if(!isPhoneNumber(phone.value))
			{
				showErrorMessage(document.getElementById('telephoneError'));
				returnValue = false;
			}
			else
			{
				hideErrorMessage(document.getElementById('telephoneError'));
				phone.value = isPhoneNumber(phone.value);
			}					
		}
		
		/*Cheeck Address1*/
		if(!isNotEmpty(address1.value))
		{
			showErrorMessage(document.getElementById('address1Error'));
			returnValue = false;
		}
		else
		{
			if(!isAddress(address1.value))
			{
				showErrorMessage(document.getElementById('address1Error'));
				returnValue = false;
			}
			else
			{
				hideErrorMessage(document.getElementById('address1Error'));
			}
		}
		
		/*Cheeck Address2*/
		if(isNotEmpty(address2.value))
		{
			if(!isAddress(address2.value))
			{
				showErrorMessage(document.getElementById('address2Error'));
				returnValue = false;
			}
			else
			{
				hideErrorMessage(document.getElementById('address2Error'));
			}
		}
		
		/*Cheeck City*/
		if(!isNotEmpty(city.value))
		{
			showErrorMessage(document.getElementById('cityError'));
			returnValue = false;
		}
		else
		{
			if(!isString(city.value))
			{
				showErrorMessage(document.getElementById('cityError'));
				returnValue = false;
			}
			else
			{
				hideErrorMessage(document.getElementById('cityError'));
			}
		}
		
		/*Cheeck PostCode*/
		if(!isNotEmpty(postCode.value))
		{
			showErrorMessage(document.getElementById('postCodeError'));
			returnValue = false;
		}
		else
		{
			if(!isPostcode(postCode.value))
			{
				showErrorMessage(document.getElementById('postCodeError'));
				returnValue = false;
			}
			else
			{
				hideErrorMessage(document.getElementById('postCodeError'));
			}
		}
		
		/*Check Card Type*/
		if(cardType.selectedIndex==0)
		{
			showErrorMessage(document.getElementById('cardTypeError'));
			returnValue = false;
		}
		else
		{
			hideErrorMessage(document.getElementById('cardTypeError'));
		}
		
		/*Cheeck Card Number*/
		if(!isNotEmpty(cardNumber.value))
		{
			showErrorMessage(document.getElementById('curdNumberError'));
			returnValue = false;
		}
		else
		{
			if(!isValidCreditCard(cardNumber.value,cardType.options[cardType.selectedIndex].value))
			{
				showErrorMessage(document.getElementById('curdNumberError'));
				returnValue = false;
			}
			else
			{
				hideErrorMessage(document.getElementById('curdNumberError'));
			}
		}
		
		/*Check expitation date*/
		if(expMonth.selectedIndex == 0 || expYear.selectedIndex == 0)
		{
			showErrorMessage(document.getElementById('expirationError'));
			returnValue = false;
		}
		else
		{
			hideErrorMessage(document.getElementById('expirationError'));
		}
		
		/*Check cvn Card Verification Nubmer*/
		if(!isNotEmpty(cvn.value))
		{
			showErrorMessage(document.getElementById('CVNError'));
			returnValue = false;
		}
		else
		{
			if(!isValidcvv2Number(cvn.value,cardType.options[cardType.selectedIndex].value))
			{
				showErrorMessage(document.getElementById('CVNError'));
				returnValue = false;
			}
			else
			{
				hideErrorMessage(document.getElementById('CVNError'));
			}
		}
				
		/*Check Password*/
		if(!isNotEmpty(password.value))
		{
			showErrorMessage(document.getElementById('passwordError'));
			returnValue = false;
		}
		else
		{
			if(!isAlphanumeric(password.value))
			{
				showErrorMessage(document.getElementById('passwordError'));
				returnValue = false;
			}
			else
			{
				/*Check the legth between 6 and 32 chars*/
				if(password.value.length >= 6 && password.value.length <= 12)
				{
					hideErrorMessage(document.getElementById('passwordError'));
				}
				else
				{
					showErrorMessage(document.getElementById('passwordError'));
					returnValue = false;
				}
			}					
		}
		
		/*Check Password2*/
		if(!isNotEmpty(password2.value))
		{
			showErrorMessage(document.getElementById('passwordError2'));
			returnValue = false;
		}
		else
		{
			if(!isAlphanumeric(password2.value))
			{
				showErrorMessage(document.getElementById('passwordError2'));
				returnValue = false;
			}
			else
			{
				/*Check the legth between 6 and 32 chars*/
				if(password2.value.length >= 6 && password2.value.length <= 12)
				{
					/*Check if password and password2 are the same*/
					if(password2.value == password.value)
					{
						hideErrorMessage(document.getElementById('passwordError2'));
					}
					else
					{
						showErrorMessage(document.getElementById('passwordError2'));
						returnValue = false;
					}
				}
				else
				{
					showErrorMessage(document.getElementById('passwordError2'));
					returnValue = false;
				}
			}						
		}
		
		if(returnValue)
		{
			var registerForm = document.getElementById('registration');
			registerForm.submit();
		}
	}
	catch(e)
	{
		alert('validatePaymentInfo(): Error\n'+e.message)
	}
}
