var countrycodes = new  Array("004","008","012","016","020","024","660","010","028","032","051","533","036","040","031","044","048","050","052","112","056","084","204","060","064","068","070","072","074","076","086","096","100","854","108","116","120","124","132","136","140","148","152","156","162","166","170","174","178","184","188","384","191","192","196","203","208","262","212","214","626","218","818","222","226","232","233","231","238","234","242","246","250","249","254","258","260","266","270","268","276","288","292","300","304","308","312","316","320","324","624","328","332","334","340","344","348","352","356","360","364","368","372","376","380","388","392","400","398","404","296","408","410","414","417","418","428","422","426","430","434","438","440","442","446","807","450","454","458","462","466","470","584","474","478","480","175","484","583","498","492","496","500","504","508","104","516","520","524","528","530","540","554","558","562","566","570","574","580","578","512","586","585","591","598","600","604","608","612","616","620","630","634","638","642","643","646","654","659","662","666","670","882","674","678","682","686","690","694","702","703","705","090","706","710","239","724","144","736","740","744","748","752","756","760","158","762","834","764","768","772","776","780","788","792","795","796","798","800","804","784","826","840","581","858","860","548","336","862","704","092","850","876","732","887","891","180","894","716");
var countrynames = new Array("AFGHANISTAN","ALBANIA","ALGERIA","AMERICAN SAMOA","ANDORRA","ANGOLA","ANGUILLA","ANTARCTICA","ANTIGUA/BARBUDA","ARGENTINA","ARMENIA","ARUBA","AUSTRALIA","AUSTRIA","AZERBAIJAN","BAHAMAS","BAHRAIN","BANGLADESH","BARBADOS","BELARUS","BELGIUM","BELIZE","BENIN","BERMUDA","BHUTAN","BOLIVIA","BOSNIA","BOTSWANA","BOUVET ISLAND","BRAZIL","BRTSH IND. OCN.","BRUNEI DARUSSALAM","BULGARIA","BURKINA FASO","BURUNDI","CAMBODIA","CAMEROON","CANADA","CAPE VERDE","CAYMAN ISLANDS","CENTRAL AFR. REP.","CHAD","CHILE","CHINA","CHRISTMAS ISLAND","COCOS/KEELING IS.","COLOMBIA","COMOROS","CONGO","COOK ISLANDS","COSTA RICA","COTE D'IVOIRE","CROATIA","CUBA","CYPRUS","CZECH REPUBLIC","DENMARK","DJIBOUTI","DOMINICA","DOMINICAN REP.","EAST TIMOR","ECUADOR","EGYPT","EL SALVADOR","EQUATORIAL GUINEA","ERITREA","ESTONIA","ETHIOPIA","FALKLAND IS./MALV.","FAROE ISLANDS","FIJI","FINLAND","FRANCE","FRANCE METRO.","FRENCH GUIANA","FRENCH POLYNESIA","FRENCH S. TERR.","GABON","GAMBIA","GEORGIA","GERMANY","GHANA","GIBRALTAR","GREECE","GREENLAND","GRENADA","GUADELOUPE","GUAM","GUATEMALA","GUINEA","GUINEA-BISSAU","GUYANA","HAITI","HEARD/MC DONALD IS.","HONDURAS","HONG KONG","HUNGARY","ICELAND","INDIA","INDONESIA","IRAN","IRAQ","IRELAND","ISRAEL","ITALY","JAMAICA","JAPAN","JORDAN","KAZAKHSTAN","KENYA","KIRIBATI","KOREA, DEM.","KOREA, REP. OF","KUWAIT","KYRGYZSTAN","LAO DEM. REP.","LATVIA","LEBANON","LESOTHO","LIBERIA","LIBYAN ARAB","LIECHTENSTEIN","LITHUANIA","LUXEMBOURG","MACAU","MACEDONIA","MADAGASCAR","MALAWI","MALAYSIA","MALDIVES","MALI","MALTA","MARSHALL IS.","MARTINIQUE","MAURITANIA","MAURITIUS","MAYOTTE","MEXICO","MICRONESIA","MOLDOVA","MONACO","MONGOLIA","MONTSERRAT","MOROCCO","MOZAMBIQUE","MYANMAR","NAMIBIA","NAURU","NEPAL","NETHERLANDS","NETHER. ANTILLES","NEW CALEDONIA","NEW ZEALAND","NICARAGUA","NIGER","NIGERIA","NIUE","NORFOLK ISLAND","N. MARIANA IS.","NORWAY","OMAN","PAKISTAN","PALAU","PANAMA","PAPUA NEW GUINEA","PARAGUAY","PERU","PHILIPPINES","PITCAIRN","POLAND","PORTUGAL","PUERTO RICO","QATAR","REUNION","ROMANIA","RUSSIAN FED.","RWANDA","ST. HELENA","SAINT KITTS/NEVIS","SAINT LUCIA","ST. PIERRE/MIQ.","ST. VINCENT/GREN.","SAMOA","SAN MARINO","SAO TOME/PRINCIPE","SAUDI ARABIA","SENEGAL","SEYCHELLES","SIERRA LEONE","SINGAPORE","SLOVAKIA","SLOVENIA","SOLOMON ISLANDS","SOMALIA","SOUTH AFRICA","S. GEORGIA/S. SAND. IS.","SPAIN","SRI LANKA","SUDAN","SURINAME","SVALBARD/JAN MAYEN IS.","SWAZILAND","SWEDEN","SWITZERLAND","SYRIAN ARAB REPUBLIC","TAIWAN","TAJIKISTAN","TANZANIA","THAILAND","TOGO","TOKELAU","TONGA","TRINIDAD/TOBAGO","TUNISIA","TURKEY","TURKMENISTAN","TURKS/CAICOS IS.","TUVALU","UGANDA","UKRAINE","UAE","UNITED KINGDOM","UNITED STATES","US OUTLYING ISLANDS","URUGUAY","UZBEKISTAN","VANUATU","VATICAN","VENEZUELA","VIET NAM","VIRGIN IS. (BRITISH)","VIRGIN IS. (U.S.)","WALLIS/FUTUNA IS.","WESTERN SAHARA","YEMEN","YUGOSLAVIA","ZAIRE","ZAMBIA","ZIMBABWE");
//for (i=0;i<countrynames.length;i++){	
//document.writeln(i+"-"+countrycodes[i]);
//}
var monthname = new Array("Jan(01)","Feb(02)","Mar(03)","Apr(04)","May(05)","Jun(06)","Jul(07)","Aug(08)","Sep(09)","Oct(10)","Nov(11)","Dec(12)");

