/********************************************************/
/* THIS PAGE IS FOR ALL THE PUBLIC JAVASCRIPT FUNCTIONS */
/********************************************************/
/********************************************************/
/* NOTE: PLEASE COMMENT ALL FUNCTIONS                   */
/********************************************************/

function switchcontactform() {
	
	if(document.getElementById('baseform').style.display=='block'&&document.getElementById('extendform').style.display=='none') {
	
		document.getElementById('baseform').style.display='none';
		document.getElementById('extendform').style.display='block';
	} else {
		document.getElementById('baseform').style.display='block';
		document.getElementById('extendform').style.display='none';
	}
}

 function launchdemo() {
 	var load = window.open('demoroot.php','','scrollbars=no,menubar=no,height=400,width=550,resizable=no,toolbar=no,location=no,status=no');
}

//Function: accessibility function that changes the font soze of every <p> and <li> on the page
//Author: Dom

function changefontsize(rte) {

	if(rte == '1') {
		wer = "100%";
		
	} else if(rte == '2') {
		wer = "120%";
		
	} else if(rte == '3') {
		wer = "140%";
		
	}

	var objt = document.getElementsByTagName("p");
		for(var i = 0; i < objt.length; i++) {
			if(objt[i].getAttribute('id')!="thequote") {
				objt[i].style.fontSize = wer;
			}
			
		}
		

}

//Function: menu display switching
//Author: Dom

function showbox(ads) {
	
	var tt = document.getElementById(ads);
	tt.style.display = (tt.style.display == "none") ? "block" : "none";

}

//Function: Integration setup switch between before/after code sample
//Author: Dom

function before() {

	document.getElementById("code2").style.display = "none";
	document.getElementById("code1").style.display = "block";
	
}

function after() {

	document.getElementById("code1").style.display = "none";
	document.getElementById("code2").style.display = "block";
	
}


//Function: css off/on
//Author: Dom

function formsubmit() {
document.getElementById("sform").submit();
}

function printview(siter) {
	
	
	var yp = document.getElementById("middlebit");
	
	var timg = "";
	if(siter=="900026") {
		timg = '<p class="closewindow" style="padding-left: 30px; font-family: times; font-size: 4pt; color: #707070"><br />Harte-Hanks Global Address<br />Newminster House<br />27-29 Baldwin Street<br />BRISTOL<br />BS1 1LT<br />UNITED KINGDOM<br />P: 44 (0)117 906 9950<br />F: 44 (0)117 906 9951<br /><br /><span style="font-style: italic">www.globaladdress.net</span></p>'	
	} else {
		timg = '<p class="closewindow" style="padding-left: 30px; font-family: times; font-size: 4pt; color: #707070"><br />Harte-Hanks Global Address<br />800 W El Camino Real<br />Mountain View CA 94040-2586<br />United States of America<br />P: (650) 903-2228<br />F: (650) 962-1188<br /><br /><span style="font-style: italic">www.globaladdress.net</span></p>'	
	}
	
	 top.consoleRef=window.open('','HarteHanksPrintView',
	  'width=800,height=600'
	   +',menubar=1'
	   +',toolbar=0'
	   +',status=0'
	   +',scrollbars=1'
	   +',resizable=1')
	 top.consoleRef.document.writeln(
		'<html><head><title>Harte-Hanks Global Address | www.globaladdress.net</title></head><body style="font-size: 80%; font-family: arial,helvetica,sans-serif;">'
		+'<div>'
		+'<table cellspacing="0" cellpadding="0" broder="0">'
		+'<tr>'
		+'<td style="vertical-align: top; text-align: left;" colspan="2">'
		+'<img src="http://hartehanks.globaladdress.net/images/printhead.jpg" alt="" />'
		+'</td>'
		+'</tr>'
		+'<tr>'
		+'<td style="vertical-align: top">'
		+timg
		+'</td>'
		+'<td style="vertical-align: top; width: 540px;">'
		+'<div style="padding-top: 30px; padding-left:20px;">'
		+yp.innerHTML
		+'</div>'
		+'<input type="hidden" id="HELLO" /></td>'
		+'</tr>'
		+'<tr><td colspan="2"><p class="closewindow" style="text-align: right"><br /><a id="closewindow" href="javascript:window.close();">Close this window</a></p></td></tr>'
		+'</table>'
		+'</div>'
		+'</body></html>'
	 )
	 
	var frt = consoleRef.document.getElementsByTagName("input");
	for(var t=0; t<frt.length; t++) {
		frt[t].disabled=true;
	}
	var frt = consoleRef.document.getElementsByTagName("select");
	for(var t=0; t<frt.length; t++) {
		frt[t].disabled=true;
	}
	var frt = consoleRef.document.getElementsByTagName("a");
	for(var t=0; t<frt.length; t++) {
		if(frt[t].getAttribute("id")!="closewindow") {
			frt[t].removeAttribute("href");
		}
	}
	var frt = consoleRef.document.getElementsByTagName("h1");
	for(var t=0; t<frt.length; t++) {
		frt[t].style.fontSize = "14pt";
	}
	var frt = consoleRef.document.getElementsByTagName("h2");
	for(var t=0; t<frt.length; t++) {
		frt[t].style.fontSize = "12pt";
	}	
	var frt = consoleRef.document.getElementsByTagName("p");
	for(var t=0; t<frt.length; t++) {
		if(frt[t].getAttribute("class")!="closewindow") {
			frt[t].removeAttribute("style");
		}
		frt[t].style.fontSize = "9pt";
	}	
	
	 
	
	
	top.consoleRef.document.close();
		
	
}



function refreshallpage() {
	window.location.reload(true);

}

//Function: editing/adding/showing version info/admin (3 functions)
//Author: Dom


function addstuff() {
	var tt = document.getElementById("versiontext");
	tt.value += "<ul>\n<li></li>\n<li></li>\n<li></li>\n<li></li>\n<li></li>\n</ul>\n";
}

