function getXMLHTTP()
{
	var Connection = null;
	
	try
	{
		Connection = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			Connection = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(oc)
		{
			Connection = null;
		}
	}
	
	if(!Connection && typeof XMLHttpRequest != "undefined")
	{
		Connection = new XMLHttpRequest();
	}
		return Connection;
}

var _xmlHttp = null;

function CallData(Rb)
{
	if(_xmlHttp && _xmlHttp.readyState != 0)
	{
		_xmlHttp.abort();
	}
		_xmlHttp = getXMLHTTP();
	
	if(_xmlHttp)
	{
		_xmlHttp.open("GET","query.php?ID="+Rb+"&"+(new Date().getTime()),true);
		_xmlHttp.setRequestHeader("Cache-Control","no-cache");
		_xmlHttp.setRequestHeader("Pragma", "no-cache");
		_xmlHttp.onreadystatechange = function()
		{
			if(_xmlHttp.readyState == 4 && _xmlHttp.responseText)
			{
				document.getElementById("content").innerHTML = _xmlHttp.responseText;
			}
		}
			_xmlHttp.send(null);
	}
}

function sendData(act)
{
	var obj = document.forms["Client"].elements;
  
	if(_xmlHttp && _xmlHttp.readyState != 0)
	{
		_xmlHttp.abort();
	}
		_xmlHttp = getXMLHTTP();
	
	if(_xmlHttp)
	{
    
		_xmlHttp.open("POST", "query.php?"+(new Date().getTime()),true);
		_xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    
		if(act == '1')
		{
			len = obj["SelectedCountry"].options.length;
			countryData = "&SelectedCountries=";
			for(i = 0; i < len; i++)
			{
				if(i > 0)
					countryData += ','+obj["SelectedCountry"].options[i].value;
				else
					countryData += obj["SelectedCountry"].options[i].value;
			}

			replaceDomain = obj["Domain"].value;
			replaceDomain = escape(replaceDomain);
			replaceDomain = replaceDomain.replace('+', '%2B');
			replaceDomain = replaceDomain.replace('%20', '+');
			replaceDomain = replaceDomain.replace('*', '%2A');
			replaceDomain = replaceDomain.replace('/', '%2F');
			replaceDomain = replaceDomain.replace('@', '%40');

			_xmlHttp.send("act=1"+countryData+"&Domain="+replaceDomain+"&Keywords="+obj["Keywords[1]"].value+","+obj["Keywords[2]"].value+","+obj["Keywords[3]"].value+","+obj["Keywords[4]"].value+","+obj["Keywords[5]"].value+"&Firstname="+obj["Firstname"].value+"&Lastname="+obj["Lastname"].value+"&BusinessName="+obj["BusinessName"].value+"&E-Mail="+obj["E-Mail"].value+"&SecondaryE-Mail="+obj["SecondaryE-Mail"].value+"&Country="+obj["Country"].value+"&State="+obj["State"].value+"&WebLanguages="+obj["WebLanguages"].value+"&TypeOfSite="+obj["TypeOfSite"].value+"&Transaction="+obj["Transaction"].value);
		}
		else if(act == '2')
		{
			_xmlHttp.send("act=2&Firstname="+obj["Firstname"].value+"&Lastname="+obj["Lastname"].value+"&BusinessName="+obj["BusinessName"].value+"&E-Mail="+obj["E-Mail"].value+"&SecondaryE-Mail="+obj["SecondaryE-Mail"].value+"&Country="+obj["Country"].value+"&State="+obj["State"].value+"&TypeOfSite="+obj["TypeOfSite"].value);
		}
		else if(act == '3')
		{
			_xmlHttp.send("act=3&type="+obj["type"].value+"&UserID="+obj["UserID"].value+"&Password="+obj["Password"].value);
		}
		else if(act == '4')
		{
			_xmlHttp.send("act=4&Firstname="+obj["Firstname"].value+"&Lastname="+obj["Lastname"].value+"&E-Mail="+obj["E-Mail"].value+"&SecondaryE-Mail="+obj["SecondaryE-Mail"].value+"&Country="+obj["Country"].value+"&State="+obj["State"].value+"&Phone="+obj["Phone"].value+"&GSM="+obj["GSM"].value+"&Subject="+obj["Subject"].value+"&Message="+obj["Message"].value);
		}
		else if(act == '5')
		{
			_xmlHttp.send("act=5&Check="+obj["Check"].value+"&Firstname="+obj["Firstname"].value+"&Lastname="+obj["Lastname"].value+"&BusinessName="+obj["BusinessName"].value+"&E-Mail="+obj["E-Mail"].value+"&SecondaryE-Mail="+obj["SecondaryE-Mail"].value+"&Country="+obj["Country"].value+"&State="+obj["State"].value+"&TypeOfSite="+obj["TypeOfSite"].value);
		}
		else if(act == '6')
		{
			len = obj["SelectedCountry"].options.length;
			countryData = "&SelectedCountries=";
			for(i = 0; i < len; i++)
			{
				if(i > 0)
					countryData += ','+obj["SelectedCountry"].options[i].value;
				else
					countryData += obj["SelectedCountry"].options[i].value;
			}

			_xmlHttp.send("act=6"+countryData+"&Check="+obj["Check"].value+"&Firstname="+obj["Firstname"].value+"&Lastname="+obj["Lastname"].value+"&BusinessName="+obj["BusinessName"].value+"&E-Mail="+obj["E-Mail"].value+"&SecondaryE-Mail="+obj["SecondaryE-Mail"].value+"&Country="+obj["Country"].value+"&State="+obj["State"].value+"&TypeOfSite="+obj["TypeOfSite"].value);
		}
		else if(act == '7')
		{
			_xmlHttp.send("act=7&Type="+obj["Type"].value+"&E-Mail="+obj["E-Mail"].value);
		}else if(act == '8')
    {     _xmlHttp.send("act=8&firstname="+obj["fname"].value+"&surname="+obj["lname"].value+"&title="+obj["title"].value+"&teaser="+obj["teaser"].value+"&target_url="+obj["target_url"].value+"&payment_type="+obj["payment_type"].value+"&paypal_email1="+obj["paypal_email1"].value+"&paypal="+obj["paypal_1"].value+"&nopaypal_text="+obj["nopaypal_text"].value+"&nopaypal_text2="+obj["nopaypal_text2"].value);
    }

		_xmlHttp.onreadystatechange = function()
		{
			if(_xmlHttp.readyState == 4 && _xmlHttp.responseText)
			{
				if(_xmlHttp.responseText.charAt(0) == "<")
				{
					_timeoutAdjustment--;
				}
				else
					{
						eval(_xmlHttp.responseText);
					}
			}
		}
	}
}

