function formatPrice(nStr) {
	nStr = nStr.toString();
	parts = nStr.split('.');

	p1 = parts[0];
	p2 = parts[1] || '' ;
        p3 = parts[3] || '' ;
	
	if(p1.length > 3) {
		p1 = p1.substr(0, p1.length-3) + '.' + p1.substr(p1.length-3,3);
	}
	
	if(p2 == '0' || p2 == '00' || p2 == '') {
		return p1 + ',-';
	} else {
            if (p3=='') p3='0';
		return p1 + ',' + p2+p3;
	}
}


function moveNumber(v) {
	if(v == true) {
		$('#moveNumber1').hide();
		$('#moveNumber2').hide();
		$('#moveNumber3').hide();
	} else {
		$('#moveNumber1').show();
		$('#moveNumber2').show();
		$('#moveNumber3').show();
	}
}

function showImage(sel, image)
{
	var tds = document.getElementById('productShow').getElementsByTagName("div");

	for(i=0;i<tds.length;i++)
	{
		if(tds[i].className == 'selected')
		{
			tds[i].className = '';
		}
	}

	sel.className = 'selected';

	document.getElementById('displayImage').src = image;
	
	return false;
}


function generate(e, t, c)
{
	var posx = 0;
	var posy = 0;
	if (!e) var e = window.event;
        
	if (e.pageX || e.pageY) 	{
		posx = e.pageX;
		posy = e.pageY;
	}
	else if (e.clientX || e.clientY) 	{
		posx = e.clientX + document.body.scrollLeft
			+ document.documentElement.scrollLeft;
		posy = e.clientY + document.body.scrollTop
			+ document.documentElement.scrollTop;
	}

	// CHANGE THE TITLE
		document.getElementById('infoBoxTitle').innerHTML = t;

	// CHANGE THE CONTENTS
		document.getElementById('infoBoxContents').innerHTML = c;

	// Move the box to the cords
		//posty -= document.getElementById('infoBox').height;
		

	// SHOW THE BOX
		document.getElementById('infoBox').style.display = '';
		
		boxHeight =  document.getElementById('infoBox').clientHeight;

                var scrollTop = document.body.scrollTop;
                if (scrollTop == 0) {
                    if (window.pageYOffset) {
                        scrollTop = window.pageYOffset;
                    } else {
                        scrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
                    }
                }

                if(boxHeight + posy - scrollTop > document.documentElement.clientHeight)
                       posy -= boxHeight;
		document.getElementById('infoBox').style.top = posy+10+'px';
		document.getElementById('infoBox').style.left = posx+10+'px';
		
}

function generate2(e, t, c)
{
	var posx = 0;
	var posy = 0;
	if (!e) var e = window.event;
	if (e.pageX || e.pageY) 	{
		posx = e.pageX;
		posy = e.pageY;
	}
	else if (e.clientX || e.clientY) 	{
		posx = e.clientX + document.body.scrollLeft
			+ document.documentElement.scrollLeft;
		posy = e.clientY + document.body.scrollTop
			+ document.documentElement.scrollTop;
	}

	// CHANGE THE TITLE
		document.getElementById('infoBoxTitle').innerHTML = t;

	// CHANGE THE CONTENTS
		document.getElementById('infoBoxContents').innerHTML = c;

	// Move the box to the cords
		document.getElementById('infoBox').style.top = posy-300+'px';
		document.getElementById('infoBox').style.left = posx-300+'px';

	// SHOW THE BOX
		document.getElementById('infoBox').style.display = '';
}

function showCvcImage(e)
{
	var posx = 0;
	var posy = 0;
	if (!e) var e = window.event;
	if (e.pageX || e.pageY) 	{
		posx = e.pageX;
		posy = e.pageY;
	}
	else if (e.clientX || e.clientY) 	{
		posx = e.clientX + document.body.scrollLeft
			+ document.documentElement.scrollLeft;
		posy = e.clientY + document.body.scrollTop
			+ document.documentElement.scrollTop;
	}

	// Move the box to the cords
		document.getElementById('cvcImage').style.top = posy-70+'px';
		document.getElementById('cvcImage').style.left = posx+80+'px';

	// SHOW THE BOXorderf
		document.getElementById('cvcImage').style.display = '';
}