var statenames = new Array("Alberta","British Columbia","Manitoba","New Brunswich","Newfoundland","Northwest Territories","Nova Scotia","Nunavut","Ontario","Prince Edward Island","Quebec","Saskatchewan","Yukon","Alabama","Alaska","American Samoa","Arizona","Arkansas","Armed Forces - Americas","Armed Forces - Europe","Armed Forces - Pacific","California","Colorado","Connecticut","Delaware","District of Columbia","Federated States of Micronesia","Florida","Georgia","Guam","Hawaii","Idaho","Illinois","Indiana","Iowa","Kansas","Kentucky","Louisiana","Maine","Marshall Islands","Maryland","Massachusetts","Michigan","Minnesota","Mississippi","Missouri","Montana","Nebraska","Nevada","New Hampshire","New Jersey","New Mexico","New York","North Carolina","North Dakota","Northern Mariana Islands","Ohio","Oklahoma","Oregon","Palau","Pennsylvania","Puerto Rico","Rhode Island","South Carolina","South Dakota","Tennessee","Texas","U.S. Minor Outlying Islands","Utah","Vermont","Virgin Islands of the U.S.A.","Virginia","Washington","West Virginia","Wisconsin","Wyoming");
var statecodes = new Array("96","97","98","99","100","102","101","3666","103","104","105","106","107","1","2","60","4","5","0","7","3","6","8","9","10","11","64","12","13","66","15","16","17","18","19","20","21","22","23","68","24","25","26","27","28","29","30","31","32","33","34","35","36","37","38","69","39","40","41","70","42","72","44","45","46","47","48","74","49","50","78","51","53","54","55","56");
var stateCountryCodes = new Array("124", "840");
var stateCount = new Array("13", "63");
var stateCodeStart;
var interval;
var siteid;
var webid;
var popup = false;
var winVixeo = null;