function Set(id)
{
	window.location = "index.php?Menu="+id;
}

var FirstTime = true;

function SetHistory(id)
{
	if(!FirstTime)
	{
		document.getElementById("content").style.textAlign = 'center';
		var ad = new SWFObject("1on40loader.swf?ver=1", "loader", "110", "30", "8", "");
		ad.addParam("wmode", "transparent");
		ad.write("content");

		d = document.getElementById("sotester");

		if(d)
		{
			d.SetVariable("defaultSelection", id-1);
			d.SetVariable("valueChanged", "changed"); 
		}

		if(_xmlHttp && _xmlHttp.readyState != 0)
		{
			_xmlHttp.abort();
		}
			_xmlHttp = getXMLHTTP();
		
		if(_xmlHttp)
		{
			_xmlHttp.open("GET","query.php?Menu="+id+"&"+(new Date().getTime()),true);
			_xmlHttp.setRequestHeader("Cache-Control","no-cache");
			_xmlHttp.setRequestHeader("Pragma", "no-cache");
			_xmlHttp.onreadystatechange = function()
			{
				if(_xmlHttp.readyState == 4 && _xmlHttp.responseText)
				{
					document.getElementById("content").style.textAlign = 'left';
					document.getElementById("content").innerHTML = _xmlHttp.responseText;
					
					b = document.getElementById("fl_banner");

					if(b)
					{
						var so = new SWFObject("1on40_banner_01.swf?id=10", "sotester1", "280", "186", "8", "#ffffff");
						so.write("fl_banner");
					}

				}
			}
				_xmlHttp.send(null);
		}


		window.focus();
	}
	else
	{
		FirstTime = false;
	}
}

