forked from seanlebeck/site
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bookmarkAds.js
180 lines (167 loc) · 6.13 KB
/
bookmarkAds.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/*returnes the whole value of the specified cookie name
*/
function getTagValue(nametag){
var allcookies = document.cookie;
cookiearray = allcookies.split(';');
for(var i=0; i<cookiearray.length; i++){
name = cookiearray[i].split('=')[0];
value = cookiearray[i].split('=')[1];
name = name.split(' ').join('');//remove spaces
if(name == nametag){
return value;
}
}
return "";
}
/*returnes true if the adid is existing in the cookie
*/
function isExistAdCookie(nametag,valuetag,delimit)
{
var valueexists = false;
var value = getTagValue(nametag);
valuearray = value.split(delimit);
for(var i=0; i<valuearray.length; i++){
if(valuearray[i] == valuetag){
valueexists = true;
}
}
return valueexists;
}
/*when the mouse is moving over the ad
*/
function setHover(adid){
var idelement = 'bookmarkad'+adid;
var curState = document.getElementById(idelement).style.backgroundPosition;
if( curState == "" || curState == "0px 0px" || curState == "0px -20px" ){//not saved
document.getElementById(idelement).style.backgroundPosition = "0px -40px";
document.getElementById('bookmarkadspan'+adid).innerHTML = "Save";
}else if( curState == "0px -60px" ){//saved
document.getElementById(idelement).style.backgroundPosition = "0px -80px";
document.getElementById('bookmarkadspan'+adid).innerHTML = "Remove";
}
}
/*when the mouse is moving out of the ad
*/
function setHout(adid){
var idelement = 'bookmarkad'+adid;
var curState = document.getElementById(idelement).style.backgroundPosition;
if( curState == "0px -40px" || curState == "0px -20px" ){//not saved
document.getElementById(idelement).style.backgroundPosition = "0px 0px";
document.getElementById('bookmarkadspan'+adid).innerHTML = "";
}else if( curState == "0px -80px" || curState == "0px -60px" ){//saved
document.getElementById(idelement).style.backgroundPosition = "0px -60px";
document.getElementById('bookmarkadspan'+adid).innerHTML = "";
}
}
/*gets the value of the control - the adid
* idel - bookmarkad234 or bookmarkad1 ...
*/
function getValueFromId(idel){
var atpos = idel.length;
if (atpos > -1) {
var adid = idel.substring(10, atpos);
return adid;
}
return "";
}
/*On loading the page sets checked/unchecked the existing ads for latest.inc.php
*/
function setCheckedSelectedBookmarksLatestAds(){
if( typeof(document.frmLatestAds) != "undefined" ){
if( typeof(document.frmLatestAds.bookmarkad) != "undefined" ){
var adscount = document.frmLatestAds.bookmarkad.length;
for (i=0; i<adscount; i++){
if(isExistAdCookie('bookmark', getValueFromId(document.frmLatestAds.bookmarkad[i].id), '.')){
document.frmLatestAds.bookmarkad[i].checked = true;
document.getElementById(document.frmLatestAds.bookmarkad[i].id).style.backgroundPosition = "0px -60px";
}
}
}
}
totalAdCookies();
}
/*On loading the page sets checked/unchecked the existing ads for ads.php
*/
function setCheckedSelectedBookmarksAds(){
if(typeof(document.getElementsByName('bookmarkad')) != "undefined"){
var adscount = document.getElementsByName('bookmarkad').length;
for (i=0; i<adscount; i++){
if(isExistAdCookie('bookmark', getValueFromId(document.getElementsByName('bookmarkad')[i].id), '.')){
document.getElementsByName('bookmarkad')[i].checked = true;
document.getElementById(document.getElementsByName('bookmarkad')[i].id).style.backgroundPosition = "0px -60px";
}
}
}
totalAdCookies();
}
/*On loading the page sets checked/unchecked the existing ads for bookmarkAds.php
*/
function setCheckedSelectedBookmarksTotal(){
if( typeof(document.frmBookmarks.bookmarkad)=="undefined" || typeof(document.frmBookmarks.bookmarkad.length)=="undefined" ){//if there only one ad row => the value is undefined
if( typeof(document.frmBookmarks.bookmarkad)!="undefined" && typeof(document.frmBookmarks.bookmarkad.id) != "undefined" ){
if(isExistAdCookie('bookmark', getValueFromId(document.frmBookmarks.bookmarkad.id), '.')){
document.frmBookmarks.bookmarkad.checked = true;
document.getElementById(document.frmBookmarks.bookmarkad.id).style.backgroundPosition = "0px -60px";
}
}
totalAdCookies();
return;
}
var adscount = document.frmBookmarks.bookmarkad.length;
for (i=0; i<adscount; i++){
if(isExistAdCookie('bookmark', getValueFromId(document.frmBookmarks.bookmarkad[i].id), '.')){
document.frmBookmarks.bookmarkad[i].checked = true;
document.getElementById(document.frmBookmarks.bookmarkad[i].id).style.backgroundPosition = "0px -60px";
}
}
totalAdCookies();
}
/*Adds a new advert or removes it if it is already there
*/
function writeCookie(nametag,valuetag,delimit)
{
var valueexists = false;
var value = getTagValue(nametag);
wholenametag = "";
valuearray = value.split(delimit);
for(var j=0; j<valuearray.length; j++){
if(valuearray[j] == valuetag){
valueexists = true;
}else{
if(valuearray[j].length != 0){
wholenametag += valuearray[j] + delimit;
}
}
}
var ExpireDate = new Date ();
var expiredays = 1;
ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));
var idelement = 'bookmarkad' + valuetag;
if( valueexists ){
document.cookie=nametag + "=" + wholenametag.substring(0, (wholenametag.length-1))+delimit + "; expires="+ExpireDate.toGMTString() + "; path=/; ";
document.getElementById(idelement).style.backgroundPosition = "0px -20px";
document.getElementById('bookmarkadspan'+valuetag).innerHTML = "Removed";
}else{
document.cookie=nametag + "=" + wholenametag + valuetag +"; expires="+ExpireDate.toGMTString() + "; path=/; ";
document.getElementById(idelement).style.backgroundPosition = "0px -60px";
document.getElementById('bookmarkadspan'+valuetag).innerHTML = "Saved";
}
totalAdCookie(nametag,delimit);
}
function totalAdCookie(nametag,delimit){
var totalcookies = 0;
var value = getTagValue(nametag);
valuearray = value.split(delimit);
for(var i=0; i<valuearray.length; i++){
if(valuearray[i].length != 0){
totalcookies++;
}
}
document.getElementById('totalbookmarks').innerHTML = totalcookies;
//alert(document.cookie);
}
/*Counts total ads for all the ads
*/
function totalAdCookies(){
totalAdCookie('bookmark','.');
}