var xmlHttpList;
var currentStep;
var currentTab;
currentTab = 1;
var basePrice;
//var prefix = "ctl00_PlaceHolderTopCenter_AreaCenter_160bfc7c9de54cdab8a70cfaa0301d19_";
var step5price1 = 0;
var step5heading1 = '';
var step5subheading1 = '';
var step5price2 = 0;
var step5heading2 = '';
var step5subheading2 = '';
function ShowStep(x)
{	
    currentStep = x;
    document.getElementById(prefix + 'w_stepId').value = currentStep;
    if(currentStep == 1)
    {
        document.getElementById('w_TopNav_0').className = 'luxNavWelcomeBg1 luxNavActiveBack';
    }
    else
    {
        document.getElementById('w_TopNav_0').className = 'luxNavWelcomeBg2';
    }
    for(index = 1; index <= 10;index++)
    {
        if(index == currentStep)
        {
            if(document.getElementById('w_TopNav_' + index) != null)
            {
                document.getElementById('w_TopNav_' + index).className = 'luxNavActive';
            }
        }
        else if(index == currentStep - 1)
        {
            if(document.getElementById('w_TopNav_' + index) != null)
            {
                document.getElementById('w_TopNav_' + index).className = 'luxNavActiveBack';
            }
        }
        else
        {
            if(document.getElementById('w_TopNav_' + index) != null)
            {
                document.getElementById('w_TopNav_' + index).className = "";
            }
        }
    }
    for(index = 1; index < 10;index++)
    {
        if(document.getElementById('w_StepDiv_' + index) != null)
        {
            if(currentStep == index)
            {
                document.getElementById('w_StepDiv_' + index).style.display = 'block';
            }
            else
            {
                document.getElementById('w_StepDiv_' + index).style.display = 'none';
            }
        }
    }
    if(currentStep == 10)
    {
        document.getElementById('totalBar').style.display = 'none';
        document.getElementById('SamplePageButtons').style.display = 'none';
        document.getElementById('WizardBottomContentBB').style.display = 'none';
        document.getElementById('WizardBottomContentSP').style.display = 'none';
        document.getElementById("WizardBottomContentFAQ").style.display = 'none';
        document.getElementById('w_SummaryDiv_1').style.display = 'block';
        document.getElementById('w_SummaryDiv_2').style.display = 'block';
        document.getElementById(prefix + "vdtrMissingInfo").innerHTML = "";
    }
    else
    {
    	document.getElementById('w_SummaryDiv_1').style.display = 'none';
        document.getElementById('w_SummaryDiv_2').style.display = 'none';
        document.getElementById('SamplePageButtons').style.display = 'block';
        if(currentTab == 1)
	        document.getElementById('WizardBottomContentBB').style.display = 'block';
	    if(currentTab == 2)
	        document.getElementById('WizardBottomContentSP').style.display = 'block';
	    if(currentTab == 3)
	    	document.getElementById("WizardBottomContentFAQ").style.display = 'block';        
        document.getElementById('totalBar').style.display = 'block';
    }
    
    return false;
}
function UpdateSession()
{
	if (xmlHttpList != null)
	    xmlHttpList.abort();
	xmlHttpList = GetXmlHttpObject(function(){});
	var requestUrl = "/LuxuryEdition/Pages/AjaxServer.aspx?szAjaxUpdateSession=yes";
	var params = "";
	params = "Price=" + document.getElementById(prefix + 'w_hdn_total').value;
	params = params + "&CurrentStep=" + currentStep;
	for(step = 1; step<10; step++)
	{
		for(index = 1;; index++)
		{
			rbtn = document.getElementById(prefix + "Step"+ step +"_Option" + index);
			if(rbtn != null)
			{
				if(rbtn.checked)
				{
					params = params + "&Step"+ step +"=" + index;
				}
			}
			else
			{
				break;
			}
		}
		if(step == 5)
		{
			for(index = 1;; index++)
			{
				rbtn = document.getElementById(prefix + "Step50_Option" + index);
				if(rbtn != null)
				{
					if(rbtn.checked)
					{
						params = params + "&Step50=" + index;
					}
				}
				else
				{
					break;
				}
			}
		}
		if(step == 6)
		{
			params = params + "&Step6_Name=" + document.getElementById(prefix + "Step6_txtName").value;
			params = params + "&Step6_Latitude=" + document.getElementById(prefix + "Step6_txtLat").value;
			params = params + "&Step6_Longitude=" + document.getElementById(prefix + "Step6_txtLong").value;
		}
		if(step == 7)
		{			
			params = params + "&Step7_Initials=" + document.getElementById(prefix + "Step7_txtInitials").value;
		}
		if(step == 8)
		{
			params = params + "&Step8_Date=" + document.getElementById(prefix + "Step8_txtDate").value;
			params = params + "&Step8_Name=" + document.getElementById(prefix + "Step8_txtName").value;
		}
	}
	SendXmlHttpPostRequest(xmlHttpList, requestUrl, params);
    return false;
}
function ShowPrevStep()
{
    if(currentStep > 1)
    {
        currentStep--;
        ShowStep(currentStep);
    }
    if (currentStep == 1)
	{
	window.location = "/LuxuryEdition/Pages/home.aspx";
	}
    return false;
}
function ShowNextStep()
{
	if(currentStep < 10)
	{
		currentStep++;
		ShowStep(currentStep);
	}
	return false;
}
function UpdateSummary(stepId,heading,sub_heading,price,image_url)
{  
    // for 5th step 
    if(stepId == 5)
    {
        step5heading1 = heading;
        /*if(!document.getElementById(prefix + "Step50_Option1").checked && !document.getElementById(prefix + "Step50_Option2").checked)
		{
			step5heading1 = step5heading1 + "<br/>" + "<span color='#e1272e>'Crest or Logo - Not Specified</span>";
		}*/
        step5subheading1 = sub_heading;
        step5price1 = price; 
    }
    if(stepId == 50)
    {
        step5heading2 = heading;
        step5subheading2 = sub_heading;
        step5price2 = price;      
    }      
    if(stepId == 50 || stepId == 5)
    {
        document.getElementById('s_listCol2_' + 5).className = 'clmn2'; 
        if(step5heading1 != '' && step5heading2 != '')
        {
            document.getElementById(prefix + 's_lbl_heading_' + 5).innerHTML = step5heading1 + "<br/>" + step5heading2;
            document.getElementById(prefix + 's_lbl_subheading_' + 5).innerHTML = step5subheading1 + "<br/>" + step5subheading2;
            if(step5price1 != "0" && step5price2 != "0" )
            {
                document.getElementById(prefix + 's_lbl_price_' + 5).innerHTML = '+ &#163; ' + step5price1 + "<br/>" + '+ &#163; ' + step5price2;
            }
            else if (step5price2 != "0")
            {
            	document.getElementById(prefix + 's_lbl_price_' + 5).innerHTML = "<br/>" + '+ &#163; ' + step5price2;
            }
            else if (step5price1 != "0")
            {
                document.getElementById(prefix + 's_lbl_price_' + 5).innerHTML = '+ &#163; ' + step5price1 + "<br/>";
            }
            else
            {
                document.getElementById(prefix + 's_lbl_price_' + 5).innerHTML = "";
            }

        }
        else if(step5heading2 != '')
        {
            document.getElementById(prefix + 's_lbl_heading_' + 5).innerHTML = "<span style='color:#e1272e'>Times Branding - Not Specified</span>" + "<br/>" + step5heading2;
            document.getElementById(prefix + 's_lbl_subheading_' + 5).innerHTML = "<br/>" +step5subheading2;
            if(step5price2 != "0" )
            {
                document.getElementById(prefix + 's_lbl_price_' + 5).innerHTML = "<br/>" + '+ &#163; ' + step5price2;
            }
            else
            {
                document.getElementById(prefix + 's_lbl_price_' + 5).innerHTML = "";
            }
        }
        else
        {
            document.getElementById(prefix + 's_lbl_heading_' + 5).innerHTML = step5heading1 + "<br/>" + "<span style='color:#e1272e'>Crest or Logo - Not Specified</span>";
            document.getElementById(prefix + 's_lbl_subheading_' + 5).innerHTML = step5subheading1 + "<br/>";
            if(step5price1 != "0")
            {
                document.getElementById(prefix + 's_lbl_price_' + 5).innerHTML = '+ &#163; ' + step5price1 + "<br/>";
            }
            else
            {
                document.getElementById(prefix + 's_lbl_price_' + 5).innerHTML = "";
            }
        }
        document.getElementById(prefix + "Step5_MainImage").src = '/Style Library/Images/TimesAtlas/' + image_url;   
    }
    else
    {
        document.getElementById('s_listCol2_' + stepId).className = 'clmn2';   
        document.getElementById(prefix + 's_lbl_heading_' + stepId).innerHTML = heading;
        document.getElementById(prefix + 's_lbl_subheading_' + stepId).innerHTML = sub_heading;
        if(price != "0")
        {
            document.getElementById(prefix + 's_lbl_price_' + stepId).innerHTML = '+ &#163; ' + price;
        }
        else
        {
            document.getElementById(prefix + 's_lbl_price_' + stepId).innerHTML = "";
        }
        document.getElementById(prefix + "Step" + stepId + "_MainImage").src = '/Style Library/Images/TimesAtlas/' + image_url;  
    }
    UpdateTotal();
    UpdateSession();
}
function UpdateTotal()
{
    var sum = basePrice;
    for(index1=1;index1<=9;index1++)
    {
        for(index2=1;;index2++)
        {
            if(document.getElementById(prefix + "Step" + index1 + "_Option" + index2) != null)
            {
                if(document.getElementById(prefix + "Step" + index1 + "_Option" + index2).checked)
                {
                	//alert("Step" + index1 + "_Option" + index2 + document.getElementById(prefix + "Step" + index1 + "_Option" + index2).getAttribute("Price"));
                    sum += parseInt(document.getElementById("hdn_" + "Step" + index1 + "_Option" + index2).value);                    
                }
            }
            else
            {
                break;
            }
        }
    } 
    if(document.getElementById(prefix + "Step50_Option1").checked)
    {
        sum += parseInt(document.getElementById("hdn_" + "Step50_Option1").value);
    }
    if(document.getElementById(prefix + "Step50_Option2").checked)
    {
        sum += parseInt(document.getElementById("hdn_" + "Step50_Option2").value);
    }
    document.getElementById(prefix + 'w_total').innerHTML = sum;
    document.getElementById(prefix + 'w_hdn_total').value = sum;
    //document.getElementById(prefix + 'btn_Summary_PlaceOrder').value = "Price: "+ poundSymbol + sum + " -- Place Order";
    document.getElementById(prefix + 'lblTotalPrice').innerHTML = "Total Order Price "+ poundSymbol +" " +sum;
}
function UpdateTextSummary()
{	
	if(document.getElementById(prefix + 'Step6_Option2').checked)
	{
		document.getElementById(prefix + 's_lbl_subheading_6').innerHTML = "Personalised<i><br/>Name: "+ document.getElementById(prefix + 'Step6_txtName').value +"<br/>Lattitude: " + document.getElementById(prefix + 'Step6_txtLat').value + "<br/>Longitude: "+ document.getElementById(prefix + 'Step6_txtLong').value +"</i>";
	}

	if(document.getElementById(prefix + 'Step7_Option1').checked)
	{
		document.getElementById(prefix + 's_lbl_heading_7').innerHTML = "With Initials<i><br/>Initials: "+ document.getElementById(prefix + 'Step7_txtInitials').value + "</i>";
	}

	if(document.getElementById(prefix + 'Step8_Option1').checked)
	{
		document.getElementById(prefix + 's_lbl_subheading_8').innerHTML = "Date and Name<i><br/>Date: "+ document.getElementById(prefix + 'Step8_txtDate').value +"<br/>Name: " + document.getElementById(prefix + 'Step8_txtName').value + "</i>";
	}       
}
function ChangeBottomTab(tabName)
{
	if(tabName == 'Book')
	{
		currentTab = 1;
		document.getElementById("divBookTab").className = 'subNav1Active';
		document.getElementById("divSampleTab").className = '';
		document.getElementById("divFAQTab").className = '';
		document.getElementById("WizardBottomContentBB").style.display = 'block';
		document.getElementById("WizardBottomContentSP").style.display = 'none';
		document.getElementById("WizardBottomContentFAQ").style.display = 'none';
	}
	if(tabName == 'Sample')
	{
		currentTab = 2;
		document.getElementById("divBookTab").className = '';
		document.getElementById("divSampleTab").className = 'subNav1Active';
		document.getElementById("divFAQTab").className = '';
		document.getElementById("WizardBottomContentBB").style.display = 'none';
		document.getElementById("WizardBottomContentSP").style.display = 'block';
		document.getElementById("WizardBottomContentFAQ").style.display = 'none';
	}
	if(tabName == 'FAQ')
	{
		currentTab = 3;
		document.getElementById("divBookTab").className = '';
		document.getElementById("divSampleTab").className = '';
		document.getElementById("divFAQTab").className = 'subNav1Active';
		document.getElementById("WizardBottomContentBB").style.display = 'none';
		document.getElementById("WizardBottomContentSP").style.display = 'none';
		document.getElementById("WizardBottomContentFAQ").style.display = 'block';
	}
}
function Clear6thTextBoxes()
{	
	document.getElementById(prefix + "Step6_txtName").value = "";
	document.getElementById(prefix + "Step6_txtLat").value = "";
	document.getElementById(prefix + "Step6_txtLong").value = "";
}
function Clear7thTextBoxes()
{	
	document.getElementById(prefix + "Step7_txtInitials").value = "";
}
function Clear8thTextBoxes()
{	
	document.getElementById(prefix + "Step8_txtDate").value = "";
	document.getElementById(prefix + "Step8_txtName").value = "";
}
function CheckRdb(rid)
{
	if(document.getElementById(prefix + rid) != null)
	{
		document.getElementById(prefix + rid).checked=true;
	}
}
function OpenLatLong()
{
	window.open("/ExtractLatLongCoordinates/Default.aspx","LatLongWindow","width=420,height=250,status=1,scrollbars=1,resizable=1,top=100,left=200");
	return false;
}
function OpenCrestHelp()
{
	var x = window.open("","CrestHelpWindow","width=420,height=250,status=1,scrollbars=1,resizable=1,top=100,left=200");
	x.document.write("<style>a:link {color:#252525} a:visited {color:#ccc}a:hover {color:orange}a:active {color:#252525}</style><span style=\"font:76% Arial, Helvetica, sans-serif; color:#555555\"><br/><br/>Send us a high resolution (300 dpi) file, black only, as a tiff, PDF or Illustrator EPS. We can accept other file formats too. If you need any further details, please use the <a href='javascript:void(0);' onclick='window.opener.location=\"/Footer/pages/ContactUs.aspx\";window.close();'>Contact Us</a> form.</span>");
	return false;
}
function OpenDateHelp()
{
	var x = window.open("","CrestDateWindow","width=410,height=328,status=1,scrollbars=1,resizable=1,top=100,left=200");
	x.document.write("<span style=\"font:76% Arial, Helvetica, sans-serif; color:#555555\"><br/><br/>Enter a date of your choice to indicate when your special edition was created. This could be a birthday, anniversary or important date to you. If left blank the date that this page is printed will be used.</span><br/><br/><img src='/Style Library/Images/TimesAtlas/Date_Message.gif'>");
	return false;
}