function SubSet(id)
{
	document.getElementById("Affcontent").style.textAlign = 'center';
	var ad = new SWFObject("1on40loader.swf?ver=1", "loader", "110", "30", "8", "");
	ad.addParam("wmode", "transparent");
	ad.write("Affcontent");

	if(_xmlHttp && _xmlHttp.readyState != 0)
	{
		_xmlHttp.abort();
	}
		_xmlHttp = getXMLHTTP();
	
	if(_xmlHttp)
	{
		_xmlHttp.open("GET","query.php?Menu="+id+"&"+(new Date().getTime()),true);
		_xmlHttp.setRequestHeader("Cache-Control","no-cache");
		_xmlHttp.setRequestHeader("Pragma", "no-cache");
		_xmlHttp.onreadystatechange = function()
		{
			if(_xmlHttp.readyState == 4 && _xmlHttp.responseText)
			{
				document.getElementById("Affcontent").style.textAlign = 'left';
				document.getElementById("Affcontent").innerHTML = _xmlHttp.responseText;

				b = document.getElementById("fl_banner");

					if(b)
					{
						var so = new SWFObject("1on40_banner_01.swf?id=10", "sotester1", "280", "186", "8", "#ffffff");
						so.write("fl_banner");
					}
			}
		}
			_xmlHttp.send(null);
	}

	window.focus();
}

function RemoveMe(t, go)
{
	if(go == 'no')
	{
		document.getElementById("content").innerHTML = '<h1>You have not been removed</h1>';
	}
	else if(go == 'yes')
	{
		sendData(7);
	}
	else
	{
		document.getElementById("content").innerHTML = '<h1>Are You sure?</h1><p>E-mail: <form name="Client"><input type="hidden" name="Type" value="'+t+'" /><input type="text" name="E-Mail" /></form></p><p><a href="javascript:RemoveMe('+t+',\'yes\')">Yes</a></p><p><a href="javascript:RemoveMe('+t+',\'no\')">No</a></p>';
	}
}

function LostUserOrPWD()
{
	document.getElementById("content").innerHTML = '<h1>For 1on40 to resend your login details, please submit the email address that you signed up with</h1><form name="Client" method="post"><p>E-mail: <input type="hidden" name="X" value="lostpassword" /><input type="text" name="E-Mail" /> <input type="submit" name="send" value="Send" /></p></form>';
}

function RemoveMeDone()
{
	document.getElementById("content").innerHTML = '<h1>You have been removed</h1>';
}

function trim(str)
{
	return str.replace(/^\s*|\s*$/g,"");
}


