var doSearch=false;
// Get query string data and set as page variables
var sData = new Array();
var sTemp;
var sess = '';
var sQueryString = document.location.search.substr(1);
if(sQueryString!=""){
	var doubles =  sQueryString.split("&");
	for (var i = 0; i < doubles.length; i ++){
		sTemp = doubles[i].split("=");
		window[sTemp[0]] = sTemp[1];
		if((sTemp[0]=='act')&&(sTemp[1]=="search")) {doSearch=true;}
		if((sTemp[0]=='act')&&(sTemp[1]=="absconded")) {doSearch=true;}
		if (doubles[i].indexOf('PHPSESSID')!=-1){
			sess = doubles[i];
		}
	}
}

// Browser detection
var b=navigator.userAgent.toLowerCase();
n_ie_win=((b.indexOf('msie')>0)&&(b.indexOf('windows')>0))?true:false;
n_ie_mac=((b.indexOf('msie')>0)&&(b.indexOf('mac')>0))?true:false;
n_ff_win=((b.indexOf('firefox')>0)&&(b.indexOf('windows')>0))?true:false;
n_ff_mac=((b.indexOf('firefox')>0)&&(b.indexOf('mac')>0))?true:false;
n_s_mac=((b.indexOf('safari')>0)&&(b.indexOf('mac')>0))?true:false;


// Set local domain (dynamically)
var myDomain="http://"+window.location.host;


function goTop() {
	document.location='#';
}

function goHome()  {
	document.location=myDomain;
}


// Functionality for Drop Down Menus
function show(id){
	document.getElementById(id).style.display='block';
}
function hide(id){
	document.getElementById(id).style.display='none';
}

// Change the src of a specific image
function chngIm(newSrc,id){
	document.getElementById(id).src=newSrc
}


// get ICC reports
function getReport(which){
	document.siteform.action=myDomain+"/php/report.php"
	//document.siteform.target='_self';
	document.getElementById('id').value=reg_id
	return true;
}

function checkForm(which){
	var enter=false;
	if(which!="licontact"){
		if(document.getElementById('usr').value!=""){
			enter=true;
			if(document.getElementById('pswrd').value==""){
				alert('Please enter your password.');
				return false;
			}
		}
		if(document.getElementById('pswrd').value!=""){
			enter=true;
			if(document.getElementById('usr').value==""){
				alert('Please enter your username.');
				return false;
			}
		}
		if(enter){
			document.siteform.action=myDomain+'/php/userlogin.php';
			return true;
		}
	}
	var chkList;
	switch(which){
		case 'callmeback':			chkList=new Array('Name','Telephone');break;
		case 'nlicontact':				chkList=new Array('Name');break;
		case 'licontact':				chkList=new Array('Name');break;
		case 'debtrecov':			chkList=new Array('Your_Name');break;
		case 'submitinfo':			chkList=new Array('Address','Trade_Name','Amount');break;
		case 'testimonials':			chkList=new Array('Name','Testimonial');break;
		case 'account':				chkList=new Array('company_name','telephone', 'email');break;
		case 'internetaccess':		chkList=new Array('Name', 'Company_Name', 'Email');break;
		case 'signup':					chkList=new Array('Name', 'Company_Name', 'Telephone', 'Email', 'Password');break;
		case 'free_demo':			chkList=new Array('Email','telephone','heard');break;
		default:							return false; break;
	}
	var msg="";
	for(i in chkList){
		if(document.siteform[chkList[i].toLowerCase()].value=="") msg+="Please complete the field: "+chkList[i].replace(/_/," ")+"\n";
		if(chkList[i]=='email' && !validEmail(document.siteform['email'].value)){
			msg+="The email address entered is not a valid one.\n";
		}
	}
	if(msg!=""){
		alert(msg);
		return false;
	}else return true;
}

function validEmail(email) {
	invalidChars = " /:,;"

	if (email == "") {					
		return false
	}
	for (i=0; i<invalidChars.length; i++) {
		badChar = invalidChars.charAt(i)
		if (email.indexOf(badChar,0) > -1) {
			return false
		}
	}
	atPos = email.indexOf("@",1)			
	if (atPos == -1) {
		return false
	}
	if (email.indexOf("@",atPos+1) != -1) {	
		return false
	}
	periodPos = email.indexOf(".",atPos)
	if (periodPos == -1) {					
		return false
	}
	if (periodPos+3 > email.length)	{
		return false
	}
	return true
}

function checkPass(){
	var msg="";
	if(document.chgpass.oldpass.value=="") msg+="Please enter your Old password\n";
	if(document.chgpass.newpass.value=="") msg+="Please enter your New password\n";
	if(document.chgpass.newpass2.value=="") msg+="Please confirm your New password\n";
	if(msg!=""){alert(msg);return false;}
	return true;
}