function resetstuff() {
	var tt = document.getElementById("versiontext");
	tt.value = "";
}

function showv(ert) {
	var rein = "v" + ert;
	var tt = document.getElementById(rein);

	if(tt.style.display == "none") {
		tt.style.display = "block";
	} else if(tt.style.display == "block") {
		tt.style.display = "none";
	}

}


//Function: forcing a scrollbar in non-IE
//Author: Dom

var detect = navigator.userAgent.toLowerCase();
var OS,browser,version,total,thestring;

if (checkIt('konqueror'))
{
	browser = "Konqueror";
	OS = "Linux";
}
else if (checkIt('safari')) browser = "Safari"
else if (checkIt('omniweb')) browser = "OmniWeb"
else if (checkIt('opera')) browser = "Opera"
else if (checkIt('webtv')) browser = "WebTV";
else if (checkIt('icab')) browser = "iCab"
else if (checkIt('msie')) browser = "Internet Explorer"
else if (!checkIt('compatible'))
{
	browser = "Netscape Navigator"
	version = detect.charAt(8);
}
else browser = "An unknown browser";

if (!version) version = detect.charAt(place + thestring.length);

function checkIt(string)
{
	place = detect.indexOf(string) + 1;
	thestring = string;
	return place;
}

var cssout;

if(browser!="Internet Explorer") {
	var tt = document.getElementsByTagName("html");

	tt[0].style.overflowY = "scroll";

}

//Function: descriptions on integrationsettings
//Author: Dom

function flashtexton(typr) {
	document.getElementById(typr).style.display = "inline";

}
function flashtextoff(typr) {
	document.getElementById(typr).style.display = "none";

}

//Function: index page background swapper
//Author: Dom

function swapreset(tryb) {
	var ee = document.getElementById(tryb).style.backgroundImage = "url('images/dbbottom1.gif')";
}

function swapper(tryb, wee) {
	var ee = document.getElementById(tryb);

	switch(wee) {

		case 'js':
			ee.style.backgroundImage = "url('images/dbbottom2.gif')";
			break;
		case 'ws':
			ee.style.backgroundImage = "url('images/dbbottom3.gif')";
			break;
		case 'ba':
			ee.style.backgroundImage = "url('images/dbbottom4.gif')";
			break;


	}
}


//Function: index page button swap and loggedin button swap
//Author: Dom

function swapy(trr, imgw) {
	var imk = "images/" + imgw + ".gif";
	document.getElementById(trr).setAttribute("src", imk);
}



// START OF AJAX STUFF //
// START OF AJAX STUFF //
// START OF AJAX STUFF //
// START OF AJAX STUFF //

function xmlhttpPost(strURL, divid) {

	var xmlHttpReq =false;

	/*@cc_on @*/

	/*@if (@_jscript_version >= 5)
		try {
			xmlHttpReq = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (E) {
				xmlHttpReq = false;
			}
		}
	@else
		xmlHttpReq = false;
	@end @*/

	if (!xmlHttpReq  && typeof XMLHttpRequest!='undefined') {
		try {
			  xmlHttpReq = new XMLHttpRequest();
		} catch (e) {
			  xmlHttpReq = false;
			}
	}

	xmlHttpReq.open("GET", strURL, true);
	xmlHttpReq.onreadystatechange = function() {
		if (xmlHttpReq.readyState == 4) {
			if (xmlHttpReq.status == 200) {
			updatepage(xmlHttpReq.responseText, divid);
			}
		}
	}

	xmlHttpReq.send(null);
	return true;

}

var focusElement = null;

function setFocus(id)
{
    focusElement = id;
}


function updatepage(str, divid){
	document.getElementById(divid).innerHTML = str;
	
	if(document.getElementById(focusElement) != null)    
        document.getElementById(focusElement).focus();    
	
	return true;
}