function regClient()
{
	var obj = document.forms["Client"].elements;

	if(!trim(obj["Keywords[1]"].value) || !trim(obj["Keywords[2]"].value) || !trim(obj["Keywords[3]"].value) || !trim(obj["Keywords[4]"].value) || !trim(obj["Keywords[5]"].value))
	{
		window.location.href = "#keywords";
		alert("All fields marked with an asterisk (*) are mandatory");
		
		return;
	}

	if(!trim(obj["Domain"].value))
	{
		window.location.href = "#data";
		alert("Please make sure that you filled domain name");
		return;
	}

	if(obj["Domain"].value != obj["ConfirmDomain"].value)
	{
		window.location.href = "#data";
		alert("Please make sure that your domain names are the same");
		return;
	}

	if(!trim(obj["Firstname"].value) || !trim(obj["Lastname"].value))
	{
		window.location.href = "#data";
		alert("All fields marked with an asterisk (*) are mandatory");

		return;
	}

	if(!trim(obj["E-Mail"].value))
	{
		window.location.href = "#data";
		alert("Please make sure that you filled email address");
		return;
	}

	if(obj["E-Mail"].value != obj["ConfirmE-Mail"].value)
	{
		window.location.href = "#data";
		alert("Please make sure that your email addresses are the same");
		return;
	}

	if(obj["SelectedCountry"].selectedIndex >= 0)
	{
		window.location.href = "#data";
		alert("Please make sure that you have selected a Country");
		return;
	}

	if(obj["State"].disabled == false)
	{
		if(obj["State"].options[obj["State"].selectedIndex].text == 'Please select')
		{
			window.location.href = "#data";
			alert("Please make sure that you have selected a State");
			return;
		}
	}

	if(!trim(obj["Transaction"].value))
	{
		window.location.href = "#data";
		alert("All fields marked with an asterisk (*) are mandatory");
		return;
	}

	if(obj["TypeOfSite"].options[obj["TypeOfSite"].selectedIndex].text == 'Please select one')
	{
		window.location.href = "#data";
		alert("Please make sure that you have selected the type of site you operate");
		return;
	}

	if(obj["TypeOfSite"].options[obj["TypeOfSite"].selectedIndex].text == 'Other')
	{
		if(!trim(obj["TypeOfSiteOther"].value))
		{
			window.location.href = "#data";
			alert("Please make sure that you have filled the type of site you operate");
			return;
		}
	}

	if(!trim(obj["WebLanguages"].value))
	{
		window.location.href = "#data";
		alert("All fields marked with an asterisk (*) are mandatory");
		return;
	}

	if(obj["Approve"].checked == false)
	{
		alert("All fields marked with an asterisk (*) are mandatory");

		return;
	}
	
	obj["button"].disabled = true;
	sendData(1);
}

function regAffiliate()
{
	var obj = document.forms["Client"].elements;

	if(!trim(obj["Firstname"].value) || !trim(obj["Lastname"].value))
	{
		alert("All fields marked with an asterisk (*) are mandatory");

		return;
	}

	if(!trim(obj["E-Mail"].value))
	{
		alert("Please make sure that you filled email address");
		return;
	}

	if(obj["E-Mail"].value != obj["ConfirmE-Mail"].value)
	{
		alert("Please make sure that your email addresses are the same");
		return;
	}

	if(obj["Country"].options[obj["Country"].selectedIndex].text == 'Please Select')
	{
		alert("Please make sure that you have selected a Country");
		return;
	}

	if(obj["State"].disabled == false)
	{
		if(obj["State"].options[obj["State"].selectedIndex].text == 'Please select')
		{
			alert("Please make sure that you have selected a State");
			return;
		}
	}

	obj["button"].disabled = true;

	sendData(2);
}

var contentInfo = "";

function successful(info)
{
	contentInfo = info;
	document.getElementById("content").style.textAlign = 'center';
	var ad = new SWFObject("1on40_submitter.swf?ver=2", "loader", "250", "30", "8", "");
	ad.addParam("wmode", "transparent");
	ad.addVariable("myId", "'asd'");
	ad.write("content");
}

function cr(inf)
{
	document.getElementById("content").style.textAlign = 'left';
	document.getElementById("content").innerHTML = contentInfo;
}

function successfulAff(info)
{
	document.getElementById("content").innerHTML = info;
}
function successfulBApp(info)
{
	if(document.getElementById("Affcontent"))
		document.getElementById("Affcontent").innerHTML = info;
	else
		document.getElementById("content").innerHTML = info;
}
function Login()
{
	document.forms["Client"].submit();
}

function errLogin()
{
	document.getElementById("msg").innerHTML = '<p>Wrong UserID or Password!</p>';
}

