//define universal reference to "staticcontent"
var crossobj=document.all? document.all.staticcontent : document.getElementById("staticcontent")

//define reference to the body object in IE
var iebody=(document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body

var uploadClicked = false;
var changesDone = false;
var newPhotoUploadClicked = false;
var themeIsLoading = 0;

function goToEditMode()
{
	//hide edit mode link
	$("#lnkGotoEditMode").hide();
	$("#lnkSaveChanges,#lnkCancelChanges,#colorScheme").show();
	$("#pizzaHeaderImg,#tenPercentOffImg,#middlePizzaImg,#footerBackImg,#pizzaLogo,#welcomeText").css({border:'dashed 1px green',cursor:'pointer'});
	$("#pizzaHeaderImg,#tenPercentOffImg,#middlePizzaImg,#footerBackImg,#pizzaLogo,#welcomeText").addClass("editMode");
}

function leaveEditMode(method)
{
	$("#lnkGotoEditMode").show();
	$("#lnkSaveChanges,#lnkCancelChanges,#colorScheme").hide();
	$("#pizzaHeaderImg,#tenPercentOffImg,#middlePizzaImg,#footerBackImg,#pizzaLogo,#welcomeText").css({border:'solid thin red',cursor: 'default'});
	$("#pizzaHeaderImg,#tenPercentOffImg,#middlePizzaImg,#footerBackImg,#pizzaLogo,#welcomeText").removeClass("editMode");
	//window.location = "index.php";
}

function changeColorScheme(color)
{
	var selectedTemplate = $("#hiddenSelectedTemplate").val();
	$("link[href^=Templates/template"+selectedTemplate+"/themes]").attr("href","Templates/template"+selectedTemplate+"/themes/"+color+".css");
	changesDone = true;
}


function showUploadForm(imageId)
{
	
	//define universal dsoc left point
    var dsocleft=document.all? iebody.scrollLeft : pageXOffset
    
    //define universal dsoc top point
    var dsoctop=document.all? iebody.scrollTop : pageYOffset

	$("#mask2").fadeIn("200");

	//$("#mask2").css({width:'957px'});

	var newTop = dsoctop+200;

	//Get the window height and width
	var winH = $(window).height();
	var winW = $(window).width();

	
	

	
	switch(imageId)
		{			
			case "pizzaLogo":
				$("#uploadDiv").fadeIn("200");
				//Set the popup window to center
				$("#uploadDiv").css('top',  winH/2-$("#uploadDiv").height()/2);
				$("#uploadDiv").css('left', winW/2-$("#uploadDiv").width()/2);
				//$("#uploadDiv").css({ top: newTop+'px'});
				$("#hiddenImageName").attr("value",imageId);
				$("#uploadHeader").html("Upload new logo");
				break;
			case "clientHeader":
				$("#uploadDiv").fadeIn("200");
				//Set the popup window to center
				$("#uploadDiv").css('top',  winH/2-$("#uploadDiv").height()/2);
				$("#uploadDiv").css('left', winW/2-$("#uploadDiv").width()/2);
				$("#hiddenImageName").attr("value",imageId);
				$("#uploadHeader").html("Upload new header image");
				break;
			case "clientFooter":
				$("#uploadDiv").fadeIn("200");
				//Set the popup window to center
				$("#uploadDiv").css('top',  winH/2-$("#uploadDiv").height()/2);
				$("#uploadDiv").css('left', winW/2-$("#uploadDiv").width()/2);
				$("#hiddenImageName").attr("value",imageId);
				$("#uploadHeader").html("Upload new footer image");
				break;
			case "clientIndex":
				$("#uploadDiv").fadeIn("200");
				//Set the popup window to center
				$("#uploadDiv").css('top',  winH/2-$("#uploadDiv").height()/2);
				$("#uploadDiv").css('left', winW/2-$("#uploadDiv").width()/2);
				$("#hiddenImageName").attr("value",imageId);
				$("#uploadHeader").html("Upload new index image");
				break;
			case "welcomeText":
				$("#welcomeTextOptions").fadeIn("200");
				$("#welcomeTextOptions").css('position', 'fixed' );
				$("#welcomeTextOptions").css('top',  winH/2-$("#welcomeTextOptions").height()/2);
				$("#welcomeTextOptions").css('left', winW/2-$("#welcomeTextOptions").width()/2);
				break;
			case "pizzaHeaderImg":
				$("#headerImageList").fadeIn("200");
				showImageList("header");
				break;
			case "footerBackImg":
				$("#footerImageList").fadeIn("200");
				$("#footerImageList").css({ height: '1800px'});
				showImageList("footer");
				break;
			case "middlePizzaImg":
				$("#indexImageList").fadeIn("200");
				$("#indexImageList").css({ height: '600px'});
				showImageList("index");
				break;
			case "tenPercentOffImg":
				$("#offerImageList").fadeIn("200");
				$("#offerImageList").css({ height: '600px'});
				showImageList("offer");
				break;
			case "clientOffer":
				$("#uploadDiv").fadeIn("200");
				//Set the popup window to center
				$("#uploadDiv").css('top',  winH/2-$("#uploadDiv").height()/2);
				$("#uploadDiv").css('left', winW/2-$("#uploadDiv").width()/2);
				$("#hiddenImageName").attr("value",imageId);
				$("#uploadHeader").html("Upload new offer image");
				break;
			default:
				break;
		}
		
	
}

function hideUploadForm()
{
	$("#mask,#mask2,#uploadDiv").fadeOut("200");
	$("#imagePreview").hide();

}

function showImageList(imageType)
{

	//alert("dasdasd");
	var xmlhttpShowImageList;
    var url = "getImageList.php";
    var params = "imageType="+imageType;
	
    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttpShowImageList=new XMLHttpRequest();
    }
    else
    {// code for IE6, IE5
        xmlhttpShowImageList=new ActiveXObject("Microsoft.XMLHTTP");
    }

    xmlhttpShowImageList.onreadystatechange=function()
      {
          if (xmlhttpShowImageList.readyState==4 && xmlhttpShowImageList.status==200)
          {
				//alert(xmlhttpShowImageList.responseText);
				switch(imageType)
				{
					case "header":
						$("#headerImageList").find(".overview").html(xmlhttpShowImageList.responseText);
						
						$('#scrollbar2').tinyscrollbar();
						break;
					case "footer":
						$("#footerImageList").find(".overview").html(xmlhttpShowImageList.responseText);
						$("#footerImageList").css({height:''});
						$('#scrollbar3').tinyscrollbar();
						break;
					case "index":
						$("#indexImageList").find(".overview").html(xmlhttpShowImageList.responseText);
						$('#scrollbar6').tinyscrollbar();
						break;
					case "offer":
						$("#offerImageList").find(".overview").html(xmlhttpShowImageList.responseText);
						//$("#offerImageList").css({height:''});
						$('#scrollbar4').tinyscrollbar();
						break;
					case "background":
						$("#backgroundImageList").find(".overview").html(xmlhttpShowImageList.responseText);
						//$("#offerImageList").css({height:''});
						$('#scrollbar3').tinyscrollbar();
						break;
					default:
						break;
				}

				addImageEditIcons();
				
          }
		  //alert(xmlhttpShowImageList.responseText);
      }

    xmlhttpShowImageList.open("GET",url+"?"+params,true);
    xmlhttpShowImageList.send();
}



function showPreview(imageType,imagePath)
{
	//alert(imageType+" - "+imagePath);
	//define universal dsoc left point
    var dsocleft=document.all? iebody.scrollLeft : pageXOffset
    
    //define universal dsoc top point
    var dsoctop=document.all? iebody.scrollTop : pageYOffset

	$("#mask2").fadeIn("200");
	
	//$("#mask2").css({width:'957px',height:'1306px'});

	var newTop = dsoctop+100;
	
	$("#selectedImage").addClass(imageType);

	if(imageType=="index")
	{
		$("#imagePreview").animate({width:'428px'},"2000");
		$("#imagePreview").animate({height:'256px'},"2500");
		$("#selectedImage").animate({width:'418px'},"2000");
		$("#selectedImage").animate({height:'246px'},"2500");
	}
	else if(imageType=="offer")
	{
		
		$("#imagePreview").animate({width:'428px'},"2000");
		$("#imagePreview").animate({height:'256px'},"2500");
		$("#selectedImage").animate({width:'418px'},"2000");
		$("#selectedImage").animate({height:'246px'},"2500");
	}
	else if(imageType=="background")
	{
		$("#imagePreview").animate({width:'915px'},"2000");
		$("#imagePreview").animate({height:'425px'},"2500");
		$("#selectedImage").animate({width:'905px'},"2000");
		$("#selectedImage").animate({height:'415px'},"2500");
	}
	else
	{
		$("#imagePreview").animate({width:'915px'},"2000");
		$("#imagePreview").animate({height:'225px'},"2500");
		$("#selectedImage").animate({width:'905px'},"2000");
		$("#selectedImage").animate({height:'215px'},"2500");
	}

	$("#selectImageLink").text("Set this image as "+imageType+" image");

	$("#imagePreview").find("#selectedImage").attr("src",imagePath);
	$("#imagePreview").css({top:newTop+'px',zIndex:'220000'});
	$("#mask2").css({zIndex:'215000'});
}