function showSubscriptionImage(e, imageName, imgWid, imgHei)
{
	if(imageName)
		document.getElementById('subscriptionImage').src = imageName;

        if(jQuery.browser.msie == true && parseInt(jQuery.browser.version) == 6) {

            document.getElementById('subscriptionImage').width = imgWid*2 ;
            document.getElementById('subscriptionImage').height = imgHei ;
        }
        imgHei += 20;
	if(!imgWid)
		imgWid = 300;
	if(!imgHei)
		imgHei = 400;

	var posx = 0;
	var posy = 0;
	if (!e) var e = window.event;
	if (e.pageX || e.pageY) 	{
		posx = e.pageX;
		posy = e.pageY;
	}
	else if (e.clientX || e.clientY) 	{
		posx = e.clientX + document.body.scrollLeft
			+ document.documentElement.scrollLeft;
		posy = e.clientY + document.body.scrollTop
			+ document.documentElement.scrollTop;
	}

	// Move the box to the cords
		document.getElementById('subscriptionImage').style.top = posy-imgHei+'px';
		document.getElementById('subscriptionImage').style.left = posx-imgWid+'px';

	var selects = document.getElementsByTagName('SELECT');
	for(var i = 0; i < selects.length; i++)
	{
		selects[i].style.display = 'none';
	}

	// SHOW THE BOX
		document.getElementById('subscriptionImage').style.display = '';
}
function hideSubscriptionImage()
{
	var selects = document.getElementsByTagName('SELECT');
	for(var i = 0; i < selects.length; i++)
	{
		selects[i].style.display = '';
	}
	document.getElementById('subscriptionImage').style.display = 'none';
}

function mindstePrisBox(e, id)
{
	if (id == null) {
        id = 'mindstePrisBox';
    }

    var posx = 0;
	var posy = 0;
	if (!e) var e = window.event;
	if (e.pageX || e.pageY) 	{
		posx = e.pageX;
		posy = e.pageY;
	}
	else if (e.clientX || e.clientY) 	{
		posx = e.clientX + document.body.scrollLeft
			+ document.documentElement.scrollLeft;
		posy = e.clientY + document.body.scrollTop
			+ document.documentElement.scrollTop;
	}

	// Move the box to the cords
	var box = $('#'+id);
        if(box)
        {
		box.css('top',posy+5+'px');
		box.css('left',posx-420+'px');
        //alert(document.getElementById('mindstePrisBox').style.left);
	// SHOW THE BOX
		box.show();
        }
}

function showSubscriptionImage2(e)
{
	var posx = 0;
	var posy = 0;
	if (!e) var e = window.event;
	if (e.pageX || e.pageY) 	{
		posx = e.pageX;
		posy = e.pageY;
	}
	else if (e.clientX || e.clientY) 	{
		posx = e.clientX + document.body.scrollLeft
			+ document.documentElement.scrollLeft;
		posy = e.clientY + document.body.scrollTop
			+ document.documentElement.scrollTop;
	}

	// Move the box to the cords
		document.getElementById('subscriptionImage').style.top = posy-130+'px';
		document.getElementById('subscriptionImage').style.left = posx-150+'px';

	// SHOW THE BOX
		document.getElementById('subscriptionImage').style.display = '';
}



function hideBox()
{
	$('#infoBox').hide();
}


// DYNAMIC
function hideGrayBoxes(n,cls)
{
	var abons = document.getElementById(n);
	if(abons)
	{
		abons = abons.getElementsByTagName("div");
	}
	else
	{
		abons = new Array();
	}

	for(i=0;i<abons.length;i++)
	{
		//document.getElementById("outputLayer").innerHTML += abons[i].style.display + "<br>";
		if(abons[i].className == cls)
		{
			abons[i].style.display='none';
		}
	}

	var inputs = document.getElementById(n);
	if(inputs)
		inputs = getElementsByTagName("input");
	else
		inputs = new Array();

	for(i=0;i<inputs.length;i++)
	{
		if(inputs[i].type == "radio")
		{
			inputs[i].disabled = true;
		}
		if(inputs[i].type == "checkbox")
		{
			inputs[i].disabled = true;
		}
	}
}

function showGrayBox(n,cls,id)
{
	hideGrayBoxes(n,cls);
	$("#container"+id).show();

	var inputs = document.getElementById("container"+id);
	if(inputs)
		inputs = inputs.getElementsByTagName("input");
	else
		inputs = new Array();

	for(i=0;i<inputs.length;i++)
	{
		if(inputs[i].type == "radio")
		{
			inputs[i].disabled = false;
		}
		if(inputs[i].type == "checkbox")
		{
			inputs[i].disabled = false;
		}
	}
}