function fnSetLatLong(latdel,latmin,latsec,lathemi,londel,lonmin,lonsec,lonhemi)
{
	document.getElementById(prefix + "Step6_txtLat").value = latdel + "\u00b0 " + latmin + "' " + latsec + "\" " + lathemi;
	document.getElementById(prefix + "Step6_txtLong").value = londel + "\u00b0 " + lonmin + "' " + lonsec + "\" " + lonhemi;
}

function CheckMissingInfo(sender, args)
{
	var lbl = document.getElementById(prefix + "vdtrMissingInfo");
	var lblHeading;
	var errMsg = "";
	var missingInf = "";
	for(index = 1; index < 10; index++)
	{
		if(index != 5)
		{
			if(document.getElementById(prefix + "s_lbl_heading_" + index).innerHTML.indexOf("Not Specified") != -1)
			{
				lblHeading = document.getElementById(prefix + "lblStepHeading_" + index).innerHTML;
				errMsg += "<h2 class=\"MissingInfo\">" + lblHeading.substr((lblHeading.search("Your ")==0)?5:0) + "</h2><Label>Please specify your "+ lblHeading.substr((lblHeading.search("Your ")==0)?5:0) + " preferences</Label>";				
			}
			if(index == 6 && document.getElementById(prefix + "Step6_Option2").checked)
			{
				lblHeading = document.getElementById(prefix + "lblStepHeading_" + index).innerHTML;
				if(Trim(document.getElementById(prefix + "Step6_txtName").value) == "" || Trim(document.getElementById(prefix + "Step6_txtLat").value) == "" || Trim(document.getElementById(prefix + "Step6_txtLong").value) == "")
				{
					missingInf += "<h2 class=\"MissingInfo\">" + lblHeading.substr((lblHeading.search("Your ")==0)?5:0) + "</h2><Label>Please specify your Name, Latitude and Longitude to be printed</Label>";
				}
			}
			if(index == 7 && document.getElementById(prefix + "Step7_Option1").checked)
			{
				lblHeading = document.getElementById(prefix + "lblStepHeading_" + index).innerHTML;
				if(Trim(document.getElementById(prefix + "Step7_txtInitials").value) == "")
				{
					missingInf += "<h2 class=\"MissingInfo\">" + lblHeading.substr((lblHeading.search("Your ")==0)?5:0) + "</h2><Label>Please specify your Initials to be printed</Label>";
				}
			}
			if(index == 8 && document.getElementById(prefix + "Step8_Option1").checked)
			{
				lblHeading = document.getElementById(prefix + "lblStepHeading_" + index).innerHTML;
				if(Trim(document.getElementById(prefix + "Step8_txtDate").value) == "" || Trim(document.getElementById(prefix + "Step8_txtName").value) == "")
				{
					missingInf += "<h2 class=\"MissingInfo\">" + lblHeading.substr((lblHeading.search("Your ")==0)?5:0) + "</h2><Label>Please specify Date and your Name to be printed</Label>";
				}
			}


		}
		else
		{
			if(!document.getElementById(prefix + "Step5_Option1").checked && !document.getElementById(prefix + "Step5_Option2").checked)
			{
				lblHeading = document.getElementById(prefix + "lblStepHeading_" + index).innerHTML;
				errMsg += "<h2 class=\"MissingInfo\">" + lblHeading.substr((lblHeading.search("Your ")==0)?5:0) + "</h2><Label>Please specify your "+ lblHeading.substr((lblHeading.search("Your ")==0)?5:0) + " preferences</Label>";
			}
			else if(!document.getElementById(prefix + "Step50_Option1").checked && !document.getElementById(prefix + "Step50_Option2").checked)
			{
				lblHeading = "Front Cover - Crest or Logo";
				errMsg += "<h2 class=\"MissingInfo\">" + lblHeading + "</h2><Label>Please specify your "+ lblHeading + " preferences</Label>";
			}
		}
	}
	if(errMsg.length > 0)
	{
		lbl.innerHTML = "<h2 class=\"MissingInfo\">Missing Information</h2><br/><br/>" + errMsg;
		args.IsValid = false;
		return;
	}
	else
	{
		if(missingInf.length > 0)
		{
			lbl.innerHTML = "<h2 class=\"MissingInfo\">Missing Information</h2><br/><br/>" + missingInf;
			args.IsValid = false;
			return;
		}
		else
		{
			lbl.innerHTML = "";
			args.IsValid = true;
			return;
		}
	}		
}