function saveImage(imageType,imagePath){
	var xmlhttpSaveImage;
    var url = "updatePage.php";
    var params = "method=saveImage&imageType="+imageType+"&imagePath="+encodeURI(imagePath);

    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttpSaveImage=new XMLHttpRequest();
    }
    else
    {// code for IE6, IE5
        xmlhttpSaveImage=new ActiveXObject("Microsoft.XMLHTTP");
    }

    xmlhttpSaveImage.onreadystatechange=function()
      {
          if (xmlhttpSaveImage.readyState==4 && xmlhttpSaveImage.status==200)
          {
				//alert(xmlhttpShowImageList.responseText);
				/*switch(imageType)
				{
					case "header":
						$("#headerImageList").html(xmlhttpSaveImage.responseText);
						break;
					case "footer":
						$("#footerImageList").html(xmlhttpSaveImage.responseText);
					$("#footerImageList").css({height:''});
						break;
					case "index":
						$("#indexImageList").html(xmlhttpSaveImage.responseText);
						break;
					default:
						break;
				}*/
				
          }
		  //alert(xmlhttpShowImageList.responseText);
      }

    xmlhttpSaveImage.open("GET",url+"?"+params,true);
    xmlhttpSaveImage.send();
}


function toggleDefaultText(elementId,defaultText)
{
	if($("#"+elementId).val()=="" || $("#"+elementId).val().length==0)
	{
		$("#"+elementId).val(defaultText);
		
	}
	else
	{
		if($("#"+elementId).val()==defaultText)
		{
			$("#"+elementId).val("");
			
		}
	}
}


function showToolTip(elementId,textToBeDisplayed)
{
	var toolTipTop = $("#"+elementId).offset().top;
	var toolTipLeft = $("#"+elementId).offset().left;
	//alert(toolTipTop+"-"+toolTipLeft);
	$("#helpToolTip").html(textToBeDisplayed);
	$("#helpToolTip").css({top:toolTipTop+'px',left:toolTipLeft+'px'})
	$("#helpToolTip").show();
	
}

function hideToolTip()
{
	$("#helpToolTip").hide();
}

function updatePageSetting(elementId,value)
{
	switch (elementId)
	{
		case "logoBack":
				
			if(value==true)
			{
				//$("#pizzeriaLogoBack").show();
				if($("#hiddenSelectedTemplate").val()=="1")
				{
					$("#pizzeriaLogoBack").css({backgroundImage:'url(../Images/transparency_optional_back_logo.png)'});
				}
				$("#hiddenLogoBack").attr("value","1");
			}
			else
			{
				$("#hiddenLogoBack").attr("value","0");	
				if($("#hiddenSelectedTemplate").val()=="1")
				{
					$("#pizzeriaLogoBack").css({backgroundImage:'none'});
				}
				//$("#pizzeriaLogoBack").hide();

			}
			break;
		case "footerNumberBack":
			if(value==true)
			{
				$("#footerContentNumberDetails").css({backgroundImage:'url(../Images/1pxTransparency75.png)'});
				$("#hiddenFooterPhoneBack").attr("value","1");
			}
			else
			{
				$("#footerContentNumberDetails").css({backgroundImage:'none'});
				$("#hiddenFooterPhoneBack").attr("value","0");
			}
			break;
		case "cornerEffect":
			if(value==true)
			{
				$("#turn_wrapper").show();
				document.getElementById("turn_wrapper").style.display="block";
				$("#hiddenCurlEffect").attr("value","1");
			}
			else
			{
				$("#turn_wrapper").hide();
				//document.getElementById("turn_wrapper").style.display="none";
				$("#hiddenCurlEffect").attr("value","0");
			}
			break;
		case "poweredBy":
			if(value==true)
			{
				$("#poweredByDiv").show();
				//document.getElementById("turn_wrapper").style.display="block";
				$("#hiddenPoweredBy").attr("value","1");
			}
			else
			{
				$("#poweredByDiv").hide();
				//document.getElementById("turn_wrapper").style.display="block";
				$("#hiddenPoweredBy").attr("value","0");
			}
			break;
		case "photosLink":
			if(value==true)
			{
				$("#photoTool").show();
				if($("#hiddenSelectedLanguage").val()=="french")
				{
					//$("#contactUsTool").css({left:'285px'});
					$("#contactUsTool").css({left:'310px'});
				}
				else
				{
					$("#contactUsTool").css({left:'330px'});
				}
				$("#headerSubToolImageOne").css({width:'404px'});
				$("#fourthSeparator").show();
				$("#hiddenPhotoLink").attr("value","1");
			}
			else
			{
				$("#photoTool").hide();
				$("#fourthSeparator").hide();
				if($("#hiddenSelectedLanguage").val()=="french")
				{
					$("#contactUsTool").css({left:'243px'});
				}
				else
				{
					$("#contactUsTool").css({left:'260px'});
				}
				//$("#contactUsTool").css({left:'260px'});
				$("#headerSubToolImageOne").css({width:'330px'});
				$("#hiddenPhotoLink").attr("value","0");
			}
			break;
		case "check2x1":
			if(value==true)
			{
				$("#sizeDiv").show();
				$("#hiddenCheck2x1").attr("value","1");
			}
			else
			{
				$("#sizeDiv").hide();
				$("#hiddenCheck2x1").attr("value","0");
			}
			break;
		case "customerSupport":
			if(value==true)
			{
				//$("#divisionLine,#techSupportDiv").show();
				$("#formDiv").show();
				$("#hiddenCustomerSupport").attr("value","1");
				$("#customerSupportEmailDiv").show();
				//$("#controlPanel").css({height:'340px'});
			}
			else
			{
				//$("#divisionLine,#techSupportDiv,#formDiv").hide();
				$("#formDiv").hide();
				$("#hiddenCustomerSupport").attr("value","0");
				$("#customerSupportEmailDiv").hide();
				//$("#controlPanel").css({height:'300px'});
			}
			break;
		case "facebookIcon":
			//alert("dasd");
			if(value==true)
			{
				$("#hiddenFacebookIcon").attr("value","1");
				$("#facebookURLDiv").show();
				$(".addthis_button_facebook").removeClass("hidden");
				$(".addthis_button_facebook").show();
				//alert("$('.hidden').size()=="+$(".hidden").size()+" && temp="+$("#hiddenSelectedTemplate").val());
				if($(".hidden").size()==0 && $("#hiddenSelectedTemplate").val()=="1")
				{
					//$("#headerImgNumber").append($("#addThisButtons"));
					//alert($("#headerImgNumber").html());
				}
			}
			else
			{
				$("#hiddenFacebookIcon").attr("value","0");
				$("#facebookURLDiv").hide();
				$(".addthis_button_facebook").addClass("hidden");
				$(".addthis_button_facebook").hide();
				//alert("$('.hidden').size()=="+$(".hidden").size()+" && temp="+$("#hiddenSelectedTemplate").val());
				if($(".hidden").size()>0 && $("#hiddenSelectedTemplate").val()=="1")
				{
					//$("#headerImgNumber").prepend($("#addThisButtons"));
					
					//alert($("#headerImgNumber").html());
				}				
			}
			break;
		case "twitterIcon":
			//alert("dasd");
			if(value==true)
			{
				$("#hiddenTwitterIcon").attr("value","1");
				$("#twitterURLDiv").show();
				$(".addthis_button_twitter").removeClass("hidden");
				$(".addthis_button_twitter").show();
				//alert("$('.hidden').size()=="+$(".hidden").size()+" && temp="+$("#hiddenSelectedTemplate").val());
				//if($(".hidden").size()==0 && $("#hiddenSelectedTemplate").val()=="1")
				//{

					//$("#headerImgNumber").append($("#addThisButtons"));
					//alert($("#headerImgNumber").html());
				//}
			}
			else
			{
				$("#hiddenTwitterIcon").attr("value","0");
				$("#twitterURLDiv").hide();
				$(".addthis_button_twitter").addClass("hidden");
				$(".addthis_button_twitter").hide();				
				//alert("$('.hidden').size()=="+$(".hidden").size()+" && temp="+$("#hiddenSelectedTemplate").val());
				//if($(".hidden").size()>0 && $("#hiddenSelectedTemplate").val()=="1")
				//{
				//	$("#headerImgNumber").prepend($("#addThisButtons"));
					
					//alert($("#headerImgNumber").html());
				//}

			}
			break;
		case "languageSelection":
			if(value==true)
			{
				$("#languageTool").show();
				$("#hiddenLanguageSelection").attr("value","1");
			}
			else
			{
				$("#languageTool").hide();
				$("#hiddenLanguageSelection").attr("value","0");
			}
			break;
		
	}
}

function resizeLogo(img_element)
{
	var originalWidth = img_element.width;
	var originalHeight = img_element.height;
	alert(originalWidth + " - " + originalHeight);

	/*var t = new Image();
    t.src = (img_element.getAttribute ? img_element.getAttribute("src") : false) || img_element.src;
	alert("New  : "+t.width);*/
}

function showNewlogo(uploadedImage)
{
	
	var xmlhttpShowNewlogo;
    var url = "updatePage.php";
    var params = "method=showLogo&uploadedImage="+uploadedImage;
	
	if(uploadedImage=="pizzaLogo")
	{
		$("#pizzaLogo").attr("src","../Images/loading1.gif");
	}
	else if(uploadedImage=="tenPercentOffImg")
	{
		$("#tenPercentOffImg").attr("src","../Images/loading1.gif");
	} 
	
	
    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttpShowNewlogo=new XMLHttpRequest();
    }
    else
    {// code for IE6, IE5
        xmlhttpShowNewlogo=new ActiveXObject("Microsoft.XMLHTTP");
    }

    xmlhttpShowNewlogo.onreadystatechange=function()
      {
          if (xmlhttpShowNewlogo.readyState==4 && xmlhttpShowNewlogo.status==200)
          {
			    //alert(xmlhttpShowNewlogo.responseText);
					if(uploadedImage=="pizzaLogo")
					{
						//$("#pizzaLogo").attr("src",xmlhttpShowNewlogo.responseText);
						$("#pizzeriaLogoBack").html(xmlhttpShowNewlogo.responseText);
					}
					else if(uploadedImage=="tenPercentOffImg")
					{
						$("#tenPercentOffImg").attr("src",xmlhttpShowNewlogo.responseText);
					}
					else
					{
						$("#photoThumb #scrollbar5").find(".overview").html(xmlhttpShowNewlogo.responseText);
						$('#scrollbar5').tinyscrollbar();
					}

									
          }
		  
      }

    xmlhttpShowNewlogo.open("GET",url+"?"+params,true);
    xmlhttpShowNewlogo.send();
}