function changeMindstePrisBox(v) {
	if(v == "1")
		$('#mindstePrisBoxTaletid').show();
	else
		$('#mindstePrisBoxTaletid').hide();
}

function hideTilvalg()
{
	var inputs = document.getElementById('shopingCartOutput2');
	if(inputs)
		inputs = inputs.getElementsByTagName("tr");
	else
		inputs = new Array();

	for(i=0;i<inputs.length;i++)
	{
		 if(inputs[i].className == 'tilvalgcartentry')
	   	{
	    	deleteCartRow(inputs[i].id);
	   	}

	}

   var inputs = document.getElementById('shopingCartOutput2');
	if(inputs)
		inputs = inputs.getElementsByTagName("tr");
	else
		inputs = new Array();

	for(i=0;i<inputs.length;i++)
	{
		 if(inputs[i].className == 'tilvalgcartentry')
	   	{
	    	deleteCartRow(inputs[i].id);
	   	}

	}

	var inputs = document.getElementById('abonnementDetails').getElementsByTagName("input");
	if(inputs)
		inputs = inputs.getElementsByTagName("input");
	else
		inputs = new Array();

	for(i=0;i<inputs.length;i++)
	{

		if(inputs[i].type == "checkbox")
		{
			inputs[i].checked = false;
		}


	}
	var trs = document.getElementById('abonnementDetails');
	if(trs)
		trs = inputs.getElementsByTagName("tr");
	else
		trs = new Array();

     for(i=0;i<trs.length;i++)
	{
		if (trs[i].className.indexOf('childrenSection') != -1)
		{
			trs[i].style.display='none';
		}

	}


}
// END OF DYNAMIC


//Number checking start
function getkey(e) {
	if (window.event)
		return window.event.keyCode;
	else if (e)
		return e.which;
	else
		return null;
}

function badchars(e, bads) {
	var key, keychar;
	key = getkey(e);
	if (key == null) return true;
	// get character
	keychar = String.fromCharCode(key);
	keychar = keychar.toLowerCase();
	bads = bads.toLowerCase();
	// check goodkeys
	if (bads.indexOf(keychar) != -1)
		return false;
	// control keys
	if ( key==null || key==0 || key==8 || key==9 || key==13 || key==27 )
		return true;
	// else return false
	return true;
}

function goodchars(e, goods) {
	var key, keychar;
	key = getkey(e);
	if (key == null) return true;
	// get character
	keychar = String.fromCharCode(key);
	keychar = keychar.toLowerCase();
	goods = goods.toLowerCase();
	// check goodkeys
	if (goods.indexOf(keychar) != -1)
		return true;
	// control keys
	if ( key==null || key==0 || key==8 || key==9 || key==13 || key==27 )
		return true;
	// else return false
	return false;
}
//Number checking End

// show the banker div
function hidebanker(id) {
	$("#" + id).hide();
}

// Functions in page 1. Calculating card, showing and hiding,
// checking and unchecking radio buttons and check boxes



// Add or substract price
function modifyElementPrice(element,amount) {
	$("#" + element).html( parseInt( $("#" + element).html() ) + parseInt(amount) );
	recalculateCard();
}

// Directly set price, text
// element2 - it could be a second element that has to be set too
function setElementPrice(element,amount) {
	if(	document.getElementById(element))
	{
		document.getElementById(element).innerHTML = 'DKK&nbsp;'+formatPrice(parseInt(amount));
	}
	if(	document.getElementById(element+'2'))
	{
		document.getElementById(element+'2').innerHTML = 'DKK&nbsp;'+formatPrice(parseInt(amount));
	}
	if(	document.getElementById(element+'3'))
	{
		document.getElementById(element+'3').innerHTML = parseInt(amount);
	}

	if(	document.getElementById(element+'6'))
	{
		document.getElementById(element+'6').innerHTML = 'DKK&nbsp;'+formatPrice((parseInt(amount)*6));
	}

	if(document.getElementById('abonhide'))
	{
		document.getElementById('abonhide').style.display='inline';
	}
	recalculateCard();
}

function setElementText(element,text)
{
	if(!document.getElementById(element)) return;
	
	document.getElementById(element).innerHTML = text;
	if(	document.getElementById(element+'2'))
	{
		document.getElementById(element+'2').innerHTML = text;
	}
}

