function showPaperCard()
{
    showNoCards();
    document.getElementById("_addressDetailsPart").style.display = "block";
    document.getElementById("_cardDesign_Part").style.display = "block";
    if(document.getElementById("_discontinued_Cards") != null)
    {
        document.getElementById("_discontinued_Cards").style.display = "block";
    }    
    document.getElementById("_occasion_Part").style.display = "block";    
    document.getElementById("_extra_Part").style.display = "block";
}

function showECard()
{
    showNoCards();
    document.getElementById("_emailDetailsPart").style.display = "block";
}

function showBothCards()
{
    document.getElementById("_emailDetailsPart").style.display = "block";
    document.getElementById("_addressDetailsPart").style.display = "block";
    document.getElementById("_cardDesign_Part").style.display = "block";
    if(document.getElementById("_discontinued_Cards") != null)
    {
        document.getElementById("_discontinued_Cards").style.display = "block";
    }
    document.getElementById("_occasion_Part").style.display = "block";
    document.getElementById("_extra_Part").style.display = "block";
}

function showNoCards()
{
    document.getElementById("_emailDetailsPart").style.display = "none";
    document.getElementById("_addressDetailsPart").style.display = "none";
    document.getElementById("_cardDesign_Part").style.display = "none";
    if(document.getElementById("_discontinued_Cards") != null)
    {
        document.getElementById("_discontinued_Cards").style.display = "none";
    }
    document.getElementById("_occasion_Part").style.display = "none";
    document.getElementById("_extra_Part").style.display = "none";
}

function initialiseNewCardPreview(){
	var container = document.getElementById('newCardGallery');
	if(container){
		var classRegEx = new RegExp(/cardThumbnail/);
		var aDivs = container.getElementsByTagName('img');
		for (i=0; i<aDivs.length;i++){
			var nodeClass = (aDivs[i].getAttribute(classSpecifier)) ? aDivs[i].getAttribute(classSpecifier) : '';
			if(nodeClass.match(classRegEx)){
				aDivs[i].onclick = showNewCardPreview;
			}
		}
	}
}

function showNewCardPreview(e)
{
	if(document.getElementById('newCardPreview'))
	{
		var nodeObject = eventTrigger(e);
		var nodeClasses = nodeObject.getAttribute(classSpecifier);
		var previewRegEx = new RegExp(/design(\d{1,2})/);
		var matchCollection = previewRegEx.exec(nodeClasses);
		var previewID = parseInt(matchCollection[1],10);
		var altTag = nodeObject.getAttribute('alt');
		
		var radioObj = document.getElementById(radioButtons[previewID]);
		radioObj.checked = true;
		
		var previewNode = document.getElementById('newCardPreview');
		previewNode.innerHTML = "";//Clears the previous image html
		
		var previewImgNode = document.createElement('img');
		previewImgNode = previewNode.appendChild(previewImgNode);
		previewImgNode.setAttribute('src', imagesFull[previewID]);	
		previewImgNode.setAttribute('width', '  ');	
		previewImgNode.setAttribute('height', '362');	
		previewImgNode.setAttribute('alt',altTag);	
	}
	return false;
}

function showNewCardPreviewRadio(card, cardname)
{
    if(document.getElementById('newCardPreview'))
	{
		var previewNode = document.getElementById('newCardPreview');
		previewNode.innerHTML = "";//Clears the previous image html
			
		var previewImgNode = document.createElement('img');
		previewImgNode = previewNode.appendChild(previewImgNode);
		previewImgNode.setAttribute('src', '/img/cards/320x360/' + card + '.gif');	
		previewImgNode.setAttribute('width', '  ');	
		previewImgNode.setAttribute('height', '362');	
		previewImgNode.setAttribute('alt',cardname);
	}
}