function saveChanges()
{
	//alert(changesDone==false);
	if(changesDone==false)
	{
		return;
	}
	var xmlhttpSaveChanges;
    var url = "updatePage.php";

	var welcomeText = $("#hiddenWelcomeText").attr("value");
	var	headerImage = encodeURI($("#headerImagePath").attr("value"));
	var	footerImage = encodeURI($("#footerImagePath").attr("value"));
	var	indexImage = encodeURI($("#hiddenIndexImage").attr("value"));
	var	curlEffect = $("#hiddenCurlEffect").attr("value");
	var	logoBack = $("#hiddenLogoBack").attr("value");
	var	footerPhoneBack = $("#hiddenFooterPhoneBack").attr("value");
	var theme = $("#hiddenTheme").attr("value");
    var currentCSS = $("link[href^=themes]").attr("href");
    var photoLink = $("#hiddenPhotoLink").attr("value");
	var check2x1 = $("#hiddenCheck2x1").attr("value");
	var customerSupport = $("#hiddenCustomerSupport").attr("value");
	var customWelcomeText = $("#hiddenCustomWelcomeText").attr("value");
	var offerImage = $("#hiddenOfferImage").attr("value");
	var poweredBy = $("#hiddenPoweredBy").attr("value");
	var languageSelection = $("#hiddenLanguageSelection").attr("value");
	var backgroundImage = $("#hiddenBackgroundImage").attr("value");

	var facebookIcon = $("#hiddenFacebookIcon").attr("value");
	var twitterIcon = $("#hiddenTwitterIcon").attr("value");
	var facebookURL = $("#hiddenFacebookURL").attr("value");
	var twitterURL = $("#hiddenTwitterURL").attr("value");

	switch (theme)
	{
	case "beige":
		currentCSS = "themes/commonBeige.css";
		break;
	case "green":
		currentCSS = "themes/commonGreen.css";
		break;
	case "orange":
		currentCSS = "themes/commonOrange.css";
		break;
	case "red":
		currentCSS = "themes/commonRed.css";
		break;
	case "black":
		currentCSS = "themes/commonBlack.css";
		break;
	case "white":
		currentCSS = "themes/commonWhite.css";
		break;
	case "winesh":
		currentCSS = "themes/commonWinesh.css";
		break;
	}  	

    var params = "method=saveChanges&headerImage="+headerImage+"&footerImage="+footerImage+"&indexImage="+indexImage+"&curlEffect="+curlEffect+"&logoBack="+logoBack+"&footerPhoneBack="+footerPhoneBack+"&theme="+theme+"&currentCSS="+currentCSS+"&check2x1="+check2x1+"&photoLink="+photoLink+"&customerSupport="+customerSupport+"&welcomeText="+welcomeText+"&offerImage="+offerImage+"&poweredBy="+poweredBy+"&languageSelection="+languageSelection+"&facebookIcon="+facebookIcon+"&twitterIcon="+twitterIcon+"&facebookURL="+facebookURL+"&twitterURL="+twitterURL+"&backgroundImage="+backgroundImage;
	
	if(welcomeText=="option3")
	{
		params+="&customWelcomeText="+customWelcomeText+"&lang="+$("#hiddenSelectedLanguage").val();
	}
	
	//alert(params);
	//return;
	$("#saveChangesWaitImg").show();	

    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttpSaveChanges=new XMLHttpRequest();
    }
    else
    {// code for IE6, IE5
        xmlhttpSaveChanges=new ActiveXObject("Microsoft.XMLHTTP");
    }

    xmlhttpSaveChanges.onreadystatechange=function()
      {
          if (xmlhttpSaveChanges.readyState==4 && xmlhttpSaveChanges.status==200)
          {
			    alert("Changes Saved");
				$("#saveChangesWaitImg").hide();
				//alert(xmlhttpSaveChanges.responseText);
				changesDone = false;
				return true;
				//$("#pizzaLogo").attr("src",xmlhttpSaveChanges.responseText);					
          }
		  
      }

    xmlhttpSaveChanges.open("POST",url,true);
	xmlhttpSaveChanges.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlhttpSaveChanges.setRequestHeader("Connection", "close");
    xmlhttpSaveChanges.send(params);
	return false;
}


function applyTheme()
{
	
	//var welcomeText = $("#welcomeText").html();
	var	headerImage = $("#headerImagePath").attr("value");
	var	footerImage = $("#footerImagePath").attr("value");
	var	indexImage = $("#hiddenIndexImage").attr("value");
	var	curlEffect = $("#hiddenCurlEffect").attr("value");
	var	logoBack = $("#hiddenLogoBack").attr("value");
	var	footerPhoneBack = $("#hiddenFooterPhoneBack").attr("value");
	var	welcomeText = $("#hiddenWelcomeText").attr("value");
	var	theme = $("#hiddenTheme").attr("value");
	var	check2x1 = $("#hiddenCheck2x1").attr("value");
	var	photoLink = $("#hiddenPhotoLink").attr("value");
	var	customerSupport = $("#hiddenCustomerSupport").attr("value");
	var	customWelcomeText = $("#hiddenCustomWelcomeText").attr("value");
	var	offerImage = $("#hiddenOfferImage").attr("value");
	var	poweredBy = $("#hiddenPoweredBy").attr("value");
	var languageSelection = $("#hiddenLanguageSelection").attr("value");
	var backgroundImage = $("#hiddenBackgroundImage").attr("value");
	
	var facebookIcon = $("#hiddenFacebookIcon").attr("value");
	var twitterIcon = $("#hiddenTwitterIcon").attr("value");
	var facebookURL = $("#hiddenFacebookURL").attr("value");
	var twitterURL = $("#hiddenTwitterURL").attr("value");

	$("#pizzaHeaderImg").css({backgroundImage:'url('+headerImage+')'});
	//$("#middlePizzaImg").css({backgroundImage:'url('+indexImage+')'});
	$("#middlePizzaImg img").attr("src",indexImage);
	$("#footerBackImg").css({backgroundImage:'url('+footerImage+')'});
	$("#tenPercentOffImg").attr("src",offerImage);
	$("#bgImage img").attr("src",backgroundImage).css({'display': 'block'});
	//alert($("#hiddenCurlEffect").attr("value")+"=="+1);

	//alert($("#hiddenCurlEffect").attr("value")==1);
	if(curlEffect==1)
	{
		$("#turn_wrapper").show();
		$('input[name=cornerEffect]').attr('checked', true);
	}
	else
	{
		//alert("dasd");
		$("#turn_wrapper").fadeOut(200);
		$('input[name=cornerEffect]').attr('checked', false);
	}

	if(poweredBy==1)
	{
		$("#poweredByDiv").show();
		$('input[name=poweredBy]').attr('checked', true);
	}
	else
	{
		//alert("dasd");
		$("#poweredByDiv").hide();
		$('input[name=poweredBy]').attr('checked', false);
	}

	if(languageSelection==1)
	{
		$("#languageTool").show();
		$('input[name=languageSelection]').attr('checked', true);
		if ($("#hiddenSelectedTemplate").val()=="1") {
			$("#menu_pdf").css({'left': '150px', 'top': '15px'});
		} else {
			$("#menu_pdf").css({'left': '-835px', 'top': '64px'});
		}
		
	}
	else
	{
		//alert("dasd");
		$("#languageTool").hide();
		$('input[name=languageSelection]').attr('checked', false);
		if ($("#hiddenSelectedTemplate").val()=="1") {
			$("#menu_pdf").css({'left': '-6px', 'top': '20px'});
		} else {
			$("#menu_pdf").css({'left': '-835px', 'top': '64px'});
		}
	}

	if(logoBack==1 && $("#hiddenSelectedTemplate").val()=="1")
	{
		
		//$("#pizzeriaLogoBack").show();
		$("#pizzeriaLogoBack").css({backgroundImage:'url(../Images/transparency_optional_back_logo.png)'});
		$('input[name=logoBack]').attr('checked', true);
	}
	else
	{
		//$("#pizzeriaLogoBack").hide();
		if($("#hiddenSelectedTemplate").val()=="1")
		{
			$("#pizzeriaLogoBack").css({backgroundImage:'none'});
			$('input[name=logoBack]').attr('checked', false);
		}
	}

	if(footerPhoneBack==1)
	{
		$("#footerContentNumberDetails").css({backgroundImage:'url(../Images/1pxTransparency75.png)'});
		$('input[name=footerNumberBack]').attr('checked', true);
	}
	else
	{
		$("#footerContentNumberDetails").css({backgroundImage:'none'});
		$('input[name=footerNumberBack]').attr('checked', false);
	}



	if(check2x1==1)
	{
		$("#sizeDiv").show();
		$('input[name=check2x1]').attr('checked', true);
	}
	else
	{
		$("#sizeDiv").hide();
		$('input[name=check2x1]').attr('checked', false);
		if (languageSelection==1) {
			if ($("#hiddenSelectedTemplate").val()=="1") {
				$("#menu_pdf").css({'top': '15px'});
			} else {
				$("#menu_pdf").css({'left': '-835px', 'top': '64px'});
			}
		} else {
			if ($("#hiddenSelectedTemplate").val()=="1") {
				$("#menu_pdf").css({'top': '-8px'});
			} else {
				$("#menu_pdf").css({'left': '-835px', 'top': '64px'});
			}
		}
	}

	if(photoLink==1)
	{
		$("#photoTool").show();
		if($("#hiddenSelectedLanguage").val()=="french")
		{
			$("#contactUsTool").css({left:'310px'});
		}
		else
		{
			$("#contactUsTool").css({left:'330px'});
		}
		//$("#contactUsTool").css({left:'330px'});
		$("#headerSubToolImageOne").css({width:'404px'});
		$("#fourthSeparator").show();
		//$("#hidePhotoBack").hide();
		$('input[name=photosLink]').attr('checked', true);
	}
	else
	{
		$("#photoTool").hide();
		$("#headerSubToolImageOne").css({width:'330px'});
		$("#fourthSeparator").hide();
		//$("#hidePhotoBack").show();
				if($("#hiddenSelectedLanguage").val()=="french")
				{
					$("#contactUsTool").css({left:'245px'});
				}
				else
				{
					$("#contactUsTool").css({left:'260px'});
				}
		//$("#contactUsTool").css({left:'260px'});
		$('input[name=photosLink]').attr('checked', false);
	}

	if(customerSupport==1)
	{
		//$("#divisionLine,#techSupportDiv").show();
		$("#formDiv").show();
		if(document.getElementById("formDiv")!=null)
		{
			document.getElementById("formDiv").style.display = "block";
		}
		$('input[name=customerSupport]').attr('checked', true);
		//$("#controlPanel").css({height:'340px'});
		$("#customerSupportEmailDiv").show();
	}
	else
	{
		//$("#divisionLine,#techSupportDiv").hide();
		$("#formDiv").hide();
		$('input[name=customerSupport]').attr('checked', false);
		//$("#controlPanel").css({height:'300px'});
		$("#customerSupportEmailDiv").hide();
	}

	
	//alert("WelcomeText : \n"+$("#"+welcomeText).html());
	
	if(welcomeText!="option3")
	{
		$("#welcomeText").html($("#"+welcomeText).html());
	}
	else
	{
		$("#welcomeText").html(customWelcomeText);
		
		//translateWelcomeText($("#welcomeText").text());
		
	}

	if(facebookIcon==1)
	{
		$(".addthis_button_facebook,#facebookURLDiv").show();
		$(".addthis_button_facebook").removeClass("hidden");
		if($(".hidden").size()==0 && $("#hiddenSelectedTemplate").val()=="1")
		{
			//$("#headerImgNumber").append($("#addThisButtons"));
		}
		$('input[name=facebookIcon]').attr('checked', true);
	}
	else
	{
		$(".addthis_button_facebook,#facebookURLDiv").hide();
		$(".addthis_button_facebook").addClass("hidden");
		if($(".hidden").size()>0 && $("#hiddenSelectedTemplate").val()=="1")
		{
			//$("#headerImgNumber").prepend($("#addThisButtons"));
		}	
		$('input[name=facebookIcon]').attr('checked', false);
	}

	if(twitterIcon==1)
	{
		$(".addthis_button_twitter,#twitterURLDiv").show();
		$(".addthis_button_twitter").removeClass("hidden");
		if($(".hidden").size()==0 && $("#hiddenSelectedTemplate").val()=="1")
		{
			//$("#headerImgNumber").append($("#addThisButtons"));
		}
		$('input[name=twitterIcon]').attr('checked', true);
	}
	else
	{
		$(".addthis_button_twitter,#twitterURLDiv").hide();
		$(".addthis_button_twitter").addClass("hidden");
		if($(".hidden").size()>0 && $("#hiddenSelectedTemplate").val()=="1")
		{
			//$("#headerImgNumber").prepend($("#addThisButtons"));
		}
		$('input[name=twitterIcon]').attr('checked', false);
	}
	if ($("#hiddenFormName").val() == 'Menu') {
		$("#menu_pdf").show()
	} else {
		$("#menu_pdf").hide()
	}
	
}