// Recalculate total price
function recalculateCard()
{
	// What is current accessories cost
	// based on invisible span
	var accessoriesPrice = parseInt(document.getElementById('hAcc').innerHTML);
	// Plan price OR hardware price
	//var v1= document.getElementById('abonnementPrice').innerHTML.substr(4,20);
	//alert(v1);
	// substr(4,20) to truncate 'DKK' at beginning
	var planPrice = parseInt(document.getElementById('abonnementPrice').innerHTML.substr(9,20).replace(".", ""));
	var signupFee = parseInt(document.getElementById('signupFee').innerHTML.substr(9,20));
	var shippingFee = parseInt(document.getElementById('shippingFee').innerHTML.substr(9,20));

	var totalPrice = accessoriesPrice + planPrice + signupFee + shippingFee;

	document.getElementById("cardTotalPrice").innerHTML = 'DKK&nbsp;'+formatPrice(totalPrice.toString());

}
// Select abonnement
function setAbonnement() {
	if (document.getElementById("subscr")) {
		document.getElementById("subscr").checked = true;
	}

	/*
	var ad  = document.getElementById("abonnementDetails");
	ad.style.display = 'block';
	var ad  = document.getElementById("minst");
	ad.style.display = 'block';
	*/

}

function abonnementSelected()
{
	var ad  = document.getElementById("abonnementDetails");
	ad.style.display = 'block';
	var ad  = document.getElementById("minst");
	ad.style.display = 'block';

	var fs = document.getElementById("firstSubscription");
	fs.checked = true;
	fs.onclick();

}

function udenAbonnementSelected()
{
	var radios = document.getElementById("subscriptionsTr").getElementsByTagName("input");

	for(i=0;i<radios.length;i++)
	{
		radios[i].checked = false;
	}

	var ad  = document.getElementById("abonnementDetails");
	ad.style.display = 'none';
	var ad  = document.getElementById("minst");
	ad.style.display = 'none';

}

// Add or remove check box element
function modifyCartRow(id, content,content2, price)
{
	// content, content2 - contents of the 2 td's
	if(!document.getElementById(id))
	{
			var p = document.createElement("tr");

			p.id = id;
			// Create and append 2 td's
			var d = document.createElement("td");
			var d2 = document.createElement("td");

			d.innerHTML=content;
			d2.innerHTML =content2;
			d.width='65%';
			d2.width='35%';
			p.appendChild(d);
			p.appendChild(d2);


		document.getElementById("shopingCartOutput").appendChild(p);
		// hAcc - hidden span to hold total price of all accessories
		modifyElementPrice('hAcc',price);
		recalculateCard();
	}
	else
	{
		document.getElementById(id).parentNode.removeChild(document.getElementById(id));

		modifyElementPrice('hAcc','-'+price);
		recalculateCard();
	}
}

// Add or remove check box element
// for lower box - for tilvalg only
function modifyCartRow2(id, content,content2, price)
{
	// content, content2 - contents of the 2 td's
	if(!document.getElementById(id))
	{
			var p = document.createElement("tr");

			p.id = id;
			p.className='tilvalgcartentry';
			// Create and append 2 td's
			var d = document.createElement("td");
			var d2 = document.createElement("td");

			d.innerHTML=content;
			d2.innerHTML =content2;
			d.width='65%';
			d2.width='35%';
			p.appendChild(d);
			p.appendChild(d2);


		document.getElementById("shopingCartOutput2").appendChild(p);
		// hAcc - hidden span to hold total price of all accessories
		modifyElementPrice('hAcc',price);
		recalculateCard();
	}
	else
	{
		document.getElementById(id).parentNode.removeChild(document.getElementById(id));

		modifyElementPrice('hAcc','-'+price);
		recalculateCard();
	}
}

// Add or remove check box element
// for lower box - for tilvalg only
function replaceCartRow(id, content,content2, price)
{
	// content, content2 - contents of the 2 td's
	if(!document.getElementById(id))
	{
			var p = document.createElement("tr");

			p.id = id;
			p.className='tilvalgcartentry';
			// Create and append 2 td's
			var d = document.createElement("td");
			d.id='chld'+id;
			var d2 = document.createElement("td");

			d.innerHTML=content;
			d2.innerHTML =content2;
			d.width='65%';
			d2.width='35%';
			p.appendChild(d);
			p.appendChild(d2);

		document.getElementById("shopingCartOutput2").appendChild(p);
		// hAcc - hidden span to hold total price of all accessories
		modifyElementPrice('hAcc',price);
		recalculateCard();
	}
	else
	{
		document.getElementById('chld'+id).innerHTML=content;

		modifyElementPrice('hAcc','-'+price);
		recalculateCard();
	}
}