function LoginDone(f, l)
{
	Set(7);
}

function SendMail()
{
	var obj = document.forms["Client"].elements;

	if(!trim(obj["Firstname"].value) || !trim(obj["Lastname"].value))
	{
		alert("All fields marked with an asterisk (*) are mandatory");
		return;
	}

	if(!trim(obj["E-Mail"].value))
	{
		alert("Please make sure that you filled email address");
		return;
	}

	if(obj["E-Mail"].value != obj["ConfirmE-Mail"].value)
	{
		alert("Please make sure that your email addresses are the same");
		return;
	}

	if(obj["Country"].options[obj["Country"].selectedIndex].text == 'Please Select')
	{
		alert("Please make sure that you have selected a Country");
		return;
	}

	if(obj["State"].disabled == false)
	{
		if(obj["State"].options[obj["State"].selectedIndex].text == '-')
		{
			alert("Please make sure that you have selected a State");
			return;
		}
	}

	if(obj["Confirm"].checked == false)
	{
		alert("If you have unchecked the permissions acceptance tick box we are unable to process your contact request");
		return;
	}

	if(!trim(obj["Subject"].value) || !trim(obj["Message"].value))
	{
		alert("All fields marked with an asterisk (*) are mandatory");
		return;
	}

	sendData(4);
}

function msgSent()
{
	document.forms["Client"].reset();
	window.location.href = "#top";
	document.getElementById("msg").innerHTML = '<p>Thank you for contacting 1on40, someone will be in contact with you shortly</p>';
}

function updateAffiliate()
{
	var obj = document.forms["Client"].elements;

	if(!trim(obj["Firstname"].value) || !trim(obj["Lastname"].value) || !trim(obj["E-Mail"].value))
	{
		alert("All fields marked with an asterisk (*) are mandatory");

		return;
	}

	sendData(5);
}

function updateClient()
{
	var obj = document.forms["Client"].elements;

	if(!trim(obj["Firstname"].value) || !trim(obj["Lastname"].value) || !trim(obj["E-Mail"].value))
	{
		alert("All fields marked with an asterisk (*) are mandatory");

		return;
	}

	sendData(6);
}

function updateAffDone()
{
	document.getElementById("msg").innerHTML = '<p>Data Updated Successfully!</p>';
}

function checkCountry()
{
	var obj = document.forms["Client"].elements;

	d = obj["Country"].options[obj["Country"].selectedIndex].value;

	if(d == 225 || trim(d) == 'United States')
	{
		obj["State"].disabled = false;
	}
	else
	{
		obj["State"].selectedIndex = 0;
		obj["State"].disabled = true;
	}
}

function checkTypeOfSite()
{
	var obj = document.forms["Client"].elements;

	d = obj["TypeOfSite"].options[obj["TypeOfSite"].selectedIndex].text;

	if(trim(d) == 'Other')
	{
		document.getElementById("siteOperate").style.display = "";
	}
	else
	{
		document.getElementById("siteOperate").style.display = "none";
	}
}

function doControlMail(msg)
{
	var obj = document.forms["Client"].elements;

	if(obj["button"])
	{
		obj["button"].disabled = false;
	}

	if(msg)
	{
		alert("Your email already exists");
	}
	else
	{
		alert("Check email address!");
	}
}

function chkbnr()
{
	b = document.getElementById("fl_banner");

	if(b)
	{
		var so = new SWFObject("1on40_banner_01.swf?id=10", "sotester1", "280", "186", "8", "#ffffff");
		so.write("fl_banner");
	}
}

var countriesAdded = 0;