function translateWelcomeText(text)
{
	
	var xmlhttpTranslateWelcomeText;
	var url = "lang.php";
	var params = "text="+text+"&lang="+$("#hiddenSelectedLanguage").val();
	
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttpTranslateWelcomeText=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
		xmlhttpTranslateWelcomeText=new ActiveXObject("Microsoft.XMLHTTP");
	}

	xmlhttpTranslateWelcomeText.onreadystatechange=function()
	  {
		  if (xmlhttpTranslateWelcomeText.readyState==4 && xmlhttpTranslateWelcomeText.status==200)
		  {
				$("#welcomeText pre").html(xmlhttpTranslateWelcomeText.responseText);
				$("#welcomeText pre").html(jQuery.trim($("#welcomeText").text()));
		  }
	  }

	xmlhttpTranslateWelcomeText.open("GET",url+"?"+params,true);
	xmlhttpTranslateWelcomeText.send();
}

function Trim(str)
{
    while (str.substring(0,1) == ' ') // check for white spaces from beginning
    {
        str = str.substring(1, str.length);
    }
    while (str.substring(str.length-1, str.length) == ' ') // check white space from end
    {
        str = str.substring(0,str.length-1);
    }
    return str;
}

function cancelChanges()
{
	var result=window.confirm("Do you want to cancel these changes?");

	if (result)
	{
		var	headerImage = $("#headerPrevImagePath").attr("value");
		var	footerImage = $("#footerPrevImagePath").attr("value");
		var	indexImage = $("#hiddenPrevIndexImage").attr("value");
		var	curlEffect = $("#hiddenPrevCurlEffect").attr("value");
		var	logoBack = $("#hiddenPrevLogoBack").attr("value");
		var	footerPhoneBack = $("#hiddenPrevFooterPhoneBack").attr("value");
		var	welcomeText = $("#hiddenPrevWelcomeText").attr("value");
		var customerSupport = $("#hiddenPrevCustomerSupport").attr("value");
		var	check2x1 = $("#hiddenPrevCheck2x1").attr("value");
		var	photoLink = $("#hiddenPrevPhotoLink").attr("value");
		var	customWelcomeText = $("#hiddenPrevCustomWelcomeText").attr("value");
		var	offerImage = $("#hiddenPrevOfferImage").attr("value");
		var	poweredBy = $("#hiddenPrevPoweredBy").attr("value");
		var languageSelection = $("#hiddenPrevLanguageSelection").attr("value");
		var backgroundImage = $("#hiddenPrevBackgroundImage").attr("value");
		var	theme = $("#hiddenPrevTheme").attr("value");
		var facebookIcon = $("#hiddenPrevFacebookIcon").attr("value");
		var twitterIcon = $("#hiddenPrevTwitterIcon").attr("value");
		var facebookURL = $("#hiddenPrevFacebookURL").attr("value");
		var twitterURL = $("#hiddenPrevTwitterURL").attr("value");

		$("#pizzaHeaderImg").css({backgroundImage:'url('+headerImage+')'});
		$("#middlePizzaImg img").attr("src",indexImage);
		//$("#middlePizzaImg").css({backgroundImage:'url('+indexImage+')'});
		$("#footerBackImg").css({backgroundImage:'url('+footerImage+')'});
		$("#tenPercentOffImg").attr("src",offerImage);
		$("#bgImage img").attr("src",backgroundImage);

		changeTheme(theme);
		//alert($("#hiddenCurlEffect").attr("value")+"=="+1);

		//alert($("#hiddenCurlEffect").attr("value")==1);
		if(curlEffect==1)
		{
			$("#turn_wrapper").show();
			$('input[name=cornerEffect]').attr('checked', true);
		}
		else
		{
			//alert("dasd");
			$("#turn_wrapper").fadeIn(200);
			$('input[name=cornerEffect]').attr('checked', false);
		}

		if(poweredBy==1)
		{
			$("#poweredByDiv").show();
			$('input[name=poweredBy]').attr('checked', true);
		}
		else
		{
			//alert("dasd");
			$("#poweredByDiv").hide();
			$('input[name=poweredBy]').attr('checked', false);
		}

		if(languageSelection==1)
		{
			$("#languageTool").show();
			$('input[name=languageSelection]').attr('checked', true);
		}
		else
		{
			$("#languageTool").hide();
			$('input[name=languageSelection]').attr('checked', false);
		}

		if(logoBack==1 && $("#hiddenSelectedTemplate").val()=="1")
		{
			//$("#pizzeriaLogoBack").show();
			$("#pizzeriaLogoBack").css({backgroundImage:'url(../Images/transparency_optional_back_logo.png)'});
			$('input[name=logoBack]').attr('checked', true);
		}
		else
		{
			//$("#pizzeriaLogoBack").hide();
			if($("#hiddenSelectedTemplate").val()=="1")
			{
				$("#pizzeriaLogoBack").css({backgroundImage:'none'});
				$('input[name=logoBack]').attr('checked', true);
			}
		}

		if(footerPhoneBack==1)
		{
			$("#footerContentNumberDetails").css({backgroundImage:'url(../Images/1pxTransparency75.png)'});
			$('input[name=footerNumberBack]').attr('checked', true);
		}
		else
		{
			$("#footerContentNumberDetails").css({backgroundImage:'none'});
			$('input[name=footerNumberBack]').attr('checked', true);
		}

		if(check2x1==1)
		{
			$("#sizeDiv").show();
			$('input[name=check2x1]').attr('checked', true);
		}
		else
		{
			$("#sizeDiv").hide();
			$('input[name=check2x1]').attr('checked', false);
		}
		
		//alert((photoLink==0) + " - " + (photoLink==1));	
		if(photoLink==1)
		{
			$('input[name=photosLink]').attr('checked', true);
			$("#photoTool").show();
			if($("#hiddenSelectedLanguage").val()=="french")
			{
				$("#contactUsTool").css({left:'310px'});
			}
			else
			{
				$("#contactUsTool").css({left:'330px'});
			}
			//$("#contactUsTool").css({left:'330px'});
			$("#headerSubToolImageOne").css({width:'404px'});
			$("#fourthSeparator").show();
			//$("#hidePhotoBack").hide();
			
		}
		else
		{
			$('input[name=photosLink]').attr('checked', false);
			$("#photoTool").hide();
			$("#headerSubToolImageOne").css({width:'330px'});
			$("#fourthSeparator").hide();
			//$("#hidePhotoBack").show();
			if($("#hiddenSelectedLanguage").val()=="french")
			{
				$("#contactUsTool").css({left:'285px'});
			}
			else
			{
				$("#contactUsTool").css({left:'260px'});
			}
			//$("#contactUsTool").css({left:'260px'});
			
		}

		if(customerSupport==1)
		{
			//$("#divisionLine,#techSupportDiv").show();
			$("#formDiv").show();
			$('input[name=customerSupport]').attr('checked', true);
			//$("#controlPanel").css({height:'340px'});
			$("#customerSupportEmailDiv").show();
		}
		else
		{
			//$("#divisionLine,#techSupportDiv").hide();
			$("#formDiv").hide();
			$('input[name=customerSupport]').attr('checked', false);
			//$("#controlPanel").css({height:'300px'});
			$("#customerSupportEmailDiv").hide();
		}
		//alert("WelcomeText : \n"+$("#"+welcomeText).html());
		if(welcomeText!="option3")
		{
			$("#welcomeText").html($("#"+welcomeText).html());
		}
		else
		{
			$("#welcomeText").html(customWelcomeText);
			//translateWelcomeText($("#welcomeText").text());
		}

		if(facebookIcon==1)
		{
			$(".addthis_button_facebook,#facebookURLDiv").show();
			$(".addthis_button_facebook").removeClass("hidden");
			if($(".hidden").size()==0 && $("#hiddenSelectedTemplate").val()=="1")
			{
				$("#headerImgNumber").append($("#addThisButtons"));
			}
			$('input[name=facebookIcon]').attr('checked', true);
		}
		else
		{
			$(".addthis_button_facebook,#facebookURLDiv").hide();
			$(".addthis_button_facebook").addClass("hidden");
			if($(".hidden").size()>0 && $("#hiddenSelectedTemplate").val()=="1")
			{
				$("#headerImgNumber").prepend($("#addThisButtons"));
			}	
			$('input[name=facebookIcon]').attr('checked', false);
		}

		if(twitterIcon==1)
		{
			$(".addthis_button_twitter,#twitterURLDiv").show();
			$(".addthis_button_twitter").removeClass("hidden");
			if($(".hidden").size()==0 && $("#hiddenSelectedTemplate").val()=="1")
			{
				$("#headerImgNumber").append($("#addThisButtons"));
			}
			$('input[name=twitterIcon]').attr('checked', true);
		}
		else
		{
			$(".addthis_button_twitter,#twitterURLDiv").hide();
			$(".addthis_button_twitter").addClass("hidden");
			if($(".hidden").size()>0 && $("#hiddenSelectedTemplate").val()=="1")
			{
				$("#headerImgNumber").prepend($("#addThisButtons"));
			}
			$('input[name=twitterIcon]').attr('checked', false);
		}

		//$("#welcomeText").html($("#"+welcomeText).html());

		changesDone = false;
	}
	else
	{
		//saveChanges();
	}

}