function escapef(stringin) {
	stringin = escape(stringin);
	stringin = stringin.replace(/\//g,"%2F");
	stringin = stringin.replace(/\?/g,"%3F");
	stringin = stringin.replace(/=/g,"%3D");
	stringin = stringin.replace(/&/g,"%26");
	stringin = stringin.replace(/@/g,"%40");
	//stringin = stringin.replace("£","&#163");
	return stringin;
}



function enterPage() {



	var phpvar = phpin;
	if(phpvar=="") {
		phpvar = "500000";
	}

	// ALWAYS CALL 4
	//var tmenuin = "script_topmenu.php?tmenuid=" + phpvar + "&site=" + site;
	//xmlhttpPost(tmenuin, 'topmenu');

	var nmch = sider;

	//alert(nmch);

	if(nmch=="M") {
		var newsin = "script_sidemenu.php?menuid=" + phpvar + "&mid="+sendmenuid+"";
		xmlhttpPost(newsin, 'newsmenu');
	} else {

		var menuin = "script_newsload.php";
		xmlhttpPost(menuin, 'newsmenu');		
	}



	xmlhttpPost('script_loadquotes.php', 'clientquotes');

	var stringin = "";



	if(phpvar!="false") {
		stringin = "script_loadpage.php?action=none&page="+phpin+"";
	} else {
		stringin = "script_loadpage.php";
	}
	//xmlhttpPost(stringin, 'middlebit');
}

function editPage(pid) {
	//alert(pid);
	var stringin = "script_loadpage.php?action=edit&page=" + pid;
	xmlhttpPost(stringin, 'middlebit');

}


function savePage(pid) {

//get all the data from the forms then get it back to the php function
//error handle here too with alerts

//IE errors: system cannot locate resource specified 30/01/07


// pagetitle
var pagetitle = document.getElementById("pageHead").value;

//page content
var oEditor = FCKeditorAPI.GetInstance('pageContent');
var pcontent = oEditor.GetXHTML();

//Browsertitle
var urltitle = document.getElementById("urlHead").value;

//meta desc
var pagedesc = document.getElementById("descriptioni").value;

//meta keys
var pagekeys = document.getElementById("keywordsi").value;


var menuchoice = "";

if(document.getElementById("showb1").checked) {
	menuchoice = document.getElementById("showb1").value;
} else if(document.getElementById("showb2").checked) {
	menuchoice = document.getElementById("showb2").value;
} else {
	menuchoice = "menu";
}


//alert(pagetitle);
//alert(pcontent);
//alert(urltitle);
//alert(pagedesc);
//alert(pagekeys);
//alert(menuchoice);

//pcontent = escapef(String(pcontent));

var stringin = "script_loadpage.php?action=save&left=" + menuchoice + "&page=" + pid + "&paget=" + escapef(pagetitle) + "&pagec=" + escapef(pcontent) + "&pageu=" + escapef(urltitle) + "&paged=" + escapef(pagedesc) + "&pagek=" + escapef(pagekeys) + "";

//alert(stringin);
xmlhttpPost(stringin, 'middlebit');


}

function resetPage(pid) {
	var stringin = "script_loadpage.php?action=none&page=" + pid;
	xmlhttpPost(stringin, 'middlebit');
}

function addMenu() {

	var menuin = "script_sidemenu.php?action=addmenu&menuid="+phpin+"&mid="+sendmenuid+"";
	xmlhttpPost(menuin, 'newsmenu');
}

function addMenuL2(l2parent) {

	var menuin = "script_sidemenu.php?action=addmenu2&menuid="+phpin+"&parent="+l2parent+"&mid="+sendmenuid+"";
	xmlhttpPost(menuin, 'newsmenu');
}

function resetMenu() {
	var menuin = "script_sidemenu.php?menuid="+phpin+"&mid="+sendmenuid+"";
	xmlhttpPost(menuin, 'newsmenu');
}

function resetNewsMenu() {
	var menuin = "script_newsload.php";
	xmlhttpPost(menuin, 'newsmenu');
}

function saveMenu(par) {
	
	var aa = document.getElementById("label").value;
	var bb = document.getElementById("link").value;
	var cc = par;
	var dd = document.getElementById("static").value;
	//var gg = document.getElementById("siteimg").value;
	var gg = "";
	
	var ee = document.getElementById("section").value;
	
	
	if(aa!=""&&bb!=""&&cc!=""&&dd!=""&&ee!="") {
		var movestring = "script_sidemenu.php?am=load&action=savenewmenu&label="+escapef(aa)+"&link="+escapef(bb)+"&parent="+cc+"&static="+dd+"&section="+ee+"&mid="+sendmenuid+"&menuid="+phpin+"&image="+gg+"";
		//alert(movestring);
		xmlhttpPost(movestring, 'newsmenu');

	} else {
		alert("Need all fields");
	}

}

function editshow(mid) {

	var menuin = "script_sidemenu.php?action=showedit&menuid="+phpin+"&mid="+sendmenuid+"";
	xmlhttpPost(menuin, 'newsmenu');

}
function saveMenuL2(menupar) {


	var mname = document.getElementById("mname2").value;
	var slink = document.getElementById("slink2").value;

	var pmenuid = document.getElementById("pmenuid").value;
	
	var tssec = document.getElementById("sections2").value;


	if(mname!="") {
		var menuin = "script_sidemenu.php?action=savemenu&pmenuid="+pmenuid+"&menuid="+phpin+"&menuparent=" + escapef(menupar) + "&mname=" + escapef(mname) + "&mlink=" + escapef(slink) + "&mid="+sendmenuid+"&secid="+tssec+"";
		//alert(menuin);
		xmlhttpPost(menuin, 'newsmenu');
		//resetMenu();

	} else {
		alert("The menu item must have a name");
	}


}
/*
function saveEditMenu(emenupar) {

	var emname = document.getElementById("emname").value;
	

	}

	var epmenuid = document.getElementById("pmenuid").value;
	
	var tssec = document.getElementById("sections").value;


	if(emname!="") {
		var emenuin = "script_sidemenu.php?action=editmenu&mid="+epmenuid+"&menuid="+phpin+"&emenuparent=" + escapef(emenupar) + "&emname=" + escapef(emname) + "&emlink=" + escapef(emlink) + "&secid="+tssec+"";
		//alert(menuin);
		xmlhttpPost(emenuin, 'newsmenu');
		//resetMenu();

	} else {
		alert("The menu item must have a name");
	}


}
*/
function saveEditMenu(mid) {



	var label = document.getElementById("label").value;
	var link = document.getElementById("link").value;
	var staticy = document.getElementById("static").value;	
	var section = document.getElementById("section").value;	
	var gg = "";

	if(label!=""&&link!=""&&staticy!="") {
	
		var movestring = "script_sidemenu.php?mid="+mid+"&menuid="+phpin+"&action=editmenu&label="+escapef(label)+"&link="+escapef(link)+"&static="+staticy+"&section="+section+"&image="+gg+"";
		
		//alert(movestring);
		xmlhttpPost(movestring, 'newsmenu');
		
	
	} else {
		alert("Please fill in all fields");
	}


}



function hideEdit() {
	var menuin = "script_sidemenu.php?action=hideedit&menuid="+phpin+"&mid="+sendmenuid+"";
	xmlhttpPost(menuin, 'newsmenu');

}

function deletePage(pid) {

	var tt = confirm("You are about to remove the page and delete the menu item. Click 'yes' to confirm this or click 'cancel' to go return to the current page.");

	if(tt) {
		// send request to delete page
		var stringin = "script_loadpage.php?action=deletepage&page=" + pid;
		//alert(stringin);
		xmlhttpPost(stringin, 'middlebit');
		
		var menuin = "script_sidemenu.php?edit=off&menuid="+phpin+"&mid="+sendmenuid+"";
		xmlhttpPost(menuin, 'newsmenu');
		
		resetTopMenu();
	}

}



function addTopMenu(tid, divref) {

	var tmenuin = "script_topmenu.php?action=addmenu&tmenuid="+tid+"&xpos="+getAnchorPosition(divref).x+"&ypos="+getAnchorPosition(divref).y+"";
	xmlhttpPost(tmenuin, 'topmenu');

}

function resetTopMenu() {
	var menuin = "script_topmenu.php?tmenuid="+phpin+"";
	xmlhttpPost(menuin, 'topmenu');
}


function createMenu(cid) {
	
	var aa = document.getElementById("label").value;
	var bb = document.getElementById("link").value;
	////var cc = document.getElementById("parent").value;
	var dd = document.getElementById("static").value;
	var ee = document.getElementById("section").value;
	////var ff = document.getElementById("level").value;
	///var gg = document.getElementById("siteimg").value;
	var gg = "";
	
	if(aa!=""&&bb!=""&&dd!=""&&ee!="") {
		var movestring = "script_topmenu.php?action=savenewmenu&tmenuid="+phpin+"&cid="+cid+"&label="+escapef(aa)+"&link="+escapef(bb)+"&static="+dd+"&section="+ee+"&image="+gg+"";
		xmlhttpPost(movestring, 'topmenu');
	} else {
		alert("Need all fields");
	}

}


function admincreatesite() {
	
	var sitelabel = document.getElementById("sitename").value;
	var sitelink = document.getElementById("sitelink").value;
	var sitecss = document.getElementById("sitecss").value;
	var sitesection = document.getElementById("sitesection").value;
	
	if(sitelabel!=""&&sitelink!=""&&sitesection!="") {
		var stringin = "script_topmenu.php?am=site&action=savecreatesite&sla="+sitelabel+"&sli="+sitelink+"&scss="+sitecss+"&ssec="+sitesection+"&tmenuid="+phpin+"";
		xmlhttpPost(stringin, 'topmenu');	
	
	} else {
		alert("Please fill in all fields");
	}
	
	

}

function savesitename(cid) {

	var sname = document.getElementById("newname").value;
	
	var sccs = document.getElementById("sitecss").value;
	var ssection = document.getElementById("sitesection").value;

	if(sname!=""&&sccs!="") {
		var smenuin = "script_topmenu.php?action=savesitename&section="+ssection+"&css="+escapef(sccs)+"&sname=" + escapef(sname) + "&site="+cid+"&tmenuid="+phpin+"";
		xmlhttpPost(smenuin, 'topmenu');
		//resetTopMenu();

	} else {
		alert("The site must have a name and a stylesheet");
	}

}
function adminsavesite(cid) {

	var divref = cid + "_a";
	
	var sitelabel = document.getElementById("newsitename").value;
	var sitelink = document.getElementById("newsitelink").value;
	var sitecss = document.getElementById("newsitecss").value;
	var sitesection = document.getElementById("newsitesection").value;
	
	if(sitelabel!=""&&sitelink!=""&&sitesection!="") {
		var stringin = "script_topmenu.php?action=saveedit&cid="+cid+"&site="+cid+"&sla="+sitelabel+"&sli="+sitelink+"&scss="+sitecss+"&ssec="+sitesection+"&tmenuid="+phpin+"&xpos="+getAnchorPosition(divref).x+"&ypos="+getAnchorPosition(divref).y+"";
		xmlhttpPost(stringin, 'topmenu');	
	
	} else {
		alert("Please fill in all fields");
	}
	
	

}

function saveeditmenu(mid) {


	//var parent = document.getElementById("parent").value;
	
	var label = document.getElementById("label").value;
	var link = document.getElementById("link").value;	
	var staticy = document.getElementById("static").value;
	var section = document.getElementById("section").value;	
	//var gg = document.getElementById("siteimg").value;
	var gg = "";

	if(label!=""&&link!=""&&staticy!="") {
	
		var movestring = "script_topmenu.php?mid="+mid+"&tmenuid="+phpin+"&action=saveeditmenu&label="+escapef(label)+"&link="+escapef(link)+"&static="+staticy+"&section="+section+"&image="+gg+"";
		xmlhttpPost(movestring, 'topmenu');
	
	} else {
		alert("Please fill in all fields");
	}


}

function deactivateSite(cid) {
	
	var movestring = "script_topmenu.php?action=deactivatesite&site=" + cid + "&tmenuid="+phpin+"";
	xmlhttpPost(movestring, 'topmenu');	

}


function editsitename(cid) {
	
	var divref = cid + "_a";
	
	var smenuin = "script_topmenu.php?action=editsitename&site="+cid+"&tmenuid="+phpin+"&xpos="+getAnchorPosition(divref).x+"&ypos="+getAnchorPosition(divref).y+"";	
	
	//var smenuin = "script_topmenu.php?action=editsitename&site="+cid+"&tmenuid="+phpin+"";
	xmlhttpPost(smenuin, 'topmenu');	
	

}

function editmenuname(mid, divref) {
	
	//var divref = mid + "_a";
	var smenuin = "script_topmenu.php?action=editmenuname&mid="+mid+"&tmenuid="+phpin+"&xpos="+getAnchorPosition(divref).x+"&ypos="+getAnchorPosition(divref).y+"";	
	xmlhttpPost(smenuin, 'topmenu');	
	

}




function topMoveLeft(menuid, lev) {
	//alert(menuid);
	var movestring = "script_topmenu.php?action=topmoveleft&level="+lev+"&menuid=" + menuid + "&tmenuid="+phpin+"&mid="+sendmenuid+"";
	xmlhttpPost(movestring, 'topmenu');
	//resetTopMenu();
}

function topMoveRight(menuid, lev) {
	//alert(menuid);
	var movestring = "script_topmenu.php?action=topmoveright&level="+lev+"&menuid=" + menuid + "&tmenuid="+phpin+"&mid="+sendmenuid+"";
	xmlhttpPost(movestring, 'topmenu');
	//resetTopMenu();
}
function siteMoveLeft(cid, lev) {
	var movestring = "script_topmenu.php?action=sitemoveleft&level="+lev+"&site=" + cid + "&tmenuid="+phpin+"&mid="+sendmenuid+"";
	xmlhttpPost(movestring, 'topmenu');
}

function siteMoveRight(cid, lev) {
	var movestring = "script_topmenu.php?action=sitemoveright&level="+lev+"&site=" + cid + "&tmenuid="+phpin+"&mid="+sendmenuid+"";
	xmlhttpPost(movestring, 'topmenu');
}

function LeftMoveUp(menuid) {
	//alert(menuid);
	var movestring = "script_sidemenu.php?action=leftmoveup&tmenuid=" + menuid + "&menuid="+phpin+"&mid="+sendmenuid+"";
	//alert(movestring);
	xmlhttpPost(movestring, 'newsmenu');
	//resetTopMenu();
}

function LeftMoveDown(menuid) {
	//alert(menuid);
	var movestring = "script_sidemenu.php?action=leftmovedown&tmenuid=" + menuid + "&menuid="+phpin+"&mid="+sendmenuid+"";
	//alert(movestring);
	xmlhttpPost(movestring, 'newsmenu');
	//resetTopMenu();
}

function refreshQuote() {
	xmlhttpPost('script_loadquotes.php', 'clientquotes');
}

function addQuote() {

	xmlhttpPost('script_loadquotes.php?action=addquote', 'clientquotes');

}

function deleteQuote(qid) {

	var tt = confirm("You are about to permantently delete the quote. Click 'yes' to confirm this or click 'cancel' to go return to the current page.");

	if(tt) {
		var stringin = "script_loadquotes.php?action=deletequote&qid="+qid+"";
		//alert(stringin);
		xmlhttpPost(stringin, 'clientquotes');
	}

}

function saveQuote() {

	var qq = document.getElementById("newquote").value;
	var rr = document.getElementById("newreferrer").value;
	
	
	var sites = document.getElementById("sites").value;
	
	//alert(sites);
	
	var sitearray = sites.split("%%%");
	
	var sitesel = "";
	
	for(var t=0; t<sitearray.length-1; t++) {
		
		//alert(document.getElementById(sitearray[t]).checked);
		
		if(document.getElementById(sitearray[t]).checked) {
			sitesel += sitearray[t] + "NNN";
		}
	
	}	

	if(qq!=""&&rr!=""&sitesel!="") {
	var stringin = "script_loadquotes.php?action=savequote&sitesin="+sitesel+"&quote="+escapef(qq)+"&referrer="+escapef(rr)+"";
	xmlhttpPost(stringin, 'clientquotes');
	} else {
		alert("You must enter values for the quote, referrer and site");
	}
}


function addNews() { 

	var stringin = "script_newsfunctions.php?action=add";
	xmlhttpPost(stringin, 'holdnews');
	

}

function loadRange(dat) {

var stringin = "script_newsfunctions.php?range="+dat+"";
xmlhttpPost(stringin, 'holdnews');


}


function editNews(nidin) {

	var stringin = "script_loadnews.php?action=edit&nid="+nidin+"";
	xmlhttpPost(stringin, 'middlebit');
	

}

function createNews() {

var headline = document.getElementById("headline").value;
var oEditor = FCKeditorAPI.GetInstance('newsContent');
var newsContent = oEditor.GetXHTML();
var browserline = document.getElementById("browserline").value;
var pagedesc = document.getElementById("description").value;
var pagekeys = document.getElementById("keywords").value;

var stringin = "script_newsfunctions.php?action=create&headline=" + escapef(headline) + "&newsc=" + escapef(newsContent) + "&btitle=" + escapef(browserline) + "&paged=" + escapef(pagedesc) + "&pagek=" + escapef(pagekeys) + "";
xmlhttpPost(stringin, 'holdnews');



}

function saveNews(nidin) {

	// pagetitle
	var headline = document.getElementById("headline").value;

	//page content
	var oEditor = FCKeditorAPI.GetInstance('newsContent');
	var newsContent = oEditor.GetXHTML();


	//Browsertitle
	var browserline = document.getElementById("browserline").value;

	//meta desc
	var pagedesc = document.getElementById("description").value;

	//meta keys
	var pagekeys = document.getElementById("keywords").value;


	//alert(headline);
	//alert(newsContent);
	//alert(browserline);
	//alert(pagedesc);
	//alert(pagekeys);
	var sites = document.getElementById("sites").value;
	
	//alert(sites);
	
	var sitearray = sites.split("%%%");
	
	var sitesel = "";
	
	for(var t=0; t<sitearray.length-1; t++) {
		
		//alert(document.getElementById(sitearray[t]).checked);
		
		if(document.getElementById(sitearray[t]).checked) {
			sitesel += sitearray[t] + "NNN";
		}
	
	}
	
	
	

	var stringin = "script_loadnews.php?action=save&sitesfor="+sitesel+"&nid=" + nidin + "&headline=" + escapef(headline) + "&newsc=" + escapef(newsContent) + "&btitle=" + escapef(browserline) + "&paged=" + escapef(pagedesc) + "&pagek=" + escapef(pagekeys) + "";
	xmlhttpPost(stringin, 'middlebit');



}

function deleteNews(nidin) {

	var tt = confirm("You are about to remove the news item. Click 'yes' to confirm this or click 'cancel' to go return to the current page.");

	if(tt) {
		// send request to delete page
		var stringin = "script_loadnews.php?action=delete&nid=" + nidin;

		xmlhttpPost(stringin, 'middlebit');
		resetNewsMenu();

	}

}

function createarticale(siter) {
		var stringin = "script_newsload.php?action=createarticle&site="+siter+"";
		xmlhttpPost(stringin, 'newsmenu');

}

function resetNewsMenu() {

		var stringin = "script_newsload.php";
		xmlhttpPost(stringin, 'newsmenu');

}

function resetNews(pageguf) {
	if(pageguf=="") {
		var stringin = "script_newsfunctions.php";
		xmlhttpPost(stringin, 'holdnews');
	} else {
		var stringin = "script_loadnews.php?nid="+pageguf+"";
		xmlhttpPost(stringin, 'middlebit');
	}

}

function reactivatePage(pid) {

	var stringin = "script_loadpage.php?action=undelete&page=" + pid;
	xmlhttpPost(stringin, 'middlebit');
	resetMenu();


}

function discardPage(pid) {
	
	var tt = confirm("This will permanently remove the page. Are you sure?");

	if(tt) {

		var stringin = "script_loadpage.php?action=discard&page=" + pid;
		xmlhttpPost(stringin, 'middlebit');

	}	

}

function delOnlyMenu(middy) {

		var stringin = "script_loadpage.php?action=deletestaticmenu&mid=" + middy;
		xmlhttpPost(stringin, 'middlebit');
		resetMenu();

}

function discardNews(nid) {
	
	var tt = confirm("This will permanently remove the article. Are you sure?");

	if(tt) {

		var stringin = "script_loadnews.php?action=discard&nid=" + nid;
		xmlhttpPost(stringin, 'middlebit');

	}	

}

function reactivateNews(nid) {

	var stringin = "script_loadnews.php?action=undelete&nid=" + nid;
	xmlhttpPost(stringin, 'middlebit');
	resetNewsMenu();
	


}


function LoggedEnterPage() {


	var phpvar = phpin;
	var nmch = sider;

	//SAME
	var tmenuin = "script_topmenu.php?tmenuid=" + phpvar;
	xmlhttpPost(tmenuin, 'topmenu');
	//SAME
	xmlhttpPost('script_loadquotes.php', 'clientquotes');
	var stringin = "";	


	var newsin = "script_resources.php?menuid=" + phpvar + "&mid="+sendmenuid+"";
	xmlhttpPost(newsin, 'newsmenu');


}

function loadLogin() {
	
	if(!document.getElementById("loginloaded")) {
		var stringin = "script_loginform.php";
		xmlhttpPost(stringin, 'loginbit');
	}

}

function resetlogin() {
	var tmenuin = "script_loginform.php?resetlogin=true";
	xmlhttpPost(tmenuin, 'loginbit');	
}
function returnon(e) {
  
  if (e.keyCode != 13) {
  	return;
  } else {
  	log_in();
  }

}
function submitlogin() {
	
	document.getElementById("login").value = "Login";
	document.getElementById("loginform").submit();
}
function returnin(e) {
  
  if (e.keyCode != 13) {
  	return;
  } else {
  	submitlogin2();
  }

}
function submitlogin2() {
	document.getElementById("weblogin").submit();
}
function helptext(typei) {
	
	var helptext = "";
	helptext += "<html><head><title>Help</title><link href='/hhgaroot.css' type='text/css' rel='stylesheet' /></head><body style='color: #fff; padding: 10px;'>";

	switch(typei) {
		case "sitename":
		helptext += "<h2 style='color: #fff'>Site name</h2>";
		helptext += "<p>The site name is the label for the site that is presented in all respective menus and links.</p>";
		helptext += "<p><strong>This is a mandatory field</strong></p>";
		break;
		case "sitelink":
		helptext += "<h2 style='color: #fff'>Site link</h2>";
		helptext += "<p>The site link is used by the URL to navigate to the respective menus and pages. When a site is created, a menu and page item are created and linked to by what is in this field.</p>";
		helptext += "<p><strong>This is a mandatory field and must be unique</strong></p>";
		break;	
		case "stylesheet":
		helptext += "<h2 style='color: #fff'>Style sheet</h2>";
		helptext += "<p>It is possible to select which of the available stylesheets you would like to aply throughout this site. This is only available to stylesheets on currently on the server.</p>";
		helptext += "<p><strong>Not selecting an option will result in a default stylesheet being loaded.</strong></p>";
		break;	
		case "restrictedto":
		helptext += "<h2 style='color: #fff'>Restricted to</h2>";
		helptext += "<p>This option controls user access to the site. Selecting'General' will mean that the site will can be accessed by the public. Anything created within this site can again be restricted to different sections.</p>";
		helptext += "<p><strong>This field is mandatory. You must be aware of the hierarchy of access that you grant when creating sections and assigning users to groups.</strong></p>";
		break;	
		case "menuname":
		helptext += "<h2 style='color: #fff'>Menu name</h2>";
		helptext += "<p>The menu name is the label for the menu that is presented along the upper menu bar on this site.</p>";
		helptext += "<p><strong>This is a mandatory field</strong></p>";
		break;
		case "menulink":
		helptext += "<h2 style='color: #fff'>Menu link</h2>";
		helptext += "<p>You can use this field to either specify the dynamic link for the menu and the associated page created when saving the menu, or specify an external link (without http://).</p>";
		helptext += "<p><strong>This is a mandatory field</strong></p>";
		break;
		case "menustatic":
		helptext += "<h2 style='color: #fff'>Static link</h2>";
		helptext += "<p>If the menu links to a page that has been externally created, or to a completely external URL, then you must select 'Yes' so that a dynamic page is not created and linked to the menu.</p>";
		helptext += "<p><strong>This is a mandatory field that is set to 'No' by default</strong></p>";
		break;		
		default:
		helptext += "<h2 style='color: #fff'>Help text</h2>";
		helptext += "<p>There is no help available for this field at this time.</p>";
		
		break;		
		

	}
	
	helptext += "<br /><br /><p class='textr'><a style='color: #3e7898' href='javascript: self.close();'>close this window</a></p></body></html>";
	
	
	openwindow = window.open("","newwin","height=200,width=320,toolbar=no,scrollbars=no,menubar=no");
	openwindow.document.write(helptext);
	openwindow.document.close();
	self.name="main";

}

function openForwardFriend() {
	var openwindow = window.open("pageforward.php?url="+window.location+"","ffwin","height=450,width=320,toolbar=no,scrollbars=yes,menubar=no");
}


function openform(wich) {

	var netlink = "";
	
	if(wich=="information") {
		netlink = "https://forms.netsuite.com/app/site/crm/externalleadpage.nl?compid=675169&formid=2&h=406d7a6a4f81f0697af3";
	}
	
	if(wich=="callback") {
		netlink = "https://forms.netsuite.com/app/site/crm/externalleadpage.nl?compid=675169&formid=1&h=772d6307f6fb117ddc15";
	}
	
	if(wich=="contact") {
		netlink = "/ContactUs.php";
	}	
	
	 top.consoleRef=window.open(netlink,wich,
	  'width=500,height=450'
	   +',menubar=0'
	   +',toolbar=0'
	   +',status=0'
	   +',scrollbars=1'
	   +',resizable=1');


}


function log_in() {
	
	
	document.getElementById("login_response").innerHTML = "<p style='font-weight: bold'>Please wait...</p>";
	
	var un = document.getElementById("username").value;
	//var ps = SHA1(document.getElementById("password").value);
	var ps = document.getElementById("password").value;
	var rem = document.getElementById("remember").checked;
	
	var stringin = "http://www.globaladdress.net/script_login2.php?l1="+escapef(un)+"&l2="+escapef(ps)+"&l3="+rem+"";
	xmlhttpPost(stringin, 'login_response');	
	
	//document.getElementById("username").value = "";
	document.getElementById("password").value = "";
	document.getElementById("remember").checked = false;
	testlogin();
}

function testlogin() {
	if(document.getElementById("loginflag")) {
		window.location = "http://www.globaladdress.net/website/";
	} else {
		setTimeout(testlogin, 1500);	
	}
}

function password_reset() {
	
	
	document.getElementById("password_response").innerHTML = "<p style='font-weight: bold'>Please wait...</p>";
	var un = document.getElementById("pemail").value;
	var stringin = "script_resetpassword.php?email="+escapef(un)+"";
	xmlhttpPost(stringin, 'password_response');	
	document.getElementById("pemail").value="";
	
}

function randomGenerator(rsize) {
	
	var nep = "";
	var tt = new Array("A","B","C","D","E","F","G","H","J","K","L","M","N","P","Q","R","S","T","U","V","W","X","Y","Z");
	for(var ff = 0; ff < rsize; ff++) {
		var i= Math.floor(Math.random()*tt.length);
		var gg = Math.floor(Math.random()*10);
		var toad = tt[i];
		if(gg%2==0) {
			toad = toad.toLowerCase();
		}
		nep += toad;
	}
	return nep;

	
}

function forward_send() {
	document.getElementById("forward_response").innerHTML = "<p style='font-weight: bold'>Please wait...</p>";
	
	var to = document.getElementById("toemail").value;
	//var ps = SHA1(document.getElementById("password").value);
	var name = document.getElementById("fromname").value;
	var from = document.getElementById("fromemail").value;
	var mess = document.getElementById("frommessage").value;
	
	var stringin = "script_forward.php?to="+escapef(to)+"&from="+escapef(from)+"&name="+escapef(name)+"&message="+escapef(mess)+"";
	xmlhttpPost(stringin, 'forward_email');		
}
function forward_open() {
	var stringin = "script_forward.php";
	xmlhttpPost(stringin, 'forward_email');		
}

function forward_reset() {
	var stringin = "script_forward.php?resetforward=true";
	xmlhttpPost(stringin, 'forward_email');		
}

function opendemosmain(whichd) {
	
	switch(whichd) {
		case "batch":
			var demoload = window.open('/LocalDemos/Demos/Batch.html','','scrollbars=no,menubar=no,height=550,width=730,resizable=no,toolbar=no,location=no,status=no');	
			break;
		case "interactive":
			var demoload = window.open('/LocalDemos/Demos/Interactive.html','','scrollbars=no,menubar=no,height=550,width=730,resizable=no,toolbar=no,location=no,status=no');	
			break;
		case "web":
			var demoload = window.open('/LocalDemos/Demos/Web.html','','scrollbars=no,menubar=no,height=550,width=730,resizable=no,toolbar=no,location=no,status=no');	
			break;
		default:
			var demoload = window.open('/LocalDemos/index.html','','scrollbars=no,menubar=no,height=550,width=730,resizable=no,toolbar=no,location=no,status=no');	
			break;
	}
	
}

function sendform() {
	document.getElementById("dx_form").submit();	
}
function ff_sendform() {
	document.getElementById("ff_form").submit();	
}


function partner_changedetail(picker) {







	var thehtml = "";
	
	var address1 = new Array("<strong>Amateo</strong><br />Merchant's House<br />27-30 Merchant's Quay<br />Dublin 8<br />Ireland","Tel: +353 1 402 8181<br />Fax: +353 1 402 8101<br />Web: <a href='http://www.amateo.com' target='_blank'>www.amateo.com</a><br />E-mail: info@amateo.com<br />");
	var address2 = new Array("<strong>GB Group plc</strong><br />GB House<br />Kingsfield Court<br />Chester Business Park<br />Chester<br />CH4 9GB<br />United Kingdom","Tel: +44 (0)1244 657333<br />Fax: +44 (0)1244 680808<br />Web: <a href='http://www.gb.co.uk' target='_blank'>www.gb.co.uk</a><br />E-mail: enquiries@gb.co.uk");
	var address3 = new Array("<strong>DQ Global</strong><br />Cams Hall<br />Cams Hill<br />Fareham<br />PO16 8AB<br />United Kingdom","Tel: +44 (0)1329 227505<br />Fax: +44(0) 1329 227506<br />Web: <a href='http://www.dqglobal.com' target='_blank'>www.dqglobal.com</a><br />E-mail: info@dqglobal.com","<strong>DQ Global Inc</strong><br />1230 Reid Street, Unit B<br />Richmond Hill<br />Ontario<br />L4B 1C4","Tel: +1 905-731-1690<br />Fax: +1 905-709-1102");
	var address4 = new Array("<strong>Wipro Technologies</strong><br />Mimet House<br />5a Praed Street<br />London<br />W2 1NJ<br />United Kingdom","Tel: +44 (0)20 7087 3770<br />Fax: +44 (0)20 7262 5360<br />Web: <a href='http://www.wipro.com' target='_blank'>www.wipro.com</a>","<strong>Wipro Technologies</strong><br />1300 Crittenden Lane<br />2nd Floor<br />Mountain View, CA 94043<br />United States of America","Tel: +1 650-316-3555<br />Fax: +1 650-316-3468<br />Web: www.wipro.com","<strong>Wipro Limited</strong><br />Level 3<br />201 Miller Street<br />North Sydney<br />NSW 2060<br />Australia","Tel: +61 2 9394 8108<br />Fax: +61 2 9394 8199<br />Web: www.wipro.com");
	var address5 = new Array("<strong>Theikos</strong><br />107 Udyog Vihar, Ph. 1V<br />Gurgaon - 122016<br />Haryana<br />India","Tel: +91 124 5109800<br />E-Mail: contactus@theikos.com<br />Web: <a href='http://www.theikos.com' target='_blank'>www.theikos.com</a>","<strong>Boston Office:</strong><br />6 Oak Street<br />Waltham MA 02453<br />United States of America","Tel: +1 781-398-2202<br />Web: <a href='http://www.theikos.com' target='_blank'>www.theikos.com</a><br />E-Mail: contactus@theikos.com","<strong>Chicago Office:</strong><br />3843 N Keeler Ave<br />Chicago IL 60641<br />United States of America","Tel: +1 781-398-2202<br />Web: <a href='http://www.theikos.com' target='_blank'>www.theikos.com</a><br />E-Mail: contactus@theikos.com");
	var address6 = new Array("<strong>Freelance Technologies Inc</strong><br />116R Edwards Ferry Rd NE<br />Leesburg VA 20176-2301<br />United States of America","Tel: +1 703-779-1990<br />Fax: +1 703-779-2199<br />Web: <a href='http://www.freelancetech.com' target='_blank'>www.freelancetech.com</a><br />E-Mail: fti@freelancetech.com");
	var address7 = new Array("<strong>Data Aspects Pty Ltd</strong><br />Level 2<br />87 Upton Street<br />Bundall<br />Qld 4217<br />Austrailia","Tel: +61 7 5579 2233<br />Fax: +61 7 5579 2234<br />Web: <a href='http://www.dataaspects.com.au' target='_blank'>www.dataaspects.com.au</a>");
	
	thehtml += "<div style='height: 10px; background: #fff url(../images/grey_top.gif) no-repeat top left;'></div>";
	thehtml += "<div style='padding:0px 10px; background: #fff url(../images/grey_middle.gif) repeat-y top left;'>";
	thehtml += "<table style='width: 395px'cellspacing='0' cellpadding='0' border='0'><tr>";
	switch(picker) {
		case "amateo":
			thehtml += "<td class='textl'>"+address1[0]+"</td>";
			thehtml += "<td class='textr'>"+address1[1]+"</td>";
			break;
		case "gb":
			thehtml += "<td class='textl'>"+address2[0]+"</td>";
			thehtml += "<td class='textr'>"+address2[1]+"</td>";
			break;	
		case "dq":
			thehtml += "<td class='textl'>"+address3[0]+"</td>";
			thehtml += "<td class='textr'>"+address3[1]+"</td>";
			thehtml += "</tr><tr><td><br /></td></tr><tr>";
			thehtml += "<td class='textl'>"+address3[2]+"</td>";
			thehtml += "<td class='textr'>"+address3[3]+"</td>";			
			break;	
		case "wipro":
			thehtml += "<td class='textl'>"+address4[0]+"</td>";
			thehtml += "<td class='textr'>"+address4[1]+"</td>";
			thehtml += "</tr><tr><td><br /></td></tr><tr>";
			thehtml += "<td class='textl'>"+address4[2]+"</td>";
			thehtml += "<td class='textr'>"+address4[3]+"</td>";
			thehtml += "</tr><tr><td><br /></td></tr><tr>";
			thehtml += "<td class='textl'>"+address4[4]+"</td>";
			thehtml += "<td class='textr'>"+address4[5]+"</td>";				
			break;	
		case "theikos":
			thehtml += "<td class='textl'>"+address5[0]+"</td>";
			thehtml += "<td class='textr'>"+address5[1]+"</td>";
			thehtml += "</tr><tr><td><br /></td></tr><tr>";
			thehtml += "<td class='textl'>"+address5[2]+"</td>";
			thehtml += "<td class='textr'>"+address5[3]+"</td>";
			thehtml += "</tr><tr><td><br /></td></tr><tr>";
			thehtml += "<td class='textl'>"+address5[4]+"</td>";
			thehtml += "<td class='textr'>"+address5[5]+"</td>";				
			break;	
		case "freelance":
			thehtml += "<td class='textl'>"+address6[0]+"</td>";
			thehtml += "<td class='textr'>"+address6[1]+"</td>";
			break;			
		case "daspects":
			thehtml += "<td class='textl'>"+address7[0]+"</td>";
			thehtml += "<td class='textr'>"+address7[1]+"</td>";
			break;
		
	}
	thehtml += "</tr></table>";
	thehtml += "</div>";
	thehtml += "<div style='height: 10px; background: #fff url(../images/grey_bottom.gif) no-repeat top left;'></div>";	
	document.getElementById("pbox").innerHTML = thehtml;
}


function openprivacy() {
	
	opener.location = "/?pn=onlineprivacypolicy";
	this.close();


}

function od_openhelp(refr) {
	var utl = "odhelp.php?id="+refr+"";
	popitup(utl);
}

var newwindow = '';

function popitup(url) {
	if (!newwindow.closed && newwindow.location) {
		newwindow.location.href = url;
	}
	else {
		newwindow=window.open(url,'name','height=250,width=380,toolbar=no,scrollbars=no,menubar=no');
		if (!newwindow.opener) newwindow.opener = self;
	}
	if (window.focus) {newwindow.focus()}
	return false;
}