﻿// JScript File
var oImage1 = new Image(84,28);
oImage1.src = 'hnavbar_b2.gif';
var oImage2 = new Image(84,28);
oImage2.src = 'hnavbar_b2_over.gif';
var oImage3 = new Image(78,22);
oImage3.src = 'vnavbar_btn.gif';
var oImage4 = new Image(78,22);
oImage4.src = 'vnavbar_btn_over.gif';

function bgButtonHilite(button,url)
{
	button.style.backgroundImage = 'url(../images/'+url+')';
}
function bgButtonLolite(button,url)
{
	button.style.backgroundImage = 'url(../images/'+url+')';
}
function BlockHilite(button)
{
	button.style.border = '1px solid silver';
}
function BlockLolite(button)
{
	button.style.border = '1px solid white';
}
function TopNav(url)
{
	window.location.href = url;
	return false;
}
function GetProduct(PrdId,PtId,PstId,ParentPstId,PtName,PstName,ParentPstName)
{
	window.location.href = 'Products4.aspx?PrdId='+PrdId+'&PtId='+PtId+'&PtName='+PtName+'&ParentPstId='+ParentPstId+'&ParentPstName='+ParentPstName+'&PstName='+PstName;
    return false;
}

var oNewPage;
function OpenNewPage(url)
{
	if(oNewPage != null)
	{
		if(oNewPage.closed) 
		{
			oNewPage = window.open(url,'AdditionalGattegnoResources','width=800,height=600,resizable');
			oNewPage.focus();
		}
		else
		{
			oNewPage.focus();
		}
	}
	else
	{
		oNewPage = window.open(url,'AdditionalGattegnoResources','width=800,height=600,resizable');
		oNewPage.focus();
	}
}

function SetNewPageId(PageId,PageURL)
{
//    location.href = PageURL+'?PageId='+PageId;
   var elements = window.document.getElementsByTagName("*");
   for(var i=0; i<elements.length;i++){
       var ControlId = elements[i].id;
       if(ControlId.indexOf("hPageId") != -1)
       {
           document.getElementById(ControlId).value = PageId;
       }
   } 
    return false;
}

var oRTEWindow
var oText = new Object();

function OpenRTE(Element)
{
//debugger
   var elements = window.document.getElementsByTagName("*");
   for(var i=0; i<elements.length;i++){
        var ControlId = elements[i].id;
        if(ControlId.indexOf(Element) != -1)
        {
            if(elements[i].tagName=="DIV")
            {
                var text = document.getElementById(ControlId).innerHTML;
                oText.text = text;
                oText.element = Element;
//                oText.element = 'h'+Element;
            }
        }
    }

//	var url = 'RTE.htm';
	var url = 'RTE.aspx?ControlId='+Element;
	if(oRTEWindow != null)
	{
		if(oRTEWindow.closed) 
		{
			oRTEWindow = window.open(url,'EditTextBlock','width=850,height=700,resizable');
			oRTEWindow.focus();
		}
		else
		{
			oRTEWindow.close();
			oRTEWindow = window.open(url,'EditTextBlock','width=850,height=700,resizable');
			oRTEWindow.focus();
		}
	}
	else
	{
		oRTEWindow = window.open(url,'EditTextBlock','width=850,height=700,resizable');
		oRTEWindow.focus();
	}
    TopButtons();
	return false;

}
function RemoveDefaultText(TextArea,text)
{
    if(TextArea.value == text){
        TextArea.value = '';
        }
    TopButtons();
}
function TopButtons(){        
    var elements = document.getElementsByTagName("*");
    for(var i=0; i<elements.length;i++){
        var ControlId = elements[i].id;
        if(ControlId.indexOf('PreviewBtn') != -1)
        {
            document.getElementById(ControlId).style.visibility = 'hidden';
        }
        if(ControlId.indexOf('PostBtn') != -1)
        {
            document.getElementById(ControlId).style.visibility = 'visible';
        }
        if(ControlId.indexOf('CancelBtn') != -1)
        {
            document.getElementById(ControlId).style.visibility = 'visible';
        }
    }
}
function GoToDesignSite(){
    document.forms[0].action = 'DesignWebsite.aspx';
	document.forms[0].submit();
	
	return false;

//    window.top.window.location.href = 'DesignWebsite.aspx';
}
function CaptureTextChange(TextBox,Session)
{
    var sText = document.getElementById(TextBox.id).value;
    sText += ","+Session
    CallServer(sText,""); 
}