function checkSaveChanges()
{
	//alert(changesDone);
	if(changesDone != false)
	{
		var result=window.confirm("Do you want to save these changes?");
		if(result)
		{
			var r = saveChanges();
			
		}
	}
}


function updateMiddleContainerStyle(color)
{
	//alert(color);

	

	var imagePath = "Element_"+color;
	var lang = "en";
	
	if($("#hiddenSelectedLanguage").val()=="french")
	{
		lang = "fr";
	}
	

	var colorCode = "";
	var  borderColor = "";
	var modalBackColor = "";
	
	if($("#hiddenSelectedTemplate").val()=="1")
	{
		switch (color)
		{
			case "Orange":
				//imagePath = "Element_Orange";
				colorCode = "#F7881F";
				borderColor = "#ED4D06";
				break;
			case "Beige":
				//imagePath = "Element_Beige";
				colorCode = "#856441";
				borderColor = "#6E4F33";
				break;
			case "Green":
				//imagePath = "Element_Green";
				colorCode = "#68B310";
				borderColor = "#005900";
				break;
			case "Red":
				//imagePath = "Element_Red";
				colorCode = "#E43D43";
				borderColor = "#B70000";
				break;			
		}

		//alert(imagePath+"  ---   "+colorCode);
		
		$("#welcome,#custSupportEmailLabel,#facebookURLLabel,#twitterURLLabel,#websiteTechnicalSupportLabel,#selectBranchLabel,#welcomeText,#clickUpload,#receivePasswd,#uploadHeader,#formDiv table,#VerificationProcess div,#captchaRefresh,#textOptions,#controlPanel span,#menu,#restoInfoLabel,#restoDetails,.title,.content,#photoLabel,#contactLabel,#myProfileLabel,#loginInformation,#registerStepOneContainer div,#registerStepTwoContainer div,#cityLabel,#fiveSeconds,#phoneRing,#numberToCall span,#registerLabel,#showMembership,#voucherLabel2,#voucherLabel,#labelYourOrder span,#registrationBox span,#finalMessages span,#languageSizeTool div,#headerImgNumber,#deliveryZipCode span,#footerContentNumberDetails div,#accountCreate span,.modal-window a").css({color:colorCode});

		$("#enter,#centeredEmailTextBox,#centeredPasswordTextBox,#paymentDoneMessageDiv,#poweredByDiv,#poweredByDiv a").css({color:colorCode});
		$("#verificationCode #enter").removeClass("orange");
		$("#verificationCode #enter").removeClass("comment");
		$("#showMembership").css({fontWeight:'bold'});
		$("#restoMap,#map,.photoClass,#photoPreview,.photoClassContainer,#membershipAgreementDiv,#dialogForgotPasswd,#dialogLogin,#welcomeTextOptions,#uploadPhotoDiv,#paymentDoneDiv").css({borderColor:borderColor});
		$("#voucherLabel2").css({borderBottomColor:colorCode});
		$("#callMeImage").css({top:'110px',left:'45px'});
		if ( $.browser.mozilla)
		{
			$("#callMeImage").css({top:'114px',left:'45px'});
		}
		$(".line,.mapInfoBack").css({backgroundColor:colorCode});
		$("#selectImage,#closePreview").css({backgroundColor:'#ffffff'});
		$(".mapInfoBack").css({color:'black'});
		$("#loginBtn").css({top:'68px',left:'10px'});
		$("#sendBtn").css({top:'215px',left:'158px'});
		$("#captchaDisplay").css({color:'#5C5858'});
		$("#closeFormDiv").css({width:'30px',height:'30px',background:'url(Templates/template1/Images/'+imagePath+'/Cross.png) no-repeat'});

		///change button images
		//alert("Images/"+imagePath+"/");
		$("#centeredContinueButton,#continue").attr("src","Templates/template1/Images/"+imagePath+"/"+lang+"/Continue_Btn.jpg");
		$("#callMeImage").attr("src","Templates/template1/Images/"+imagePath+"/CallMe_Btn.jpg");
		$("#doneImage").attr("src","Templates/template1/Images/"+imagePath+"/Done_Btn.jpg");
		$("#loginBtn").attr("src","Templates/template1/Images/"+imagePath+"/Login_Btn.jpg");
		$("#sendBtn,#sendPasswdBtn,#btncustomerSupportSend").attr("src","Templates/template1/Images/"+imagePath+"/Send_Btn.jpg");
		$("#donePayment").attr("src","Templates/template1/Images/"+imagePath+"/Done_Btn.jpg");
		$("#updateMyProfile,#updateCustSupportEmail,#updateButton,#updateFacebookURL,#updateTwitterURL").attr("src","Templates/template1/Images/"+imagePath+"/Update_Btn.jpg");
		$("#closePreview img").attr("src","Templates/template1/Images/"+imagePath+"/Cross.png");
		//$("#closeFormDiv").attr("src","Images/"+imagePath+"/Cross.png");
		$("#edit").attr("src","Templates/template1/Images/"+imagePath+"/Edit_Btn.jpg");
		$("#closeFormDiv").css({width:'30px',height:'30px',background:'url(Templates/template1/Images/'+imagePath+'/Cross.png) no-repeat'});
		$("#saveChangesWaitImg").css({top:'6px',left:'-68px'});
		//$("#centeredContinueButton").css({width: '83px', height: '38px', top: '82px', left: '2px'});
	}
	else if($("#hiddenSelectedTemplate").val()=="2")
	{
		switch (color)
		{
			case "Orange":
				//imagePath = "Element_Orange";
				colorCode = "#F7881F";
				borderColor = "#F27602";
				modalBackColor = "#F77103";
				break;
			case "Beige":
				//imagePath = "Element_Beige";
				colorCode = "#856441";
				borderColor = "#6E4F33";
				modalBackColor = "";
				break;
			case "Green":
				//imagePath = "Element_Green";
				colorCode = "#68B310";
				borderColor = "#597254";
				modalBackColor = "#597255";
				break;
			case "Red":
				//imagePath = "Element_Red";
				colorCode = "#E43D43";
				borderColor = "#B70000";
				modalBackColor = "#E11B01";
				break;
			case "Black":
				//imagePath = "Element_Red";
				colorCode = "#686868";
				borderColor = "#000000";
				modalBackColor = "#000000";
				break;
			case "Winesh":
				//imagePath = "Element_Red";
				colorCode = "#AF7E7C";
				borderColor = "#590300";
				modalBackColor = "#590300";
				break;
			case "White":
				//imagePath = "Element_Red";
				colorCode = "#686868";
				borderColor = "#ffffff";
				modalBackColor = "#FFFFFF";
				break;
		}

		//alert(imagePath+"  ---   "+colorCode);
		if(color!="White")
		{
			$("#custSupportEmailLabel,#websiteTechnicalSupportLabel,#selectBranchLabel,#clickUpload,#receivePasswd,#uploadHeader,#formDiv table,#VerificationProcess div,#captchaRefresh,#textOptions,#controlPanel span,#menu,#restoInfoLabel,#restoDetails,.title,.content,#photoLabel,#contactLabel,#myProfileLabel,#loginInformation,#registerStepOneContainer div,#registerStepTwoContainer div,#cityLabel,#fiveSeconds,#phoneRing,#numberToCall span,#registerLabel,#showMembership,#voucherLabel2,#voucherLabel,#labelYourOrder span,#registrationBox span,#finalMessages span,#accountCreate span,.modal-window a").css({color:'#ffffff'});
			$("#restoMap,#map,.photoClass,.photoClassContainer,#membershipAgreementDiv,#dialogForgotPasswd,#dialogLogin,#uploadDiv,#welcomeTextOptions,#uploadPhotoDiv,#paymentDoneDiv").css({borderColor:'#ffffff'});
			$("#controlPanel").css({backgroundColor:borderColor,borderColor:'#ffffff',color:'#ffffff'});
			$("#payDeliveryInfo  div,#poweredByDiv,#techSupportDiv,#technicalSupportAnc,.heading").css({color:'#ffffff'});
			$("#receivePasswdText,#forgotPasswdText").css({color:'#ffffff'});
			$("#voucherLabel2").css({borderBottomColor:'#ffffff'});
			$(".line").css({backgroundColor:'#ffffff',height:'1px',border:'none',marginBottom:'20px'});
			$(".lineBreak").css({backgroundColor:'#ffffff',height:'1px',border:'none'});
			$("#divisionLine").css({backgroundColor:'#ffffff'});
			$("#cityDropDownContainer").css({color:'#FFFFFF'});
			
		}
		else
		{
			$("#custSupportEmailLabel,#websiteTechnicalSupportLabel,#selectBranchLabel,#clickUpload,#receivePasswd,#uploadHeader,#formDiv table,#VerificationProcess div,#captchaRefresh,#textOptions,#controlPanel span,#menu,#restoInfoLabel,#restoDetails,.title,.content,#photoLabel,#contactLabel,#myProfileLabel,#loginInformation,#registerStepOneContainer div,#registerStepTwoContainer div,#cityLabel,#fiveSeconds,#phoneRing,#numberToCall span,#registerLabel,#showMembership,#voucherLabel2,#voucherLabel,#labelYourOrder span,#registrationBox span,#finalMessages span,#accountCreate span,.modal-window a,.modal-window input").css({color:'#686868'});
			$("#restoMap,#map,.photoClass,.photoClassContainer,#membershipAgreementDiv,#dialogForgotPasswd,#dialogLogin,#uploadDiv,#welcomeTextOptions,#uploadPhotoDiv,#paymentDoneDiv").css({borderColor:'#686868'});
			$("#controlPanel").css({backgroundColor:borderColor,borderColor:'#686868',color:'#686868'});
			$("#payDeliveryInfo div,.heading,#poweredByDiv,#techSupportDiv,#technicalSupportAnc,#dialogForgotPasswd").css({color:'#686868'});
			$("#receivePasswdText,#forgotPasswdText").css({color:'#686868'});
			$("#voucherLabel2").css({borderBottomColor:'#686868'});
			$(".line").css({backgroundColor:'#686868',height:'1px',border:'none',marginBottom:'20px'});
			$(".lineBreak").css({backgroundColor:'#686868',height:'1px',border:'none'});
			$("#divisionLine").css({backgroundColor:'#686868'});
		}
		
		

		$("#headerPhoneNumber").css({margin:'8px',marginRight:'10px'});

		$("#enter,#centeredEmailTextBox,#centeredPasswordTextBox,#paymentDoneMessageDiv,#emailTextBox,#passwdTextBox,#enterEmailTextBox").css({color:colorCode});
		$("#verificationCode #enter").removeClass("orange");
		$("#verificationCode #enter").removeClass("comment");
		$("#showMembership").css({fontWeight:'bold'});
		$(".modal-window").css({backgroundColor:modalBackColor});	
		
		
		$("#callMeImage").css({top:'117px',left:'45px'});
		$("#doneButton").css({top:'128px'});
		$(".mapInfoBack,#selectImage,#closePreview,#imagePreview,#imageContainer,#imageContainer .nav").css({backgroundColor:borderColor});
		$("#closePreview,#selectImage").css({border:'solid 2px #ffffff',borderTop:'none'});
		
		$(".mapInfoBack").css({color:'black'});
		$("#loginBtn").css({top:'72px',left:'10px'});
		$("#sendBtn").css({top:'220px',left:'165px'});
		$("#captchaDisplay").css({color:'#5C5858'});
		$("#closeFormDiv").css({width:'30px',height:'30px',background:'url(Templates/template2/Images/'+imagePath+'/Cross.png) no-repeat'});
		
		

		///change button images
		//alert("Images/"+imagePath+"/");
		$("#centeredContinueButton,#continue").attr("src","Templates/template2/Images/"+imagePath+"/"+lang+"/Continue_Btn.jpg");
		$("#callMeImage").attr("src","Templates/template2/Images/"+imagePath+"/"+lang+"/CallMe_Btn.jpg");
		$("#doneImage").attr("src","Templates/template2/Images/"+imagePath+"/"+lang+"/Done_Btn.jpg");
		$("#loginBtn").attr("src","Templates/template2/Images/"+imagePath+"/"+lang+"/Login_Btn.jpg");
		$("#sendBtn,#sendPasswdBtn,#btncustomerSupportSend").attr("src","Templates/template2/Images/"+imagePath+"/"+lang+"/Send_Btn.jpg");
		$("#donePayment").attr("src","Templates/template2/Images/"+imagePath+"/"+lang+"/Done_Btn.jpg");
		$("#updateMyProfile,#updateCustSupportEmail,#updateButton,#updateFacebookURL,#updateTwitterURL").attr("src","Templates/template2/Images/"+imagePath+"/"+lang+"/Update_Btn.jpg");
		$("#closePreview img").attr("src","Templates/template2/Images/"+imagePath+"/Cross.png");
		//$("#closeFormDiv").attr("src","Images/"+imagePath+"/Cross.png");
		$("#edit").attr("src","Templates/template2/Images/"+imagePath+"/"+lang+"/Edit_Btn.jpg");
		$("#closeFormDiv").css({width:'30px',height:'30px',background:'url(Templates/template2/Images/'+imagePath+'/Cross.png) no-repeat'});

		$("#middleContentContainer").css({background:'url(Templates/template2/Images/'+imagePath+'/back1px.png)'});
		$("#footerContainer").css({height:'75px',backgroundColor:borderColor,width:'955px',backgroundImage:'none'});
		
		if($("#hiddenFormName").val()=="Photos" || $("#hiddenFormName").val()=="ContactUs")
		{
			$("#headerImgNumber").css({bottom:'-59px'});
			$("#deliveryZipCode").css({bottom:'5px'});
			$("#size").css({bottom:'30px'});
			$("#languageTool").css({top:'50px'});
			$("#wrapper").css({height:'auto'});
		}

		if($("#hiddenFormName").val()=="Voucher")
		{
                    if ($("#verificationCodeInstructions").length > 0) {
                        $("#headerImgNumber").css({bottom:'-67px !important'});
			$("#deliveryZipCode").css({bottom:'5px'});
			$("#size").css({bottom:'30px'});
			$("#languageTool").css({top:'50px'});
			$("#wrapper").css({height:'auto'});
                    } else {
			$("#headerImgNumber").css({bottom:'-67px'});
			$("#deliveryZipCode").css({bottom:'-51px'});
			$("#languageTool").css({top:'105px'});
			//$("#wrapper").css({height:'auto'});
			$("#footerContainer").css({backgroundColor:borderColor});
                        }
                }

		if($("#hiddenFormName").val()=="Register")
		{
			$("#headerImgNumber").css({bottom:'-59px'});
			$("#deliveryZipCode").css({bottom:'5px'});
			$("#size").css({bottom:'30px'});
			$("#languageTool").css({top:'50px'});
			$("#wrapper").css({height:'auto'});
		}

		if($("#hiddenFormName").val()=="MyProfile")
		{
			$("#headerImgNumber").css({bottom:'-59px'});
			$("#deliveryZipCode").css({bottom:'5px'});
			$("#size").css({bottom:'30px'});
			$("#languageTool").css({top:'50px'});
			$("#wrapper").css({height:'auto'});
		}
	}

}