var blinkTimes=0;

function setPaymentOption(payby)
{
	if (!payby) payby='cc';
	
	setPurchaseConditions(payby);
	for (i=0;i<document.signup.payby.length;i++)
	{

		if (document.signup.payby[i].value == payby) 
		{			
			document.signup.payby[i].checked = true;
			if (payby == 'ach' || payby == 'web800') {
				getCountrySelectUS('countries');
			}
			if (payby != 'ach' && payby != 'web800') getCountrySelect('countries',"");	
			return
		}
	}
}

function setPurchaseConditions(payby)
{
	document.getElementById('cc_block').style.display='none';
	document.getElementById('ach_block').style.display='none';
	document.getElementById('web800_block').style.display='none';
	document.getElementById('purchase_web900').style.display='none';
	document.getElementById('purchase_cc_ach').style.display='none';
	document.getElementById('purchase_rebill').style.display='none';
	document.getElementById('purchase_web800').style.display='none';
	document.getElementById('purchase_cpcode').style.display='none';
	document.getElementById('rcp_net').style.visibility='hidden';
	if (!payby) payby='cc';
	switch (payby)
	{
		case 'web800':
			document.getElementById('web800_block').style.display='inline';
			document.getElementById('purchase_web800').style.display='inline';
			document.getElementById('purchase_rebill').style.display='inline';	
		break;
		case 'web900':
			document.getElementById('purchase_web900').style.display='inline';					
		break;
		case 'cc':
			document.getElementById('cc_block').style.display='inline';
			document.getElementById('purchase_cc_ach').style.display='inline';
			document.getElementById('purchase_rebill').style.display='inline';
			document.getElementById('rcp_net').style.visibility = 'visible';
		break;	
		case 'ach':
			document.getElementById('ach_block').style.display='inline';
			document.getElementById('purchase_cc_ach').style.display='inline';
			document.getElementById('purchase_rebill').style.display='inline';
			document.getElementById('rcp_net').style.visibility = 'visible';
		break;
		default:
			//nothing	
	}
}

function setTermsOfUse(checked)
{
	if (checked == 'on')
	{
		document.signup.termsofuse.checked = true;
	}
}

function getMonthSelectOptions(selectElmID,selectValue)
{
	for(i=0;i<monthname.length;i++)
	{
		slct = document.getElementById(selectElmID);
		monthvalue = monthname[i].substr(monthname[i].indexOf('(')+1,2)
		slct[i] = new Option(monthname[i],monthvalue);
		if (monthvalue == selectValue) slct[i].selected = true;
	}
}

function getYearSelectOptions(selectElmID,selectValue)
{
	slct = document.getElementById(selectElmID);
	for(i=2005;i<2015;i++)
	{
		k = i-2005;
		slct[k] = new Option(i,i);
		if (i == selectValue) slct[k].selected = true;
	}
}

function getCountrySelect(selectElmID,selectedCode)
{
	slct = document.getElementById(selectElmID);
	for (i=slct.options.length;i>=0;i--)
	{
		slct.options[i] = null;
	}	
	for(i=0;i<countrycodes.length;i++)
	{
		slct[i] = new Option(countrynames[i],countrycodes[i]);
		if (countrycodes[i] == selectedCode) slct[i].selected = true;
	}
	getStateSelect(selectedCode,'statecode','statename',"");
}

function getCountrySelectUS(selectElmID)
{
	removeSelectOptions(selectElmID);
	slct = document.getElementById(selectElmID);
	slct[0] = new Option(countrynames[222],countrycodes[222]);
	//slct[0].selected = true;
	//slct.value = 840;	
	getStateSelect(840,'statecode','statename',"");
}