/* used for textarea in shopping basket - add card page */ 
function initialiseNewCharCount(MaxNumberOfCharacters){
    
	if(document.getElementById('newAddCard')){
        
	    var charLimitNode = document.getElementById('newCharLimit');
	    charLimitNode.style.display = 'none';
	    var charCountNode = document.getElementById('newCharCount');
	    charCountNode.style.display = 'block';
        
        
		MaxCharCount = MaxNumberOfCharacters;
		var textareaNode = getTextArea('newAddCard','wordCount');
		
		currentCharCount = textareaNode.value.length;
		remainingCharacters = MaxCharCount - currentCharCount;
		displayNewCharCount(remainingCharacters);
		textareaNode.onkeyup = updateNewCharCount;
	}
}

function updateNewCharCount(){
	var textareaNode = getTextArea('newAddCard','wordCount');
	//StripLinebreaks(textareaNode);
	currentCharCount = textareaNode.value.length;	
	remainingCharacters = MaxCharCount - currentCharCount;
	if(remainingCharacters >= 0){
		prevText = textareaNode.value;
		displayNewCharCount(remainingCharacters);
	}else{
		textareaNode.value = prevText;
		$("#newCharCount").hide();
		$("#newCharCount").fadeIn("slow");
	}
}

function displayNewCharCount(numberOfCharacters){
	var charCountPara = document.getElementById('newCharCount');
	var spanCollection = charCountPara.getElementsByTagName('span');
	spanCollection[0].innerHTML = numberOfCharacters;
}

function initialiseHelp()
{
    var needHelpAnchors = document.getElementsByTagName("a");
    for(var i = 0; i < needHelpAnchors.length; i++) 
    {
        if(needHelpAnchors[i].getAttribute("href") != null)
        {
            if((needHelpAnchors[i].getAttribute("href").indexOf('&hlppg=')>=0) || (needHelpAnchors[i].getAttribute("href").indexOf('?hlppg=')>=0))
            {
                var needHelpAnchor = needHelpAnchors[i];
                needHelpAnchor.setAttribute("href", "javascript: getHTMLView('" + getUrlParam("hlppg", needHelpAnchor.getAttribute("href")) + "');");
            }
        }
    }
}

function getUrlParam(pramname, url)
{ 
    pramname = pramname.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]"); 
    var regexS = "[\\?&]"+pramname+"=([^&#]*)"; 
    var regex = new RegExp( regexS ); 
    var results = regex.exec( url ); 
    if( results == null )    return ""; 
    else return results[1];
}

//***************************************************ajax call for help page*************************************
var xhGHV
var helpdocVal
function getHTMLView(helpdoc)
{
    helpdocVal = helpdoc;
    xhGHV=GetXmlHttpObject();
    if (xhGHV==null)
    {
        alert ("Your browser does not support AJAX!");
        return;
    }     
    else
    {
        //document.getElementById("datacontainer").style.backgroundImage = "url('images/processing.gif')";
        var url="/basket/help/" + helpdoc + ".htm";
        xhGHV.onreadystatechange=showHTMLView;//showHTMLView is the next function called
        xhGHV.open("Get",url,true);
        xhGHV.send(null);               
    }
}

function showHTMLView()
{
    if (xhGHV.readyState==4)
    { 
        helpdocVal = "ctl00_ContentPlaceHolder_Help_" + helpdocVal;
        helpContainer = document.getElementById(helpdocVal);
        helpContainer.style.display = "block";
        helpContainer.innerHTML = "<p style=\"color: #0066cc;\" onclick=\"javascript: document.getElementById('" + helpContainer.getAttribute("id") + "').style.display = 'none';\">Close</p>";
        helpContainer.innerHTML += xhGHV.responseText;            
        helpContainer.innerHTML += "<p style=\"color: #0066cc;\" onclick=\"javascript: document.getElementById('" + helpContainer.getAttribute("id") + "').style.display = 'none';\">Close</p>";
    } 
}
//***************************************************ajax call for help page*************************************


//************************************************** XML HTTP Object ******************************************
var xmlHttp
function GetXmlHttpObject()
{
    var xmlHttp=null;
    try
    {
    // Firefox, Opera 8.0+, Safari
        xmlHttp=new XMLHttpRequest();
    }
    catch (e)
    {
    // Internet Explorer
        try
        {
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e)
        {
            xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
    return xmlHttp;
}
//************************************************** XML HTTP Object ******************************************