$(window).scroll(function(){
				//$("#uploadDiv")
				//	.stop()
				//	.animate({"marginTop": ($(window).scrollTop()) + "px"}, "400" );

				//$("#controlPanel")
				//	.stop()
				//	.animate({"marginTop": ($(window).scrollTop()) + "px"}, "10" );
});



function getBranchMapDetails(branch_id)

{
	//alert(branch_id);

	if(streetViewEnabled==true)
	{
		alert("please close the street view before selecting the branch");
		return;
	}
	var xmlhttpMapDetails;
    var url = "getMapDetails.php";
    var params = "branch_id="+branch_id;
	
    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttpMapDetails=new XMLHttpRequest();
    }
    else
    {// code for IE6, IE5
        xmlhttpMapDetails=new ActiveXObject("Microsoft.XMLHTTP");
    }

    xmlhttpMapDetails.onreadystatechange=function()
      {
          if (xmlhttpMapDetails.readyState==4 && xmlhttpMapDetails.status==200)
          {
			    //alert(xmlhttpMapDetails.responseText);
				var latitudeLongitude=xmlhttpMapDetails.responseText;
				var latLongMapDetails = latitudeLongitude.split("@");
				document.getElementById("hiddenLatitude").value = latLongMapDetails[0];
				document.getElementById("hiddenLongitude").value = latLongMapDetails[1];
				document.getElementById("restoDetailsOnMap").innerHTML = latLongMapDetails[2];
				var color = $("#hiddenTheme").attr("value");
				var colorCode = "#F7881F";
				//alert(color);
				switch(color)
				{
					case "beige":
						colorCode = "#856441";
						break;
					case "orange":
						colorCode = "#F7881F";
						break;
					case "red":
						colorCode = "#E43D43";
						break;
					case "green":
						colorCode = "#68B310";
						break;
					
				}
				
				$(".mapInfoBack").css({backgroundColor:colorCode});

				load('1');

				//alert(latLongMapDetails);
				//$("#pizzaLogo").attr("src",xmlhttpMapDetails.responseText);				
          }
		  
      }

    xmlhttpMapDetails.open("GET",url+"?"+params,true);
    xmlhttpMapDetails.send();
}