function ReceiveServerData(arg, context)
{ 
    var s = arg;
}
function maxlength(oComment)
{
	var sComment = oComment.value;
	if(sComment.length > 500)
	{
//debugger
		sComment = sComment.substring(0,500);
		oComment.value = sComment;
		iCharsLeft = 0;
		window.alert("This text box is full.");
	}
	else
	{
		iCharsLeft = 500 - sComment.length;
	}
	document.getElementById('iNumCharsLeft').innerHTML = iCharsLeft;

}
	var oImgWindow;
	function PopImg()
	{
		document.getElementById("popupImgSrc").value = ImgToPop;
		if(oImgWindow != null)
		{
			if(oImgWindow.closed) 
			{
				oImgWindow = window.open('image.htm','imgPage','width=800,height=800,resizable,scrollbars');
				oImgWindow.focus();
			}
			else
			{
//				oImgWindow.document.getElementById("detImgLoc").src = ImgToPop;
				oImgWindow.close();
				oImgWindow = window.open('image.htm','imgPage','width=800,height=800,resizable,scrollbars');
				oImgWindow.focus();
			}
		}
		else
		{
			oImgWindow = window.open('image.htm','imgPage','width=800,height=800,resizable,scrollbars');
			oImgWindow.focus();
		}
	}
	function GoToProduct(PageId,PrdId,PtId,PstId,ParentPstId,PtName,PstName,ParentPstName)
    {
	    document.getElementById('PtId').value = PtId;
	    document.getElementById('PtName').value = PtName;
	    document.getElementById('PstId').value = PstId;
	    document.getElementById('PstName').value = PstName;
	    document.getElementById('ParentPstId').value = ParentPstId;
	    document.getElementById('ParentPstName').value = ParentPstName;
	    document.getElementById('PrdId').value = PrdId;
	    // Products4
	    document.forms[0].action= 'Products.aspx?PageId=' + PageId;
	    document.forms[0].submit();
	    
	    return false;
    }
    function GoToProducts(PageId,PtId,PstId,ParentPstId,PtName,PstName,ParentPstName)
    {
	    document.getElementById('PtId').value = PtId;
	    document.getElementById('PtName').value = PtName;
	    document.getElementById('PstId').value = PstId;
	    document.getElementById('PstName').value = PstName;
	    document.getElementById('ParentPstId').value = ParentPstId;
	    document.getElementById('ParentPstName').value = ParentPstName;
	    // Products3
	    document.forms[0].action= 'Products.aspx?PageId=' + PageId;
	    document.forms[0].submit();
    }
    function AddToCart(PageId,PrdId,PstId,PtId,OptId)
	{
		var iPSTSelected = PstId;
		var hdrCartContents;
		if(OptId!="")
		{
			hdrCartContents = OptId +',1';
		}
		else
		{
			hdrCartContents = PrdId +',1';
		}
	    document.getElementById('PrdIds').value = hdrCartContents;
	    document.getElementById('iPST').value = iPSTSelected;
	    document.getElementById('PtId').value = PtId;

		//window.location.href("Cart.aspx?PrdId="+hdrCartContents+"&iPST="+iPSTSelected+"&PTId="+PtId);
	    document.forms[0].action= 'Cart.aspx?PageId='+PageId;
	    document.forms[0].submit();
	    return false;
	}
	function GotoCheckout(PageId)
    {
	    document.getElementById("hCartContents").value = '';

    //	document.forms[0].action = 'https://www.paypal.com/cgi-bin/webscr';
	    document.forms[0].action = 'Cart.aspx?PageId='+PageId;
	    document.forms[0].target = '_parent'
	    document.forms[0].submit();
	    return false;
    }
    function CheckCheckbox(Checkbox,PrdId)
    {
	    if(Checkbox.checked==true)
	    {
		    if(window.confirm("Are you sure you wish to delete this item?"))
		    {
			    var hPrdToDel = document.getElementById("DeletedPrd").value;
			    if(hPrdToDel.length != 0)
			    {
				    document.getElementById("DeletedPrd").value += ';'+PrdId;
			    }
			    else
			    {
				    document.getElementById("DeletedPrd").value += PrdId;
			    }
			    document.forms[0].submit();
		    }
	    }
	    else
	    {
		    Checkbox.value = "off";
	    }
    }
    function Contents(sCartContents)
    {
	    document.forms[0].CartContents.value = sCartContents;
	    return true;
    }
    function updateCart(cartContents)
    {
	    document.forms[0].submit();
        return false;
    }
    function AddNewQty(Qty,PrdId)
    {
	    var hNewQty = document.getElementById("newQty").value;
	    if(hNewQty.length != 0)
	    {
		    document.getElementById("newQty").value += ';'+PrdId+','+Qty.value;
	    }
	    else
	    {
		    document.getElementById("newQty").value += PrdId+','+Qty.value;
	    }
    }
    function GotoPrevScreen(Page) 
    {
    document.forms[0].action= 'Products.aspx?PageId='+Page;
    document.forms[0].submit();
    return false;
    }
    function validateAddress()
{
	var sAlertStr
	sAlertStr = ''

	if(document.forms[0].t_name.value == '')
	{		sAlertStr += "Please enter your invoice name";	}
	if(document.forms[0].t_address1.value == '')
	{	if (sAlertStr == '')
		{	sAlertStr += "Please enter your invoice street address";	}
		else
		{	sAlertStr += ", your invoice street address";	}
	}
	if(document.forms[0].t_city.value == '')
	{	if (sAlertStr == '')
		{	sAlertStr += "Please enter your invoice town or city";	}
		else
		{	sAlertStr += ", your invoice town or city";	}	
	}
	if(document.forms[0].t_zip.value == '')
	{	if (sAlertStr == '')
		{	sAlertStr += "Please enter your invoice postcode";	}
		else
		{	sAlertStr += ", your invoice postcode";	}
	}	
	if(document.forms[0].t_night_phone_b.value == '')
	{	if (sAlertStr == '')
		{	sAlertStr += "Please enter your invoice phone number";	}
		else
		{	sAlertStr += ", your phone invoice number";	}
	}

	if(document.forms[0].d_name.value == '')
    {	if (sAlertStr == '')	
        {	sAlertStr += "Please enter your delivery name";	}
		else
		{	sAlertStr += ", your delivery name";		}
	}
	if(document.forms[0].d_address1.value == '')
	{	if (sAlertStr == '')
		{	sAlertStr += "Please enter your delivery street address";	}
		else
		{	sAlertStr += ", your delivery street address";	}
	}
	if(document.forms[0].d_city.value == '')
	{	if (sAlertStr == '')
		{	sAlertStr += "Please enter your delivery town or city";	}
		else
		{	sAlertStr += ", your delivery town or city";	}	
	}
	if(document.forms[0].d_zip.value == '')
	{	if (sAlertStr == '')
		{	sAlertStr += "Please enter your delivery postcode";	}
		else
		{	sAlertStr += ", your delivery postcode";	}
	}	
	if(document.forms[0].d_night_phone_b.value == '')
	{	if (sAlertStr == '')
		{	sAlertStr += "Please enter your delivery phone number";	}
		else
		{	sAlertStr += ", your delivery phone number";	}
	}
	
	if(sAlertStr == '')
	{
		document.getElementById('first_name').value = ' ';
		document.getElementById('last_name').value = document.getElementById('t_name').value;
		document.getElementById('address1').value = document.getElementById('t_address1').value;
		document.getElementById('address2').value = document.getElementById('t_address2').value;
		document.getElementById('city').value = document.getElementById('t_city').value;
		document.getElementById('state').value = document.getElementById('t_state').value;
		document.getElementById('zip').value = document.getElementById('t_zip').value;
		document.getElementById('night_phone_a').value = document.getElementById('t_night_phone_a').value;
		document.getElementById('night_phone_b').value = document.getElementById('t_night_phone_b').value;
	    StoreDetails();
	}
	else
	{
		window.alert(sAlertStr);
		return false;
	}
}
function AutofillDeliveryAddress()
{
	document.getElementById('d_name').value = document.getElementById('t_name').value;
	document.getElementById('d_address1').value = document.getElementById('t_address1').value;
	document.getElementById('d_address2').value = document.getElementById('t_address2').value;
	document.getElementById('d_city').value = document.getElementById('t_city').value;
	document.getElementById('d_state').value = document.getElementById('t_state').value;
	document.getElementById('d_zip').value = document.getElementById('t_zip').value;
	document.getElementById('d_night_phone_a').value = document.getElementById('t_night_phone_a').value;
	document.getElementById('d_night_phone_b').value = document.getElementById('t_night_phone_b').value;
}
function StoreDetails()
{
	document.getElementById("hCartContents").value = '';

	document.forms[0].action = 'storeDetails.aspx';
	document.forms[0].target = '_self'
	document.forms[0].submit();

}
function ToggleEdit(URL,BtnClicked)
{
   var elements = document.getElementsByTagName("*");
   for(var i=0; i<elements.length;i++){
       var ControlId = elements[i].id;
       if(ControlId.indexOf("BtnClicked") != -1)
       {
            document.getElementById(ControlId).value = BtnClicked.id;
       }
   } 
    document.forms[0].action = URL;
	document.forms[0].submit();
    return false;
}
