var myIP = '', ip = '', countrycode = '',countryname = '', box, locale = '', setviacookies = false, pagelang = '',pagename=''; var GBCountry = new RegExp("GB|IM|UK"); var MINTALLY = 999; var MINTALLYTEXT = 'us'; var foeidefaultwebsite = 'http://www.foei.org'; var xmlReqs = new Array(); xmlReqs[0] = "getfoeidetails"; xmlReqs[1] = "ip2c/get.php"; xmlReqs[2] = "getmyip"; xmlReqs[3] = "getcopsigners"; var langMap = new Array(); langMap["ENG"] = "en"; langMap["ESN"] = "es"; langMap["FRA"] = "fr"; langMap["IND"] = "id"; langMap["DAN"] = "da"; langMap["DEU"] = "de"; var webMap = new Array(); webMap["ENG"] = "http://www.foei.org/"; webMap["ESN"] = "http://www.foei.org/amigos-de-la-tierra-internacional?set_language=es"; webMap["FRA"] = "http://www.foei.org/les-amis-de-la-terre?set_language=fr"; webMap["IND"] = "http://www.foei.org/"; webMap["DAN"] = "http://www.foei.org/"; function initFromCookies() { /* cop-email - email address cop-locale - ewni or int cop-ccode - country code if int set flag set centre text set banner_text */ //set pagelang if((box = document.getElementById('pagelang'))!=null) { pagelang = box.innerHTML; } //get the pagename if poss if((box = document.getElementById('pagename'))!=null) { pagename = box.innerHTML; } if((locale = readCookie('cop-locale'))!=null) { setviacookies = true; //set this flag, so that init() need not bother createCookie('cop-init','initfromCookies',7); switchLocale(); } if(pagename=="word") { //change the success template - if ewni - donate, if int - foei group page window.status = 'word locale: '+locale; if(locale=="int") { var copwebsite; if((copwebsite = readCookie('cop-website'))!=null && copwebsite!="") { if(copwebsite.indexOf("http://")!=0) { copwebsite = "http://"+copwebsite; } if(document.actionform!=undefined && document.actionform.successpageurl!=undefined) { if(copwebsite.indexOf('www.foei.org')!=-1 && pagelang!="") { document.actionform.successpageurl.value = webMap[pagelang]; } else { document.actionform.successpageurl.value = copwebsite; } } } else { //no stored } } } if(pagename=="petition") { //change the success template - if ewni - donate, if int - foei group page if(document.petitionform!=undefined && document.petitionform.misc6!=undefined && langMap[pagelang]!=undefined) { document.petitionform.misc6.value = langMap[pagelang]; } } var copemail; if((copemail = readCookie('cop-email'))!=null) { //look for email field if(document.petitionform!=undefined && document.petitionform.email_address!=undefined) { document.petitionform.email_address.value = copemail; } if(document.actionform!=undefined && document.actionform.sender_email!=undefined) { document.actionform.sender_email.value = copemail; } if(document.donateform!=undefined && document.donateform.Email_address_Mail!=undefined) { document.donateform.Email_address_Mail.value = copemail; } } var copname,copfname,copsname; if((copfname = readCookie('cop-fname'))!=null && (copsname = readCookie('cop-sname'))!=null) { if(document.actionform!=undefined && document.actionform.sender_name!=undefined) { document.actionform.sender_name.value = copfname+' '+copsname; } //stick it on front of subject field too if(document.actionform!=undefined && document.actionform.subject!=undefined) { document.actionform.subject.value = copfname+" "+copsname+"'s "+document.actionform.subject.value; } if(document.petitionform!=undefined && document.petitionform.sname!=undefined) { document.petitionform.sname.value = copsname; } if(document.petitionform!=undefined && document.petitionform.fname!=undefined) { document.petitionform.fname.value = copfname; } if(document.donateform!=undefined && document.donateform.First_name_Required!=undefined) { document.donateform.First_name_Required.value = copfname; } if(document.donateform!=undefined && document.donateform.Surname_Required!=undefined) { document.donateform.Surname_Required.value = copsname; } } if((countrycode = readCookie('cop-ccode'))!=null) { //select that item on drop down, and write misc5 field switchCountry(); if((box=document.getElementById('pagename'))!=null && box.innerHTML=="petition") { makeAJAXReq(0,'/phpscripts/getfoeidetails.php', 'countryname='+countryname+'&countrycode='+countrycode, processFOEI, true, true); } } swapPage(); } function switchCountry() { //loop thru the drop down if(document.forms.petitionform!=undefined && document.forms.petitionform.country!=undefined && countrycode!='') { for(var i=0;i0 && logoArr[0].childNodes!=undefined) { logo = logoArr[0].childNodes[0].data; cname = nameArr[0].childNodes[0].data; if((el = document.getElementById('foeilogo'))!=null) { el.src = '/phpscripts'+logo; } if((el = document.getElementById('foeiname'))!=null) { el.innerHTML = cname; } if(websiteArr!=null && websiteArr.length>0 && websiteArr[0].childNodes!=undefined && websiteArr[0].childNodes.length>0) { website = websiteArr[0].childNodes[0].data; createCookie('cop-website',website,7); } else { createCookie('cop-website',foeidefaultwebsite,7); } if(idArr!=null && idArr.length>0 && idArr[0].childNodes!=undefined && idArr[0].childNodes.length>0) { if((el = document.getElementById('foei_id'))!=null) { el.value = idArr[0].childNodes[0].data; } } } else { createCookie('cop-website',foeidefaultwebsite,7); if((el = document.getElementById('foeilogo'))!=null) { //get the lang specific logo if((logobox=document.getElementById('international_logo'))!=null) { el.src = logobox.innerHTML; } //and lang specific version of friends of the earth international if((el = document.getElementById('foeiname'))!=null) { //get the lang specific logo if((logobox=document.getElementById('foeinamedefault'))!=null) { el.innerHTML = logobox.innerHTML; } } } //alert(xhr.responseText); //document.getElementById('misc5').value = 'no results'; //document.getElementById('output').innerHTML = xhr.responseText; } //alert('sg_processLoginOutput ok'); } else { //alert('2There was a problem with the request. http_request.status: '+xhr.status); } } else { //alert('3There was a problem with the request.'); } } /* ajax */ function makeAJAXReq(id, url, parameters, processingFunction, async, isPost) { var xml_http_request = null; if(isPost == undefined) { isPost = true; } if(async == undefined) { async = true; } xml_http_request = false; if (window.XMLHttpRequest) { // Mozilla, Safari,... xml_http_request = new XMLHttpRequest(); if (xml_http_request.overrideMimeType) { // set type accordingly to anticipated content type xml_http_request.overrideMimeType('text/xml'); //xml_http_request.overrideMimeType('text/html'); } } else if (window.ActiveXObject) { // IE try { xml_http_request= new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { alert('e1'+e); try { xml_http_request= new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { alert('e2'+e); } } } if (!xml_http_request) { alert('Cannot create XMLHTTP instance'); return false; } //alert('params:'+parameters); xml_http_request.onreadystatechange = processingFunction; try{ if(isPost) { xml_http_request.open('POST', url, async); xml_http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); xml_http_request.setRequestHeader("Content-length", parameters.length); //xml_http_request.setRequestHeader("Content-Disposition", 'form-data; name="act_updateActionstaken.xml"'); xml_http_request.setRequestHeader("Connection", "close"); xml_http_request.send(parameters); } else { //alert('get params:'+parameters); xml_http_request.open("GET", url+'?'+parameters, async); xml_http_request.send(null); } } catch (e) { alert(e); } xmlReqs[id] = xml_http_request; } function processAJAXOutput2() { //alert('po'); var xid = 1; var xhr = xmlReqs[xid]; var el, countrynameArr, countrycodeArr; if (xhr.readyState == 4) { if (xhr.status == 200 || xhr.status == 302) { //alert(xhr.responseText); var rXML = xhr.responseXML.documentElement; var ipArr = rXML.getElementsByTagName('client_ip'); var cnArr = rXML.getElementsByTagName('cname'); var ccArr = rXML.getElementsByTagName('ccode'); if(cnArr!=null && cnArr.length>0 && cnArr[0].childNodes!=undefined && cnArr[0].childNodes.length>0) { countrycode = ccArr[0].childNodes[0].data; switchCountry(); swapPage(); swapLogo(document.forms.petitionform.country); } else { countrycode = 'GB'; switchCountry(); swapPage(); swapLogo(document.forms.petitionform.country); //alert(xhr.responseText); //document.getElementById('misc5').value = 'no results'; //document.getElementById('output').innerHTML = xhr.responseText; } //alert('sg_processLoginOutput ok'); } else { //alert('2There was a problem with the request. http_request.status: '+xhr.status); } } else { //alert('3There was a problem with the request.'); } } function processSignerTally() { //alert('po'); var xid = 3; var xhr = xmlReqs[xid]; var el; if (xhr!=undefined && xhr.readyState == 4) { if (xhr.status == 200 || xhr.status == 302) { //alert(xhr.responseText); var rXML = xhr.responseXML.documentElement; var cnArr = rXML.getElementsByTagName('count'); if(cnArr!=null && cnArr.length>0 && cnArr[0].childNodes!=undefined && cnArr[0].childNodes.length>0) { var cnt = cnArr[0].childNodes[0].data * 1; if(cnt>MINTALLY) { if((el = document.getElementById('petition-tally'))!=null) { el.innerHTML = cnArr[0].childNodes[0].data; } } else { if((el = document.getElementById('tally-phrase'))!=null) { el.innerHTML = MINTALLYTEXT; } } } else { alert(xhr.responseText); //document.getElementById('misc5').value = 'no results'; //document.getElementById('output').innerHTML = xhr.responseText; } //alert('sg_processLoginOutput ok'); } else { alert('2There was a problem with the request. http_request.status: '+xhr.status); } } else { //alert('3There was a problem with the request.'); } } function processMyIp() { //alert('po'); var xid = 2; var xhr= xmlReqs[xid]; if (xhr.readyState == 4) { if (xhr.status == 200 || xhr.status == 302) { //alert(xhr.responseText); myIP = xhr.responseText; checkip(myIP); //alert('sg_processLoginOutput ok'); } else { //alert('2There was a problem with the request. http_request.status: '+http_request.status); } } else { //alert('3There was a problem with the request.'); } } function checkip (testip) { //post the pageID to a form via ajax which calls the updateUserActions dynament //actionPageID //components/user/act_updateActionstaken.xml if(testip!=undefined) { ip = testip; } //ip = '132.74.18.2'; //israel //ip = '62.162.32.44'; //macedonia ip = ''; //alert(ip); //makeAJAXReq('/phpscripts/remoteform.php', 'remoteurl=http://www.webseomasters.com/ip-to-country/find-my-ip.php&ip_address='+ip, processAJAXOutput, true, false); //makeAJAXReq('/phpscripts/getfeed.php', 'ct=text/html&doublecoded=true&feedurl=http://www.ip2country.org/?query='+ip, processAJAXOutput2, true, true); makeAJAXReq(1,'/phpscripts/ip2c/get.php', 'ip='+ip, processAJAXOutput2, true, true); } function getmyip () { //post the pageID to a form via ajax which calls the updateUserActions dynament //actionPageID //components/user/act_updateActionstaken.xml //alert(ip); makeAJAXReq(2,'/phpscripts/getmyip.php', '', processMyIp, true, false); } //onsubmit petition form - set email cookie, also make a name cookie function onpetitionsubmit() { if(locale=="int") { //fill in fields that would otherwise be invalid if(document.forms.petitionform.address1.value=="") {document.forms.petitionform.address1.value = "int n/a";} if(document.forms.petitionform.address2.value=="") {document.forms.petitionform.address2.value = "int n/a";} if(document.forms.petitionform.postcode.value=="") {document.forms.petitionform.postcode.value = "int n/a";} document.forms.petitionform.misc1.value = "int"; } else { document.forms.petitionform.misc1.value = "ewni"; } if(has_valid_text_fields(document.forms.petitionform)) { createCookie('cop-email',document.forms.petitionform.email_address.value,7); createCookie('cop-fname',document.forms.petitionform.fname.value,7); createCookie('cop-sname',document.forms.petitionform.sname.value,7); createCookie('cop-name',document.forms.petitionform.fname.value+' '+document.forms.petitionform.sname.value,7); document.forms.petitionform.misc2.value = document.getElementById('foeiname').innerHTML; //shld be innerhtml of the foei group name return true; } else { return false; } } function getSignerTally () { makeAJAXReq(3,'/phpscripts/getcopsigners.php', 's=1', processSignerTally, true, true); } function resetParentList (childList,parentList) { if(childList!=undefined && childList.selectedIndex > 0) { var ctext = childList[childList.selectedIndex].text; var i=0; for(i=0;i 0 if any missing fields if (invalid_counter !==0){ if (document.getElementById('valid') !==null){ document.getElementById('valid').style.display = "block"; } return false; }else{ return true; } }