function updateCustomerSupportEmail(custSupportEmail)
{
	var xmlhttpCustomerSupportEmail;
    var url = "customerSupportDetails.php";
    var params = "custSupportEmail="+custSupportEmail;
	
    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttpCustomerSupportEmail=new XMLHttpRequest();
    }
    else
    {// code for IE6, IE5
        xmlhttpCustomerSupportEmail=new ActiveXObject("Microsoft.XMLHTTP");
    }

    xmlhttpCustomerSupportEmail.onreadystatechange=function()
      {
          if (xmlhttpCustomerSupportEmail.readyState==4 && xmlhttpCustomerSupportEmail.status==200)
          {
			    alert(xmlhttpCustomerSupportEmail.responseText);
				$("#customerSupportEmail").val("");										
          }
		  
      }

    xmlhttpCustomerSupportEmail.open("GET",url+"?"+params,true);
    xmlhttpCustomerSupportEmail.send();
}

function showWebsiteTechnicalSupport()
{

	///clear form fields
		$("#formDiv input[type=text]").val("");
		$("#formDiv input[type=text]").removeClass("isInvalid").addClass("inputText");
		$("#formDiv input[type=text]").css({border:'thin solid #BDBDBD'});
		document.getElementById("message").value = "";
		
		$("#formDiv").hide();
		$("#hiddenCustomerSupportType").attr("value","website");	
		//show_modal("formDiv");
		$("#mask2").show();
		$("#formDiv").show();
		$("#formDiv").css({zIndex:'210000',backgroundColor:'white',border:'solid 4px red',padding:'10px',top:'0px',left:'160px',height:'510px'});

		$("#websiteTechnicalSupportLabel,#closeFormDiv").show();

		var color = $("#hiddenTheme").attr("value");
		var template = $("#hiddenSelectedTemplate").attr("value");
		switch (color)
		{
			case "orange":
				if(template=="2")
				{
					$("#formDiv").css({border:'4px solid #ffffff',backgroundColor:'#f77103',color:'#ffffff'});	
				}
				else
				{
					$("#formDiv").css({border:'4px solid #f77103'});
				}
				break;
			case "beige":
				if(template=="2")
				{
					$("#formDiv").css({border:'4px solid #ffffff',backgroundColor:'#6E4F33',color:'#ffffff'});	
				}
				else
				{
					$("#formDiv").css({border:'4px solid #6E4F33'});
				}
				break;
			case "green":
				if(template=="2")
				{
					$("#formDiv").css({border:'4px solid #ffffff',backgroundColor:'#597254',color:'#ffffff'});	
				}
				else
				{
					$("#formDiv").css({border:'4px solid #005900'});
				}
				break;
			case "red":
				if(template=="2")
				{
					$("#formDiv").css({border:'4px solid #ffffff',backgroundColor:'#B70000',color:'#ffffff'});	
				}
				else
				{
					$("#formDiv").css({border:'4px solid #B70000'});
				}
				break;	
			case "white":
				if(template=="2")
				{
					$("#formDiv").css({border:'4px solid #686868',backgroundColor:'#ffffff',color:'#bdbdbd'});	
				}
				else
				{
					$("#formDiv").css({border:'4px solid #686868'});
				}
				break;
			case "winesh":
				if(template=="2")
				{
					$("#formDiv").css({border:'4px solid #ffffff',backgroundColor:'#590300',color:'#ffffff'});	
				}
				else
				{
					$("#formDiv").css({border:'4px solid #6E4F33'});
				}
				break;
			case "black":
				$("#formDiv").css({border:'4px solid #ffffff',backgroundColor:'#000000',color:'#ffffff'});	
				
				break;
		}

		

}

function navigatePhoto(direction)
{
	$("#selectedPhoto").attr("src","../Images/loading1.gif");

	//$("#selectedPhoto").width("100");
	//$("#selectedPhoto").height("100");

	var currentImage = $("#photoThumb .current");

	var nextImage = currentImage.next(".photoClassContainer");

	var prevImage = currentImage.prev(".photoClassContainer");

	//alert(nextImage.html());

	if(nextImage.html()==null)
	{
		nextImage = $(".photoClassContainer:first");
	}
	
	if(prevImage.html()==null)
	{
		prevImage = $(".photoClassContainer:last");
	}

	var nextImageSrc = nextImage.find(".photoClass").attr("src");

	var prevImageSrc = prevImage.find(".photoClass").attr("src");

	$(".photoClassContainer").removeClass("current");

	if(direction=="prev")
	{
		prevImage.addClass("current");
		
		var photoHeight = prevImage.find(".photoHeight").val();
		
		var photoWidth = prevImage.find(".photoWidth").val();
		
		if(photoWidth>=900)
			photoWidth = 900;

		$("#photoPreview").css({height:photoHeight+'px',width:photoWidth+'px'});

		$("#photoPreview #imageContainer").css({height:photoHeight+'px',width:photoWidth+'px'});

		$("#selectedPhoto").attr("src",prevImageSrc);
	}
	else
	{
		nextImage.addClass("current");

		var photoHeight = nextImage.find(".photoHeight").val();
		
		var photoWidth = nextImage.find(".photoWidth").val();
		
		if(photoWidth>=900)
			photoWidth = 900;

		$("#photoPreview").css({height:photoHeight+'px',width:photoWidth+'px'});

		$("#photoPreview #imageContainer").css({height:photoHeight+'px',width:photoWidth+'px'});

		$("#selectedPhoto").attr("src",nextImageSrc);
	}

	
}

function swtichTemplates(selectedTemplate)
{
		var xmlhttpSwtichTemplates;
		var url = "updatePage.php";
		var params = "method=switchTemplate&selectedTemplate="+selectedTemplate;
		$("#saveChangesWaitImg").show();
		if (window.XMLHttpRequest)
		{// code for IE7+, Firefox, Chrome, Opera, Safari
			xmlhttpSwtichTemplates=new XMLHttpRequest();
		}
		else
		{// code for IE6, IE5
			xmlhttpSwtichTemplates=new ActiveXObject("Microsoft.XMLHTTP");
		}

		xmlhttpSwtichTemplates.onreadystatechange=function()
		  {
			  if (xmlhttpSwtichTemplates.readyState==4 && xmlhttpSwtichTemplates.status==200)
			  {
					//alert(xmlhttpSwtichTemplates.responseText);
					//window.location.reload();
					var formName = $("#hiddenFormName").val();
					switch (formName)
					{
						case "Index":
							window.location = "index.php";
							break;
						case "Menu":
							window.location = "menu.php";
							break;
						case "RestoInfo":
							window.location = "restoInfo.php";
							break;
						case "Photos":
							window.location = "photos.php";
							break;
						case "Register":
							window.location = "register.php";
							break;
						case "MyProfile":
							window.location = "myProfile.php";
							break;
						case "Vouchers":
							window.location = "vouchers.php";
							break;
						case "ContactUs":
							window.location = "contactUs.php";
							break;
					}
			  }
			  
		  }

		xmlhttpSwtichTemplates.open("GET",url+"?"+params,true);
		xmlhttpSwtichTemplates.send();
}


function setMetaKeywords()
{
		var xmlhttpMetaKeywords;
		var url = "updatePage.php";
		var params = "method=setMetaKeywords";
		
		if (window.XMLHttpRequest)
		{// code for IE7+, Firefox, Chrome, Opera, Safari
			xmlhttpMetaKeywords=new XMLHttpRequest();
		}
		else
		{// code for IE6, IE5
			xmlhttpMetaKeywords=new ActiveXObject("Microsoft.XMLHTTP");
		}

		xmlhttpMetaKeywords.onreadystatechange=function()
		  {
			  if (xmlhttpMetaKeywords.readyState==4 && xmlhttpMetaKeywords.status==200)
			  {
					//alert(xmlhttpMetaKeywords.responseText);
					$("meta[name=keywords]").attr("content",xmlhttpMetaKeywords.responseText);
			  }
			  
		  }

		xmlhttpMetaKeywords.open("GET",url+"?"+params,true);
		xmlhttpMetaKeywords.send();
}


function callUpdateURL(element,type)
{
	if(element.value.length==0)
	{
		alert("Enter "+type+" URL");
		element.focus();
		return;
	}	
	alert(type);
	updateURL(element.value,type);
}