function exportWin(type, name){
	var inputboxes = '';
	var doc=window.document;
	var reload = '';

	if ((type=="savePDF" && name!="ICC") || type=="print" || type=="saveHTML"){
		if(doc.getElementById('tsdetails'))doc.getElementById('tsdetails').style.display="inline";
		if(doc.getElementById('swording'))doc.getElementById('swording').style.display="inline";
		if(doc.getElementById('icclist'))doc.getElementById('icclist').style.display="none";
		if(name=="decision4"||name=="ccj"){
			if(doc.getElementById('print_but'))doc.getElementById('print_but').innerHTML="";
			var num = 1;
			while (doc.getElementById('arrow_'+num)){
				doc.getElementById('arrow_'+num).innerHTML="";
				num++;
			}
		}
	}
	var count = 1;
	while (doc.getElementById('score_im_'+count)){
		doc.getElementById('score_im_'+count).innerHTML="";
		count++;
	}
	if (doc.getElementById('tsdetails')){
		doc.getElementById('tsdetails').style.display="inline";
	}

	if (doc.getElementById('inputboxes'))
		{
			inputboxes = doc.getElementById('inputboxes').innerHTML;
			doc.getElementById('inputboxes').innerHTML="";
		}

	var tds=doc.getElementsByTagName("td");
	for(i in tds){
		if(tds[i].className=="tableheader"){
			tds[i].className="printheader";
		}
		if(tds[i].className=="tablecell"){
			tds[i].className="printcell";
		}
	}
	var trs=doc.getElementsByTagName("tr");
	for(i in trs){
		if(trs[i].className=="qlinks"){
			trs[i].style.display="none";
		}
	}
	var tab=doc.getElementsByTagName("table");
	for(i in tab){
		if(tab[i].className=="noborder"){
			tab[i].className="border";
		}
		if(tab[i].className=="qlinks"){
			tab[i].style.display="none";
		}

	}
	var as=doc.getElementsByTagName("a");
	for(i in as){
		if(as[i].style){
			as[i].style.color="black";
		}
	}
	switch(type){
		case 'print':		if (name=='ICC') { window.print(); } break;
		case 'saveHTML':	doc.write("<html>\n<head>\n<title>"+name+"</title>\n</head>\n<body>\n"+doc.getElementById('right').innerHTML+"\n</body></html>");
									doc.close();
									var thepage=name.replace(/\s/g,"_");
									doc.execCommand('SaveAs',true,'TS_'+thepage+'.htm');
									
									break;
		case 'savePDF':		var the_el = (name=="decision4") ? 'report-body' : 'right';
									doc.getElementById('html_source').value="<html>\n<head>\n<title></title>\n</head>\n<body>\n"+doc.getElementById(the_el).innerHTML+"\n</body></html>";
									doc.getElementById('convert').submit();

									if (doc.getElementById('inputboxes')) {
										doc.getElementById('inputboxes').innerHTML=inputboxes;
									}
									if (doc.getElementById('tsdetails')){
										doc.getElementById('tsdetails').style.display="none";
									}
									
									var tds=doc.getElementsByTagName("td");
									for(i in tds){
										if(tds[i].className=="printheader"){
											tds[i].className="tableheader";
										}
										if(tds[i].className=="printcell"){
											tds[i].className="tablecell";
										}
									}
									var trs=doc.getElementsByTagName("tr");
									for(i in trs){
										if(trs[i].className=="qlinks"){
											trs[i].style.display="";
										}
									}
									var tab=doc.getElementsByTagName("table");
									for(i in tab){
										if(tab[i].className=="border"){
											tab[i].className="noborder";
										}
										if(tab[i].className=="qlinks"){
											tab[i].style.display="";
										}
									}
									break;

		default:					break;
	}

}

function printICC(which) {
	var doc=window.document
	doc.getElementById('print_but').innerHTML="";
	if (which == 'decision4')
	{
		var num = 1;
		while (doc.getElementById('arrow_'+num))
		{
			doc.getElementById('arrow_'+num).innerHTML="";
			num++;
		}
	}
	window.print();
}

function CallPrint(strid)
{
var prtContent = document.getElementById(strid);

var WinPrint = window.open('','','left=0, top=0,toolbar=0,status=0, resize=1, scrollbars=1');
WinPrint.document.open();
WinPrint.document.write(prtContent.innerHTML);
WinPrint.document.close();
WinPrint.focus();

var doc=WinPrint.document;
doc.getElementById('print_but').innerHTML="";

var num = 1;
while (doc.getElementById('arrow_'+num))
{
	doc.getElementById('arrow_'+num).innerHTML="";
	num++;
}

WinPrint.print();
}


function printRecord() {
  var divToPrint=document.getElementById('print-area');
  newWin= window.open("");
  newWin.document.write(divToPrint.outerHTML);
	var doc = newWin.document;
	var tds=doc.getElementsByTagName("td");
	for(i in tds){
		if(tds[i].className=="tableheader"){
			tds[i].className="printheader";
		}
		if(tds[i].className=="tablecell"){
			tds[i].className="printcell";
		}
	}
	var trs=doc.getElementsByTagName("tr");
	for(i in trs){
		if(trs[i].className=="qlinks"){
			trs[i].style.display="none";
		}
	}
	var tab=doc.getElementsByTagName("table");
	for(i in tab){
		if(tab[i].className=="noborder"){
			tab[i].className="border";
		}
		if(tab[i].className=="qlinks"){
			tab[i].style.display="none";
		}

	}
	var as=doc.getElementsByTagName("a");
	for(i in as){
		if(as[i].style){
			as[i].style.color="black";
		}
	}
}


function setUrl(){
	document.getElementById('backlink').value=escape(document.location);
	return true;
}

function go(num){
	if((n_ff_mac)||(n_ff_win)||(n_s_mac))history.go(num+2);
	else history.go(num);
}


function gloss(anc) {
	window.open(myDomain+"/Glossary.html#"+anc, "_gloss",'width=790,height=325,left=5,top=5,scrollbars=yes');

}

function chkNum(which){
	if(isNaN(document.getElementById(which).value)){
		alert('Please only enter numbers in the Amount box');
		document.getElementById(which).value=(isNaN(parseFloat(document.getElementById(which).value)))?"":parseFloat(document.getElementById(which).value);
		document.getElementById(which).focus();
		return false;
	}
	return true
}