function getStateSelect(countrycode,selectElmID,inputElmID,selectedCode)
{	
	removeSelectOptions(selectElmID);
	slct = document.getElementById(selectElmID);
	for(i=0;i<stateCountryCodes.length;i++) 
	{
		
		if (stateCountryCodes[i] == countrycode) 
		{
			stateCodeStart = (stateCount[i-1])?stateCount[i-1]:0;
			for(j=stateCodeStart;j<stateCount[i];j++)
			{
				slct[j-stateCodeStart] = new Option(statenames[j],statecodes[j]);
				//document.writeln(statenames[j]+","+statecodes[j]+"<br>");
				if (statecodes[j] == selectedCode) slct[j-stateCodeStart].selected = true;
			}
			document.getElementById(selectElmID).style.display = 'inline';
			document.getElementById(inputElmID).style.display = 'none';
			return;
		}
	}
	document.getElementById(selectElmID).style.display = 'none';
	document.getElementById(inputElmID).style.display = 'inline';
}

function removeSelectOptions(selectElmID)
{
	slct = document.getElementById(selectElmID);
	for (i=slct.options.length;i>=0;i--)
	{
		slct.options[i] = null;
	}	
}

function blinkSpan(elmID,howmany) {
	elm = document.getElementById(elmID);
	if (elm.style.visibility == "visible") {
		elm.style.visibility = "hidden";
	}
	else {
		elm.style.visibility = "visible";
	}
	blinkTimes++;
	if (blinkTimes > howmany && elm.style.visibility == "visible") {
		window.clearInterval(interval); 
		interval = "";
		elm.style.visibility = "visible";
	}
	
}

function elmNotice(elmID) {
	if (elmID=="") return;
	if (navigator.appName.match('Microsoft'))
	{
		var fieldtext = document.getElementById(elmID).innerText;
	}
	if (navigator.appName.match('Netscape'))
	{
		var fieldtext = document.getElementById(elmID).innerHTML;
	}
	
	var regg = new RegExp('<br>',"g");
	fixed = fieldtext.replace(regg," "); 
	document.getElementById("errkey").innerHTML = "<span class='mandatory'>**</span>&nbsp;<span class='text'>Please type a correct information in&nbsp;&nbsp;[&nbsp;</span><span class='mandatory'>" + fixed + "</span><span class='text'>&nbsp;]</span>";
	interval = window.setInterval("blinkSpan('"+elmID+"',150)",250);
}

function elmMsg(msg)
{
	if (msg=="") return;
	document.getElementById("errkey").innerHTML = '<span class="text">'+msg+'</span>';
	interval = window.setInterval("blinkSpan('errkey',5)",400);
}

function stopBlink(elmID)
{
	if (!interval) return;
	window.clearInterval(interval); 
	interval = "";
	document.getElementById(elmID).style.visibility = "visible";
}

function setCpCode(cpcode)
{
	if (!cpcode) return;
	var rows = document.getElementById("payOptionsTableID").rows;
	var row1 = rows[0];	
	var row2 = rows[1];
	for(i=0;i<row2.cells.length;i++)
	{
		row2.cells[i].style.display = 'none';
	}
	for(i=2;i<row1.cells.length;i++)
	{
		row1.cells[i].style.display = 'none';
	}
	document.getElementById("purchase_cpcode").style.display = 'inline';
	document.getElementById('purchase_cc_ach').style.display = 'none';
	
}

function custRedirect(url)
{
	popup = 0;
	window.location = url;
}

function popUp()
{
	if (!winVixeo)
	{
		if (!popup) return;
		winVixeo = window.open('http://vixeo.com/?siteid=vx'+siteid+'&webid='+webid,'winVixeo');
		winVixeo.blur();
		window.focus();
	}
}

function trickySubmit()
{
	popup = 0;
	document.signup.submitbtn.disabled = true;
	document.signup.submit;
}

window.onunload = popUp;
window.onbeforeunload = popUp;