function updateURL(link,type)
{
	
	//alert(type + " : " +link);
	var xmlhttpUpdateURL;
	var url = "updatePage.php";
	
	if(link.indexOf('#')!=-1)
	{
		link = link.substring(0,link.indexOf('#')) + link.substring(link.indexOf('#')+3);
		//alert(link);
		
	}

	var params = "method=updateURL&type="+type+"&link="+encodeURI(link);
	alert(params);
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttpUpdateURL=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
		xmlhttpUpdateURL=new ActiveXObject("Microsoft.XMLHTTP");
	}

	xmlhttpUpdateURL.onreadystatechange=function()
	  {
		  if (xmlhttpUpdateURL.readyState==4 && xmlhttpUpdateURL.status==200)
		  {
				alert(xmlhttpUpdateURL.responseText);
				if(type=="facebook")
				{
					$("#hiddenFacebookURL,#hiddenPrevFacebookURL").val(link);
					$(".addthis_button_facebook").attr("href",link);
				}
				else
				{
					$("#hiddenTwitterURL,#hiddenPrevTwitterURL").val(link);
					$(".addthis_button_twitter").attr("href",link);
				}
		  }
	  }

	xmlhttpUpdateURL.open("GET",url+"?"+params,true);
	xmlhttpUpdateURL.send();
}


function changeTheme(color)
{
	switch(color)
	{
		case "orange":
			changeColorScheme("commonOrange");
			$("#hiddenTheme").attr("value","orange");
			break;
		case "wooden":
			changeColorScheme("commonBeige");
			$("#hiddenTheme").attr("value","beige");
			break;
		case "green":
			changeColorScheme("commonGreen");
			$("#hiddenTheme").attr("value","green");
			break;
		case "red":
			changeColorScheme("commonRed");
			$("#hiddenTheme").attr("value","red");
			break;
		case "black":
			changeColorScheme("commonBlack");
			$("#hiddenTheme").attr("value","black");
			break;
		case "winesh":
			changeColorScheme("commonWinesh");
			$("#hiddenTheme").attr("value","winesh");
			break;
		case "white":
			changeColorScheme("commonWhite");
			$("#hiddenTheme").attr("value","white");
			break;
	}
	
	if(color=="orange")
	{
		updateMiddleContainerStyle("Orange");
	}
	else if(color=="green")
	{
		updateMiddleContainerStyle("Green");
	}
	else if(color=="wooden" || color=="beige")
	{
		updateMiddleContainerStyle("Beige");
	}
	else if(color=="red")
	{
		updateMiddleContainerStyle("Red");
	}
	else if(color=="black")
	{
		updateMiddleContainerStyle("Black");
	}
	else if(color=="white")
	{
		updateMiddleContainerStyle("White");
	}
	else if(color=="winesh")
	{
		updateMiddleContainerStyle("Winesh");
	}
}



function modifyWarningMessageStyle()
{
	var template = $("#hiddenSelectedTemplate").val();
	if(template=="2")
	{
		var selectedTheme = $("#hiddenTheme").val();
		if(selectedTheme!="white")
		{
                        if ($("#resume_detais_voucher").length > 0) {
                            $(".errorMessageContainer #emailErrorCenter,.errorMessageContainer #emailErrorLeftEdge,.errorMessageContainer #emailErrorRightEdge").css({backgroundImage:'none',zIndex:'0'});
                        } else {
                            $(".errorMessageContainer #emailErrorCenter,.errorMessageContainer #emailErrorLeftEdge,.errorMessageContainer #emailErrorRightEdge").css({backgroundImage:'none',backgroundColor:'#ffffff',zIndex:'0'});
                        }
			$("#postCodeDash,#secondPhoneFirstDash,#secondPhoneSecondDash,#phoneFirstDash,#phoneSecondDash").css({color:'#ffffff'});
		}
		else
		{
			$(".errorMessageContainer #emailErrorCenter").css({background:'url("../Images/RegisterPleaseCorrectCenterLine.png")'});
			$(".errorMessageContainer #emailErrorLeftEdge").css({background:'url("../Images/RegisterPleaseCorrectLeftCorner.png")'});
			$(".errorMessageContainer #emailErrorRightEdge").css({background:'url("../Images/RegisterPleaseCorrectRightCorner.png")'});
			$("#postCodeDash,#secondPhoneFirstDash,#secondPhoneSecondDash,#phoneFirstDash,#phoneSecondDash").css({color:'#686868'});
		}
	}
}


function addImageEditIcons()
{

	var deleteIconPath = "../Images/deleteIconW.png";
	var selectIconPath = "../Images/selectIconW.png";	

	if($("#hiddenTheme").val()=="white")
	{
		var deleteIconPath = "../Images/deleteIconB.png";
		var selectIconPath = "../Images/selectIconB.png";
	}

	$(".deleteImage").css({background:'url('+deleteIconPath+')', width:'17px', height:'17px',position:'relative',float:'right',display:'none'});
	$(".setImage").css({background:'url('+selectIconPath+')', width:'16px', height:'16px',position:'relative',float:'left',display:'none'});

	$(".deleteImage").click(function(event){
		var image = $(this).parent("div").attr("id");
		var imageId = image.substr(image.indexOf('_')+1,image.length);
		var imageType = $(this).parent("div").attr("class");

		var imagePath = $(this).parent("div").find("img").attr("class");
		
		var imageOnPage = "";
		var imageOnPageType = "";

		switch(imageType)
		{
			case "thumbnails header":
				var imgURL = $("#pizzaHeaderImg").css('backgroundImage');
				imageOnPage = imgURL.substring(5,imgURL.length-2);
				//alert(imageOnPage + "\n" + imagePath);
				//imageOnPage = document.getElementById("pizzaHeaderImg").style.background;//$("#pizzaHeaderImg").attr("src");
				imageOnPageType = "header";
				break;
			case "thumbnails index":
				imageOnPage = $("#middlePizzaImg img").attr("src");
				imageOnPageType = "index";
				break;
			case "thumbnails footer":
				//imageOnPage = $("#tenPercentOffImg").attr("src");
				var imgURL = $("#footerBackImg").css('backgroundImage');
				imageOnPage = imgURL.substring(5,imgURL.length-2);
				//alert(imageOnPage + "\n" + imagePath);
				imageOnPageType = "footer";
				break;
			case "thumbnails offer":
				imageOnPage = $("#tenPercentOffImg").attr("src");				
				imageOnPageType = "offer";
				break;
			case "thumbnails background":
				imageOnPage = $("#bgImage img").attr("src");
				imageOnPageType = "background";
				break;
		}
		
		//alert(imagePath==imageOnPage);

		if(imagePath==imageOnPage)
		{
			alert("This image is currently being used as "+ imageOnPageType +" image, so cannot delete now.");
		}
		else
		{
			deleteImage(imageId, imageType);
		}
		
		//to stop from event bubbling
		event.stopPropagation();
	});

	$(".setImage").click(function(event){
		var image = $(this).parent("div").attr("id");
		var imageType = $(this).parent("div").attr("class");
		var imagePath = $(this).parent("div").find("img").attr("class");
		setImage(imageType, imagePath);

		//to stop from event bubbling
		event.stopPropagation();
	});
}

function deleteImage(imageId, imageType)
{
	var result=window.confirm("Do you want to delete this image?");
	if(result)
	{
		removeImageFromDatabase(imageId, imageType);
	}
}

function removeImageFromHTML(imageId, imageType)
{
	var image = "#thumb_"+imageId;
	
	if(imageType=="RestoPhoto")
	{
		$("#photo_"+imageId).parent("div").remove();
	}
	else
	{
		$(image).remove();
	}

	
	switch(imageType)
	{
		case "thumbnails header":
			$('#scrollbar2').tinyscrollbar();
			break;
		case "thumbnails index":
			$('#scrollbar6').tinyscrollbar();
			break;
		case "thumbnails footer":
			$('#scrollbar3').tinyscrollbar();
			break;
		case "thumbnails offer":
			$('#scrollbar4').tinyscrollbar();
			break;
		case "thumbnails background":
			$('#scrollbar3').tinyscrollbar();
			break;
		case "RestoPhoto":
			$('#scrollbar5').tinyscrollbar();
			break;
	}
	
}

function removeImageFromDatabase(imageId, imageType)
{
	var xmlhttpRemoveImage;
	var url = "updatePage.php";
	var params = "method=removeImage&imageId="+imageId+"&imageType="+imageType;
	
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttpRemoveImage=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
		xmlhttpRemoveImage=new ActiveXObject("Microsoft.XMLHTTP");
	}

	xmlhttpRemoveImage.onreadystatechange=function()
	  {
		  if (xmlhttpRemoveImage.readyState==4 && xmlhttpRemoveImage.status==200)
		  {
				alert(xmlhttpRemoveImage.responseText);
				removeImageFromHTML(imageId,imageType);
		  }
	  }

	xmlhttpRemoveImage.open("GET",url+"?"+params,true);
	xmlhttpRemoveImage.send();
}

function setImage(imageType, imagePath)
{
	switch(imageType)
	{
		case "thumbnails header":
			$("#pizzaHeaderImg").css("background-image","url("+imagePath+")");
			$("#headerImagePath").attr("value",imagePath);
			alert("Header image changed");
			break;
		case "thumbnails index":
			$("#middlePizzaImg img").attr("src",imagePath);
			$("#hiddenIndexImage").attr("value",imagePath);				
			alert("Index image changed");
			break;
		case "thumbnails footer":
			$("#footerBackImg").css("background-image","url("+imagePath+")");
			$("#footerImagePath").attr("value",imagePath);
			alert("Footer image changed");
			break;
		case "thumbnails offer":
			$("#tenPercentOffImg").attr("src",imagePath);
			$("#hiddenOfferImage").attr("value",imagePath);
			alert("Offer image changed");
			break;
		case "thumbnails background":
			$("#bgImage img").attr("src",imagePath);
			$("#hiddenBackgroundImage").attr("value",imagePath);
			alert("Background image changed");
			break;
	}
	
	changesDone = true;
}