function Trim(TRIM_VALUE)
{
    if(TRIM_VALUE.length < 1)
    {
        return"";
    }
    TRIM_VALUE = RTrim(TRIM_VALUE);
    TRIM_VALUE = LTrim(TRIM_VALUE);
    if(TRIM_VALUE=="")
    {
        return "";
    }
    else
    {
        return TRIM_VALUE;
    }
}

function RTrim(VALUE)
{
    var w_space = String.fromCharCode(32);
    var v_length = VALUE.length;
    var strTemp = "";
    if(v_length < 0)
    {
        return"";
    }
    var iTemp = v_length -1;

    while(iTemp > -1)
    {
        if(VALUE.charAt(iTemp) == w_space)
        {
        }
        else
        {
            strTemp = VALUE.substring(0,iTemp +1);
            break;
        }
        iTemp = iTemp-1;
    } //End While
    return strTemp;

} //End Function

function LTrim(VALUE)
{
    var w_space = String.fromCharCode(32);
    if(v_length < 1)
    {
        return"";
    }
    var v_length = VALUE.length;
    var strTemp = "";

    var iTemp = 0;

    while(iTemp < v_length)
    {
        if(VALUE.charAt(iTemp) == w_space)
        {
        }
        else
        {
            strTemp = VALUE.substring(iTemp,v_length);
            break;
        }
        iTemp = iTemp + 1;
    } //End While
    return strTemp;
} //End Function