function deleteCartRow(id) {
	if (document.getElementById(id)) {
		document.getElementById(id).parentNode.removeChild(document.getElementById(id));
	}
}
function toggleSection(sect,id,firstchild)
{

	var extrarows = document.getElementsByTagName("tr");

	for(i=0;i<extrarows.length;i++)
	{
		if(extrarows[i].className == sect)
		{
			var vis = extrarows[i];


			if (vis.style.display == 'none')
			{
				vis.style.display = '';
				replaceCartRow(id,firstchild,'',0);
			} else
			{
				vis.style.display = 'none';
				deleteCartRow(id);
			}
		}

	}
}


// Various page functions

// CPR - select next field when first is filled
// to be called on onkeyup.
function nextField(this_inp,next_inp,nChars) {
	var element1=document.getElementById(this_inp);
	var element2=document.getElementById(next_inp);
	
	if (element1.value.length == nChars) {
		element2.focus();
	}
}

// toggle visibility of 2 elements
function toggleSaldoControl() {
	var vis = $("#scontrol");
	var vis2 = $("#scontrol2");

	if (vis.css('display') == 'none') {
		vis.show();
		vis2.show();
	} else {
		vis.hide();
		vis2.hide();
	}
}


function newWindow(mypage,myname,w,h,features) {
	var winl = (screen.width-w)/2;
	var wint = (screen.height-h)/2;
	if (winl < 0) winl = 0;
	if (wint < 0) wint = 0;
	var settings = 'height=' + h + ',';
	settings += 'width=' + w + ',';
	settings += 'top=' + wint + ',';
	settings += 'left=' + winl + ',';
	settings += features;
	win = window.open(mypage,myname,settings);
	win.window.focus();
}
// functions for items in the new cart
function showNN() {
	$('#newnumberrow').show();
}

function hideNN() {
	$('#newnumberrow').hide();
}

function showFN() {
	$('#movenumberrow').show();
}

function hideFN() {
	$('#movenumberrow').hide();
}

function toggleSN() {
	nn = $('#secretnumberrow');
	if(nn.css('display') == '') {
		nn.hide()
	} else {
		nn.show()
	}
}

function toggleSL() {
	nn = $('#saldolimitrow');
	if(nn.css('display') == ''){
		nn.hide()
	} else {
		nn.show()
	}
}

function toggleON() {
	nn = $('#omitnumberrow');
	if(nn.css('display') == ''){
		nn.hide()
	} else {
		nn.show()
	}
}

function setSL(amount) {
	$('#scc').html( 'DKK&nbsp;'+formatPrice(parseInt(amount)) );
}

function changePS(text,text2,text3) {
	$('#ps').html( text );
	$('#giroo').html( text2 );
	$('#giroo2').html( text3 );
}

function switchTypes(tempValue)
{
/*	document.getElementById('outputLayer').innerHTML += tempValue + "<br />";

	if(tempValue == 2)
	{
		document.getElementById('callmeTable').style.display = "none";
		document.getElementById('callmeDescr').style.display = "none";
		document.getElementById('surfncallTable').style.display = "block";
		document.getElementById('surfncallDescr').style.display = "inline";
	}
	else
	{
		document.getElementById('callmeTable').style.display = "block";
		document.getElementById('callmeDescr').style.display = "inline";
		document.getElementById('surfncallTable').style.display = "none";
		document.getElementById('surfncallDescr').style.display = "none";
	}/**/
}

    function hideAll(i) {
        $.each($(".tabs"), function(){
            if($(this).attr('id') != 'tab'+i)
                $('#'+$(this).attr('id')).hide();
        });
    }
	
    function showTab(i) {
        hideAll(i);
        $('#tab'+i).show();
    }

	/**
	 * This function handle tabs on product page
	 */
	function productTabs() {
		  var links = $(".tab li a");
		  var blocks = $(".tabshow01");
		  $.each( links, function() {
		  	$(this).bind('click', function() {
				$.each(links, function(){
					$(this).removeClass('active');
				})
				$(this).addClass('active');
				
				$.each( blocks, function() {
					$(this).hide();
				})
				
				$('#tab' + $(this).attr('id').substr(4)).show();
				
				return false;	
			})
		  });
	}
	

	
	function expandFilter() {
        if ($('.filter-row-to-hide').css('display') == 'none') {
			$('.bbset').css( {'border-bottom-style': 'solid', 
							  'border-bottom-width': '1px', 
							  'border-bottom-color': '#DCDAD8'} );
            $('.filter-row-to-hide').show();
            $('.expand-link-1').hide();
        } else {
            $('.bbset').css('border-bottom-style', 'none');
            $('.filter-row-to-hide').hide();
            $('.expand-link-1').show();
        }
    }
	


	
	

