hej..
jeg har dette meget lange javascript som laver en cookie når man vælger nogle bestemte ting på min side.
document.getElementsByClassName = function(cl)
{
var retnode = [];
var myclass = new RegExp('\\b'+cl+'\\b');
var elem = this.getElementsByTagName('*');
for (var i = 0; i < elem.length; i++)
{
var classes = elem[i].className;
if (myclass.test(classes)) retnode.push(elem[i]);
}
return retnode;
}
function BuyProduct(thisform, MinBuyAmount, MaxBuyAmount,BundleMinBuy)
{
switch($('GroupID').innerHTML)
{
case '100':
case '101':
case '200':
case '207':
if($('variant1').selectedIndex == 0 || $('variant2').selectedIndex == 0)
{
alert(ErrorText);
return false;
}
break;
default:
if($('variant1').selectedIndex == 0)
{
alert(ErrorText);
return false;
}
break;
}
if (BundleMinBuy=='True')
{
// MinBuyAmount in bundle mode
if (parseInt(thisform.AMOUNT.value) % parseInt(MinBuyAmount) > 0)
{
thisform.AMOUNT.value = MinBuyAmount;
alert(MinBuyMsg + '( '+MinBuyAmount+' )')
return (false);
}
if (isNaN (parseInt(thisform.AMOUNT.value)))
{
thisform.AMOUNT.value = MinBuyAmount;
alert(MinBuyMsg + '( '+MinBuyAmount+' )')
return (false);
}
}
else
{
// MinBuyAmount in normal mode
if (parseInt(thisform.AMOUNT.value) < parseInt(MinBuyAmount))
{
thisform.AMOUNT.value = MinBuyAmount;
alert(MinBuyMsg + '( '+MinBuyAmount+' )')
return (false);
}
if (isNaN (parseInt(thisform.AMOUNT.value)))
{
thisform.AMOUNT.value = MinBuyAmount;
alert(MinBuyMsg + '( '+MinBuyAmount+' )')
return (false);
}
}
if (parseInt(MaxBuyAmount) > 0 )
{
if (parseInt(thisform.AMOUNT.value) > parseInt(MaxBuyAmount))
{
thisform.AMOUNT.value = MinBuyAmount;
alert(MaxBuyMsg + ' ( '+MaxBuyAmount+' )')
return (false);
}
}
if (!CanBuy) alert(SelectVarMsg);
if(CanBuy == true) CookieArray();
return (CanBuy);
}
function createCookie(name,value,days)
{
var expires;
if (days)
{
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
expires = "; expires="+date.toGMTString();
}
else expires = "";
document.cookie = name+"="+value+expires+"; path=/";
document.cookie += ";domain=.annespang.com";
}
function readCookie(name)
{
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++)
{
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}
function eraseCookie(name)
{
createCookie(name,"",-1000);
}
function $(elementName)
{
if(elementName)
{
return document.getElementById(elementName);
}
return null;
}
// Count element's provided with elementid
function elementsCount(elementId, startValue)
{
var getAllElements = true;
while(getAllElements)
{
if($(elementId+startValue) == null)
{
getAllElements = false;
startValue--;
}
else startValue++;
}
if(startValue < 0) startValue=0;
return startValue;
}
function CookieArray()
{
// Displays error if one or more fields are missing.
var elementsToCheck = elementsCount('variant', 1);
for(var i=1;i<=elementsToCheck;i++)
{
if(!$('variant'+i).value)
{
//alert('Alle felter skal udfyldes.');
//return false;
}
}
var groupid = $('GroupID').innerHTML;
if(groupid != null)
{
var addgroup = true;
var cookievalues = readCookie('TabGroupsCookie');
var newarray = new Array();
if(cookievalues != null)
{
cookievalues = readCookie('TabGroupsCookie').split(',');
for(var i=0;i<cookievalues.length;i++)
{
if(groupid == cookievalues[i]) addgroup = false;
}
if(addgroup)
{
for( var i=0; i<=cookievalues.length; i++)
{
( i == cookievalues.length ? newarray[i] = groupid : newarray[i] = cookievalues[i] );
}
eraseCookie('TabGroupsCookie');
createCookie('TabGroupsCookie', newarray, 86400);
}
else newarray=cookievalues;
}
else createCookie('TabGroupsCookie', groupid, 86400);
}
}
var y = new Array();
var y = document.getElementsByClassName('VariantGroup');
function CustomizeProd(which,init)
{
if(typeof(which) == 'undefined') which = 1;
if(typeof(init) == 'undefined') init = 0;
if(init == 0)
{
switch(document.getElementById('GroupID').innerHTML)
{
case '100':
case '101':
case '200':
case '207':
if($('variant1').selectedIndex == 0 || $('variant2').selectedIndex == 0)
{
alert(ErrorText2);
return;
}
break;
default:
if($('variant1').selectedIndex == 0)
{
alert(ErrorText2);
return;
}
break;
}
}
if(which == 0)
{
show0 = 'none';
show1 = '';
}
else
{
show0 = '';
show1 = 'none';
}
//Sidevisning 1
for(t1 = 0; t1 < p1tag.length; t1++) if($(p1tag[t1])) $(p1tag[t1]).style.display = show0;
//Sidevisning 2
for(t2 = 0; t2 < p2tag.length; t2++) if($(p2tag[t2])) $(p2tag[t2]).style.display = show1;
switch($('GroupID').innerHTML)
{
case '100':
case '101':
case '200':
case '207':
if($('variant1').selectedIndex != 0) $('Model1_Text').innerHTML = $('variant1').options[$('variant1').selectedIndex].text;
if($('variant2').selectedIndex != 0) $('Model2_Text').innerHTML = $('variant2').options[$('variant2').selectedIndex].text;
switch(which)
{
case 0:
for(var i = 3; i < y.length; i++) y[i].style.display = '';
y[1].style.display = 'none';
y[2].style.display = 'none';
break;
case 1:
y[1].style.display = '';
y[2].style.display = '';
for(var i = 3; i < y.length; i++) y[i].style.display = 'none';
break;
}
break;
default:
if($('variant1').selectedIndex != 0) $('Model1_Text').innerHTML = $('variant1').options[$('variant1').selectedIndex].text;
switch(which)
{
case 0:
for(var i = 0; i < 2; i++) y[i].style.display = 'none';
for(var i = 2; i < y.length; i++) y[i].style.display = '';
break;
case 1:
y[1].style.display = '';
for(var i = 2; i < y.length; i++) y[i].style.display = 'none';
break;
}
break;
}
}
function oc(a)
{
var o = {};
for(var i=0;i<a.length;i++)
{
o[a[i]]='';
}
return o;
}
function submitform()
{
var gender;
var gendererror = 'Du kan kun handle til én person ad gangen, da bestillingen er knyttet til personlige mål. Hvis du ønsker at handle til flere forskellige personer, kan du - uden at det koster dig ekstra med hensyn til ekspedition, betaling, fragt, etc. - handle og betale ad flere omgange under forskellige personlige profiler. Bemærk blot, at de enkelte personlige profiler skal være knyttet til hver sin e-mailadresse; du kan altså IKKE oprette flere personlige profiler på baggrund af den samme e-mailadresse.';
var cookiearr = readCookie('TabGroupsCookie');
if(cookiearr) // if no elements are present in cookie "array", continue submit function
{
groups = cookiearr.split(',');
if(groups[0] != null) // make sure we have the first element in array to check against.
{
( groups[0] in oc(womensgroups) ? gender = 'women' : gender = 'men' );
if(gender == 'men') if($('GroupID').innerHTML in oc(womensgroups))
{
alert(gendererror);
return;
}
if(gender == 'women') if($('GroupID').innerHTML in oc(mensgroups))
{
alert(gendererror);
return;
}
}
}
var submform = true;
switch($('GroupID').innerHTML)
{
case '100':
case '101':
case '200':
case '207':
if($('variant1').selectedIndex == 0 || $('variant2').selectedIndex == 0)
{
alert(ErrorText);
submform = false;
}
break;
default:
if($('variant1').selectedIndex == 0)
{
alert(ErrorText);
submform = false;
}
break;
}
if(submform == true)
{
CookieArray();
//if(BuyProduct(document.forms[0],'1','0','False'))
document.forms[0].submit();
}
}
createCookie('init','1',86400);
var basketcontent = new Array();
basketcontent = document.getElementsByClassName('Amount_Basket');
if(basketcontent[0].innerHTML == '0,00 DKK') eraseCookie('TabGroupsCookie');
if(basketcontent[0].innerHTML == '0,00 EUR') eraseCookie('TabGroupsCookie');
if(basketcontent[0].innerHTML == '0,00 USD') eraseCookie('TabGroupsCookie');
if(basketcontent[0].innerHTML == '0,00 DKK') eraseCookie('TabGroupsCookie');
if(basketcontent[0].innerHTML == '0,00 EUR') eraseCookie('TabGroupsCookie');
if(basketcontent[0].innerHTML == '0,00 USD') eraseCookie('TabGroupsCookie');
if($('GroupID')) CustomizeProd(1,1);
det jeg godt vil nu er at hvis cookien ikke eksisterer når man går ind på en bestem side så bliver man sendt til en side og hvis den eksisterer bliver man sendt til en anden side..
kan dette lade sig gøre og hvordan tjekker jeg om min cookie eksisterer?