function AddSelectItem()
{
	var obj = document.forms["Client"].elements;

	if(obj["Country"].selectedIndex >= 0)
	{
		opText = obj["Country"].options[obj["Country"].selectedIndex].text;
		opValue = obj["Country"].options[obj["Country"].selectedIndex].value;

		if(opValue != "")
		{

			var nElem = document.createElement("OPTION");
			nElem.text = opText;
			nElem.value = opValue;
			obj["SelectedCountry"].options.add(nElem);

			obj["Country"].remove(obj["Country"].selectedIndex);
		}

		if(trim(opText) == 'United States' || trim(opText) == 'Central America' || trim(opText) == 'North America')
		{
			countriesAdded = countriesAdded + 1;
			obj["State"].disabled = false;
		}
	}
}

function RemoveSelectItem()
{
	var obj = document.forms["Client"].elements;
	if(obj["SelectedCountry"].selectedIndex >= 0)
	{
		opText = obj["SelectedCountry"].options[obj["SelectedCountry"].selectedIndex].text;
		opValue = obj["SelectedCountry"].options[obj["SelectedCountry"].selectedIndex].value;

		var nElem = document.createElement("OPTION");
		nElem.text = opText;
		nElem.value = opValue;
		obj["Country"].options.add(nElem);

		obj["SelectedCountry"].remove(obj["SelectedCountry"].selectedIndex);

		if(trim(opText) == 'United States' || trim(opText) == 'Central America' || trim(opText) == 'North America')
		{
			countriesAdded = countriesAdded - 1;
			
			if(countriesAdded < 1)
			{
				obj["State"].selectedIndex = 0;
				obj["State"].disabled = true;
			}
		}
	}
}

function changeDisable(type) {
  var email = document.getElementById('email');
  var email2 = document.getElementById('email2');
  var nopaypal = document.getElementById('nopaypal_input');
  var nopaypal2 = document.getElementById('nopaypal_input2');
  if(type == 'paypal') {
    
      email.style.display = '';
      email2.style.display = '';     
      nopaypal.style.display = 'none';
      nopaypal2.style.display = 'none';
    
  }
  if(type == 'nopaypal') {
    email.style.display = 'none';
    email.value = '';
    email2.value = '';
    email2.style.display = 'none';
    nopaypal.style.display = '';
    nopaypal2.style.display = '';
  }
  
}
function validate() {
  var element = new Array();
  var allow = true;
  element[0] = document.getElementById('title');
  element[1] = document.getElementById('teaser');
  element[2] = document.getElementById('target_url');
  element[3] = document.forms['Client'].elements['payment_type'];
  
  if(element[3][0].checked == true) {
    element[3] = document.forms['Client'].elements['payment_type'][0];
    document.forms['Client'].elements['payment_type'].value = 'Paypal';
    element[4] = document.getElementById('paypal_1');
    element[5] = document.getElementById('paypal_2');
    if(element[4].value != element[5].value) {
      allow = false;
      document.getElementById('payment').innerHTML = document.getElementById('payment').innerHTML+"<br />Paypal E-mails to not match!";
    }
  }else if(element[3][1].checked == true) {
  element[3] = element[3][1];
  document.forms['Client'].elements['payment_type'].value = "nopaypal";
  }else{
  allow = false;
  document.getElementById('payment').innerHTML = document.getElementById('payment').innerHTML+"<br />You have to select a payment type!";
  }  
  
  for (i in element) {
    if(element[i].value == "" || element[i].value == "Missing!") {
      element[i].value = 'Missing!';
      allow = false;
    }
  }
  if(allow == false) {
  return false;
  }else{ 
    document.Client.send.disabled=true;;
    sendData(8);
  }
}

function popupWin(id)
{
	window.open("popup.php?ID="+id,"blank","menubar=no,toolbar=no,scrollbars=yes,width=1024,height=800")
}

function ControlLength(name, maxlen)
{
	if(name.value.length > maxlen)
		name.value = name.value.substring(0,maxlen);
}

function ReadLength(input, output, maxlen)
{
	document.getElementById(output).innerHTML = maxlen - input.value.length;
}

function limitText(limitField,countdown, limitNum) {
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	}
  countdown.innerHTML = limitNum-limitField.value.length;
}