String.prototype.trim = function () {
    return this.replace(/^\s*/, "").replace(/\s*$/, "");
}

function newWindow(mypage,myname,w,h) {
	var winl = (screen.width-w)/2;
	var wint = (screen.height-h)/2;
	if (winl < 0) winl = 0;
	if (wint < 0) wint = 0;
	var settings = 'height=' + h + ',';
	settings += 'width=' + w + ',';
	settings += 'top=' + wint + ',';
	settings += 'left=' + winl + ',';
	settings += features;
	win = window.open(mypage,myname,settings);
	win.window.focus();
}


    function printWindow() {
        window.print();
    }

function searchFieldDefaultValue()
{
    $('.fld').focus(function () {
        if ($(this).attr('rel') == 'default') {
            $(this).val('');
            $(this).attr('rel', '');
        }
    });
}

function variationColorChange(element)
{
    if ($('#product-' + $(element).attr('rel')).attr('class') != 'proList') {
        $('.focused-price-img-' + $(element).attr('rel')).attr('src', $('input[name=focused-price-img-' + $(element).val() + ']').val());
        $('.focused-muse-' + $(element).attr('rel')).attr('src', $('input[name=focused-muse-' + $(element).val() + ']').val());
        $('.variation-img-' + $(element).attr('rel')).attr('src', $('input[name=variation-img-' + $(element).val() + ']').val());
        $('.variation-img-' + $(element).attr('rel')).attr('alt', $('input[name=variation-name-' + $(element).val() + ']').val());
        $('.variation-img-' + $(element).attr('rel')).attr('title', $('input[name=variation-name-' + $(element).val() + ']').val());
        $('.focused-link-' + $(element).attr('rel')).attr('href', $('input[name=variation-url-' + $(element).val() + ']').val());
    } else {
        $('.variation-img-' + $(element).attr('rel')).attr('src', $('input[name=variation-img-' + $(element).val() + ']').val());
        $('.variation-img-' + $(element).attr('rel')).attr('alt', $('input[name=variation-name-' + $(element).val() + ']').val());
        $('.variation-img-' + $(element).attr('rel')).attr('title', $('input[name=variation-name-' + $(element).val() + ']').val());
        $('.variation-img-link-' + $(element).attr('rel')).attr('href', $('input[name=variation-url-' + $(element).val() + ']').val());
        $('.variation-name-link-' + $(element).attr('rel')).attr('href', $('input[name=variation-url-' + $(element).val() + ']').val());
        $('.variation-more-' + $(element).attr('rel')).attr('href', $('input[name=variation-url-' + $(element).val() + ']').val());
        $('.variation-spar-' + $(element).attr('rel')).attr('src', $('input[name=variation-spar-' + $(element).val() + ']').val());
        $('.variation-price-img-' + $(element).attr('rel')).attr('src', $('input[name=variation-price-img-' + $(element).val() + ']').val());
        $('.variation-muse-' + $(element).attr('rel')).text($('input[name=variation-muse-' + $(element).val() + ']').val());
    }

}

function setCookie(c_name,value,expiredays)
{
    var exdate=new Date();
    exdate.setDate(exdate.getDate()+expiredays);
    document.cookie=c_name+ "=" +escape(value)+
        ((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function getCookie(c_name)
{
    if (document.cookie.length>0)
    {
    c_start=document.cookie.indexOf(c_name + "=");
      if (c_start!=-1)
        {
        c_start=c_start + c_name.length+1;
        c_end=document.cookie.indexOf(";",c_start);
        if (c_end==-1) c_end=document.cookie.length;
        return unescape(document.cookie.substring(c_start,c_end));
        }
      }
    return "";

}
function unescape2(v)
{
	return unescape(v.replace(/\+/g, " "));
}

