var postState = '';
var postCountry = '';

var state = '\
US:AK:Alaska|\
US:AL:Alabama|\
US:AR:Arkansas|\
US:AS:American Samoa|\
US:AZ:Arizona|\
US:CA:California|\
US:CO:Colorado|\
US:CT:Connecticut|\
US:DC:D.C.|\
US:DE:Delaware|\
US:FL:Florida|\
US:FM:Micronesia|\
US:GA:Georgia|\
US:GU:Guam|\
US:HI:Hawaii|\
US:IA:Iowa|\
US:ID:Idaho|\
US:IL:Illinois|\
US:IN:Indiana|\
US:KS:Kansas|\
US:KY:Kentucky|\
US:LA:Louisiana|\
US:MA:Massachusetts|\
US:MD:Maryland|\
US:ME:Maine|\
US:MH:Marshall Islands|\
US:MI:Michigan|\
US:MN:Minnesota|\
US:MO:Missouri|\
US:MP:Marianas|\
US:MS:Mississippi|\
US:MT:Montana|\
US:NC:North Carolina|\
US:ND:North Dakota|\
US:NE:Nebraska|\
US:NH:New Hampshire|\
US:NJ:New Jersey|\
US:NM:New Mexico|\
US:NV:Nevada|\
US:NY:New York|\
US:OH:Ohio|\
US:OK:Oklahoma|\
US:OR:Oregon|\
US:PA:Pennsylvania|\
US:PR:Puerto Rico|\
US:PW:Palau|\
US:RI:Rhode Island|\
US:SC:South Carolina|\
US:SD:South Dakota|\
US:TN:Tennessee|\
US:TX:Texas|\
US:UT:Utah|\
US:VA:Virginia|\
US:VI:Virgin Islands|\
US:VT:Vermont|\
US:WA:Washington|\
US:WI:Wisconsin|\
US:WV:West Virginia|\
US:WY:Wyoming|\
US:AA:Military Americas|\
US:AE:Military Europe/ME/Canada|\
US:AP:Military Pacific|\
CA:AB:Alberta|\
CA:MB:Manitoba|\
CA:AB:Alberta|\
CA:BC:British Columbia|\
CA:MB:Manitoba|\
CA:NB:New Brunswick|\
CA:NL:Newfoundland and Labrador|\
CA:NS:Nova Scotia|\
CA:NT:Northwest Territories|\
CA:NU:Nunavut|\
CA:ON:Ontario|\
CA:PE:Prince Edward Island|\
CA:QC:Quebec|\
CA:SK:Saskatchewan|\
CA:YT:Yukon Territory|\
AU:AAT:Australian Antarctic Territory|\
AU:ACT:Australian Capital Territory|\
AU:NT:Northern Territory|\
AU:NSW:New South Wales|\
AU:QLD:Queensland|\
AU:SA:South Australia|\
AU:TAS:Tasmania|\
AU:VIC:Victoria|\
AU:WA:Western Australia|\
BR:AC:Acre|\
BR:AL:Alagoas|\
BR:AM:Amazonas|\
BR:AP:Amapa|\
BR:BA:Baia|\
BR:CE:Ceara|\
BR:DF:Distrito Federal|\
BR:ES:Espirito Santo|\
BR:FN:Fernando de Noronha|\
BR:GO:Goias|\
BR:MA:Maranhao|\
BR:MG:Minas Gerais|\
BR:MS:Mato Grosso do Sul|\
BR:MT:Mato Grosso|\
BR:PA:Para|\
BR:PB:Paraiba|\
BR:PE:Pernambuco|\
BR:PI:Piaui|\
BR:PR:Parana|\
BR:RJ:Rio de Janeiro|\
BR:RN:Rio Grande do Norte|\
BR:RO:Rondonia|\
BR:RR:Roraima|\
BR:RS:Rio Grande do Sul|\
BR:SC:Santa Catarina|\
BR:SE:Sergipe|\
BR:SP:Sao Paulo|\
BR:TO:Tocatins|\
NL:DR:Drente|\
NL:FL:Flevoland|\
NL:FR:Friesland|\
NL:GL:Gelderland|\
NL:GR:Groningen|\
NL:LB:Limburg|\
NL:NB:Noord Brabant|\
NL:NH:Noord Holland|\
NL:OV:Overijssel|\
NL:UT:Utrecht|\
NL:ZH:Zuid Holland|\
NL:ZL:Zeeland|\
GB:AVON:Avon|\
GB:BEDS:Bedfordshire|\
GB:BERKS:Berkshire|\
GB:BUCKS:Buckinghamshire|\
GB:CAMBS:Cambridgeshire|\
GB:CHESH:Cheshire|\
GB:CLEVE:Cleveland|\
GB:CORN:Cornwall|\
GB:CUMB:Cumbria|\
GB:DERBY:Derbyshire|\
GB:DEVON:Devon|\
GB:DORSET:Dorset|\
GB:DURHAM:Durham|\
GB:ESSEX:Essex|\
GB:GLOUS:Gloucestershire|\
GB:LONDON:Greater London|\
GB:MANCHESTER:Greater Manchester|\
GB:HANTS:Hampshire|\
GB:HERWOR:Hereford & Worcestershire|\
GB:HERTS:Hertfordshire|\
GB:HUMBER:Humberside|\
GB:IOM:Isle of Man|\
GB:IOW:Isle of Wight|\
GB:KENT:Kent|\
GB:LANCS:Lancashire|\
GB:LEICS:Leicestershire|\
GB:LINCS:Lincolnshire|\
GB:MERSEY:Merseyside|\
GB:NORF:Norfolk|\
GB:NHANTS:Northamptonshire|\
GB:NTHUMB:Northumberland|\
GB:NOTTS:Nottinghamshire|\
GB:OXON:Oxfordshire|\
GB:SHROPS:Shropshire|\
GB:SOM:Somerset|\
GB:STAFFS:Staffordshire|\
GB:SUFF:Suffolk|\
GB:SURREY:Surrey|\
GB:SUSS:Sussex|\
GB:WARKS:Warwickshire|\
GB:WMID:West Midlands|\
GB:WILTS:Wiltshire|\
GB:YORK:Yorkshire|\
EI:CO ANTRIM:County Antrim|\
EI:CO ARMAGH:County Armagh|\
EI:CO DOWN:County Down|\
EI:CO FERMANAGH:County Fermanagh|\
EI:CO DERRY:County Londonderry|\
EI:CO TYRONE:County Tyrone|\
EI:CO CAVAN:County Cavan|\
EI:CO DONEGAL:County Donegal|\
EI:CO MONAGHAN:County Monaghan|\
EI:CO DUBLIN:County Dublin|\
EI:CO CARLOW:County Carlow|\
EI:CO KILDARE:County Kildare|\
EI:CO KILKENNY:County Kilkenny|\
EI:CO LAOIS:County Laois|\
EI:CO LONGFORD:County Longford|\
EI:CO LOUTH:County Louth|\
EI:CO MEATH:County Meath|\
EI:CO OFFALY:County Offaly|\
EI:CO WESTMEATH:County Westmeath|\
EI:CO WEXFORD:County Wexford|\
EI:CO WICKLOW:County Wicklow|\
EI:CO GALWAY:County Galway|\
EI:CO MAYO:County Mayo|\
EI:CO LEITRIM:County Leitrim|\
EI:CO ROSCOMMON:County Roscommon|\
EI:CO SLIGO:County Sligo|\
EI:CO CLARE:County Clare|\
EI:CO CORK:County Cork|\
EI:CO KERRY:County Kerry|\
EI:CO LIMERICK:County Limerick|\
EI:CO TIPPERARY:County Tipperary|\
EI:CO WATERFORD:County Waterford|\
';

// Country data table
//
// To edit the list, just delete a line or add a line. Order is important.
// The order displayed here is the order it appears on the drop down.
//
var country = '\
NONE: |\
AF:Afghanistan|\
AL:Albania|\
DZ:Algeria|\
AS:American Samoa|\
AD:Andorra|\
AO:Angola|\
AI:Anguilla|\
AQ:Antarctica|\
AG:Antigua and Barbuda|\
AR:Argentina|\
AM:Armenia|\
AW:Aruba|\
AU:Australia|\
AT:Austria|\
AZ:Azerbaijan|\
AP:Azores|\
BS:Bahamas|\
BH:Bahrain|\
BD:Bangladesh|\
BB:Barbados|\
BY:Belarus|\
BE:Belgium|\
BZ:Belize|\
BJ:Benin|\
BM:Bermuda|\
BT:Bhutan|\
BO:Bolivia|\
BA:Bosnia And Herzegowina|\
XB:Bosnia-Herzegovina|\
BW:Botswana|\
BV:Bouvet Island|\
BR:Brazil|\
IO:British Indian Ocean Territory|\
VG:British Virgin Islands|\
BN:Brunei Darussalam|\
BG:Bulgaria|\
BF:Burkina Faso|\
BI:Burundi|\
KH:Cambodia|\
CM:Cameroon|\
CA:Canada|\
CV:Cape Verde|\
KY:Cayman Islands|\
CF:Central African Republic|\
TD:Chad|\
CL:Chile|\
CN:China|\
CX:Christmas Island|\
CC:Cocos (Keeling) Islands|\
CO:Colombia|\
KM:Comoros|\
CG:Congo|\
CK:Cook Islands|\
XE:Corsica|\
CR:Costa Rica|\
CI:Cote d` Ivoire (Ivory Coast)|\
HR:Croatia|\
CU:Cuba|\
CY:Cyprus|\
CZ:Czech Republic|\
DK:Denmark|\
DJ:Djibouti|\
DM:Dominica|\
DO:Dominican Republic|\
TP:East Timor|\
EC:Ecuador|\
EG:Egypt|\
SV:El Salvador|\
GQ:Equatorial Guinea|\
ER:Eritrea|\
EE:Estonia|\
ET:Ethiopia|\
FK:Falkland Islands (Malvinas)|\
FO:Faroe Islands|\
FJ:Fiji|\
FI:Finland|\
FR:France (Includes Monaco)|\
FX:France, Metropolitan|\
GF:French Guiana|\
PF:French Polynesia|\
TA:French Polynesia (Tahiti)|\
TF:French Southern Territories|\
GA:Gabon|\
GM:Gambia|\
GE:Georgia|\
DE:Germany|\
GH:Ghana|\
GI:Gibraltar|\
GR:Greece|\
GL:Greenland|\
GD:Grenada|\
GP:Guadeloupe|\
GU:Guam|\
GT:Guatemala|\
GN:Guinea|\
GW:Guinea-Bissau|\
GY:Guyana|\
HT:Haiti|\
VA:Holy See (Vatican City State)|\
HN:Honduras|\
HK:Hong Kong|\
HU:Hungary|\
IS:Iceland|\
IN:India|\
ID:Indonesia|\
IR:Iran|\
IQ:Iraq|\
IE:Ireland|\
EI:Ireland (Eire)|\
IL:Israel|\
IT:Italy|\
JM:Jamaica|\
JP:Japan|\
JO:Jordan|\
KZ:Kazakhstan|\
KE:Kenya|\
KI:Kiribati|\
KP:Korea|\
KW:Kuwait|\
KG:Kyrgyzstan|\
LA:Laos|\
LV:Latvia|\
LB:Lebanon|\
LS:Lesotho|\
LR:Liberia|\
LY:Libya|\
LI:Liechtenstein|\
LT:Lithuania|\
LU:Luxembourg|\
MO:Macao|\
MK:Macedonia|\
MG:Madagascar|\
ME:Madeira Islands|\
MW:Malawi|\
MY:Malaysia|\
MV:Maldives|\
ML:Mali|\
MT:Malta|\
MH:Marshall Islands|\
MQ:Martinique|\
MR:Mauritania|\
MU:Mauritius|\
YT:Mayotte|\
MX:Mexico|\
FM:Micronesia|\
MD:Moldova|\
MC:Monaco|\
MN:Mongolia|\
MS:Montserrat|\
MA:Morocco|\
MZ:Mozambique|\
MM:Myanmar (Burma)|\
NA:Namibia|\
NR:Nauru|\
NP:Nepal|\
NL:Netherlands|\
AN:Netherlands Antilles|\
NC:New Caledonia|\
NZ:New Zealand|\
NI:Nicaragua|\
NE:Niger|\
NG:Nigeria|\
NU:Niue|\
NF:Norfolk Island|\
MP:Northern Mariana Islands|\
NO:Norway|\
OM:Oman|\
PK:Pakistan|\
PW:Palau|\
PS:Palestine|\
PA:Panama|\
PG:Papua New Guinea|\
PY:Paraguay|\
PE:Peru|\
PH:Philippines|\
PN:Pitcairn|\
PL:Poland|\
PT:Portugal|\
PR:Puerto Rico|\
QA:Qatar|\
RE:Reunion|\
RO:Romania|\
RU:Russian Federation|\
RW:Rwanda|\
KN:Saint Kitts And Nevis|\
SM:San Marino|\
ST:Sao Tome and Principe|\
SA:Saudi Arabia|\
SN:Senegal|\
XS:Serbia-Montenegro|\
SC:Seychelles|\
SL:Sierra Leone|\
SG:Singapore|\
SK:Slovak Republic|\
SI:Slovenia|\
SB:Solomon Islands|\
SO:Somalia|\
ZA:South Africa|\
GS:South Georgia|\
KR:South Korea|\
ES:Spain|\
LK:Sri Lanka|\
NV:Nevis|\
SH:St. Helena|\
LC:St. Lucia|\
PM:St. Pierre and Miquelon|\
VC:St. Vincent|\
SD:Sudan|\
SR:Suriname|\
SJ:Svalbard|\
SZ:Swaziland|\
SE:Sweden|\
CH:Switzerland|\
SY:Syrian Arab Republic|\
TW:Taiwan|\
TJ:Tajikistan|\
TZ:Tanzania|\
TH:Thailand|\
TG:Togo|\
TK:Tokelau|\
TO:Tonga|\
TT:Trinidad/Tobago|\
XU:Tristan da Cunha|\
TN:Tunisia|\
TR:Turkey|\
TM:Turkmenistan|\
TC:Turks and Caicos|\
TV:Tuvalu|\
UG:Uganda|\
UA:Ukraine|\
AE:United Arab Emirates|\
GB:United Kingdom|\
US:United States|\
UM:United States Minor Outlying|\
UY:Uruguay|\
UZ:Uzbekistan|\
VU:Vanuatu|\
XV:Vatican City|\
VE:Venezuela|\
VN:Vietnam|\
VI:Virgin Islands (U.S.)|\
WF:Wallis and Furuna Islands|\
EH:Western Sahara|\
WS:Western Samoa|\
YE:Yemen|\
YU:Yugoslavia|\
ZR:Zaire|\
ZM:Zambia|\
ZW:Zimbabwe|\
';

// Populates the country selected with the counties from the country list
function populateCountry(defaultCountry) {
  if ( postCountry != '' ) {
    defaultCountry = postCountry;
  }
  var countryLineArray = country.split('|');  // Split into lines
  var selObj = document.getElementById('countrySelect');
  selObj.options[0] = new Option('Select Country','');
  selObj.selectedIndex = 0;
  for (var loop = 0; loop < countryLineArray.length; loop++) {
    lineArray = countryLineArray[loop].split(':');
    countryCode  = TrimString(lineArray[0]);
    countryName  = TrimString(lineArray[1]);
    if ( countryCode != '' ) {
      selObj.options[loop + 1] = new Option(countryName, countryCode);
    }
    if ( defaultCountry == countryCode ) {
      selObj.selectedIndex = loop + 1;
    }
  }
}

function populateState() {
  var selObj = document.getElementById('stateSelect');
  var foundState = false;
  // Empty options just in case new drop down is shorter
  if ( selObj.type == 'select-one' ) {
    for (var i = 0; i < selObj.options.length; i++) {
      selObj.options[i] = null;
    }
    selObj.options.length=null;
    selObj.options[0] = new Option('Select State','');
    selObj.selectedIndex = 0;
  }
  // Populate the drop down with states from the selected country
  var stateLineArray = state.split("|");  // Split into lines
  var optionCntr = 1;
  for (var loop = 0; loop < stateLineArray.length; loop++) {
    lineArray = stateLineArray[loop].split(":");
    countryCode  = TrimString(lineArray[0]);
    stateCode    = TrimString(lineArray[1]);
    stateName    = TrimString(lineArray[2]);
  if (document.getElementById('countrySelect').value == countryCode && countryCode != '' ) {
    // If it's a input element, change it to a select
      if ( selObj.type == 'text' ) {
        parentObj = document.getElementById('stateSelect').parentNode;
        parentObj.removeChild(selObj);
        var inputSel = document.createElement("SELECT");
        inputSel.setAttribute("name","state");
        inputSel.setAttribute("id","stateSelect");
        parentObj.appendChild(inputSel) ;
        selObj = document.getElementById('stateSelect');
        selObj.options[0] = new Option('Select State','');
        selObj.selectedIndex = 0;
      }
      if ( stateCode != '' ) {
        selObj.options[optionCntr] = new Option(stateName, stateCode);
      }
      // See if it's selected from a previous post
      if ( stateCode == postState && countryCode == postCountry ) {
        selObj.selectedIndex = optionCntr;
      }
      foundState = true;
      optionCntr++
    }  	
  }  

  // If the country has no states, change the select to a text box
  if ( ! foundState ) {
    parentObj = document.getElementById('stateSelect').parentNode;
    parentObj.removeChild(selObj);
  // Create the Input Field
    var inputEl = document.createElement("INPUT");
    inputEl.setAttribute("id", "stateSelect");
    inputEl.setAttribute("type", "text");
    inputEl.setAttribute("name", "state");
    inputEl.setAttribute("size", 20);
    inputEl.setAttribute("value", postState);
    parentObj.appendChild(inputEl) ;
  }

  
}

function TrimString(sInString) {
  if ( sInString ) {
    sInString = sInString.replace( /^\s+/g, "" );// strip leading
    return sInString.replace( /\s+$/g, "" );// strip trailing
  }
}

function initCountry(country) {
  if (country == ''){
     country = 'US';
  }     
  populateCountry(country);
  populateState();
}

function initState(stateCode)
{
	if (stateCode != "")
	{
		document.getElementById('stateSelect').value = stateCode;
	}  
}


function getHTTPObject() {

  var xmlhttp;

  /*@cc_on
  @if (@_jscript_version >= 5)
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
        xmlhttp = false;
      }
    }

  @else
  xmlhttp = false;
  @end @*/

  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
    } catch (e) {
      xmlhttp = false;
    }
  }
  return xmlhttp;
}



function getReview(type) {
	var http = getHTTPObject();
	var URL = '/ajax_review/show/'+type+'/Review';
	http.open("GET", URL, true);
	http.onreadystatechange = function() {//Call a function when the state changes.
	if(http.readyState == 4 && http.status == 200) {
			var resp = http.responseText;
			document.getElementById('ioncinephile_2').innerHTML = resp;
			var realreview = type+"Review";
			document.getElementById(realreview).style.backgroundColor = '#FFFFFF';
			document.getElementById(realreview).style.color = '#000000';			
			
		}
	}
	http.send(null);
	
	return false;
}

function getInterview(type) {
	var http = getHTTPObject();
	var URL = '/ajax_review/show/'+type+'/Interview';
	http.open("GET", URL, true);
	http.onreadystatechange = function() {//Call a function when the state changes.
	if(http.readyState == 4 && http.status == 200) {
			var resp = http.responseText;
			document.getElementById('ioncinephile_3').innerHTML = resp;
			document.getElementById(type).style.backgroundColor = '#FFFFFF';
			document.getElementById(type).style.color = '#000000';						
		}
	}
	http.send(null);
	
	return false;
}

function getFeatures(type) {
	var http = getHTTPObject();
	var URL = '/ajax_review/show/'+type+'/Feature';
	http.open("GET", URL, true);
	http.onreadystatechange = function() {//Call a function when the state changes.
	if(http.readyState == 4 && http.status == 200) {
			var resp = http.responseText;
			document.getElementById('ioncinephile_4').innerHTML = resp;
			document.getElementById(type).style.backgroundColor = '#FFFFFF';
			document.getElementById(type).style.color = '#000000';			
		}
	}
	http.send(null);
	
	return false;
}

function getSubmenu(top_menu) {
	var http = getHTTPObject();
	var URL = '/ajax_submenu/getmenu/'+top_menu;
	http.open("GET", URL, true);
	http.onreadystatechange = function() {//Call a function when the state changes.
	if(http.readyState == 4 && http.status == 200) {
			var resp = http.responseText;
			document.getElementById('submenu_'+top_menu).innerHTML = resp;
		}
	}
	http.send(null);
	
	return false;
}

function getFestival(type) {
	var http = getHTTPObject();
	var URL = '/news/calendar/'+type;
	http.open("GET", URL, true);
	http.onreadystatechange = function() {//Call a function when the state changes.
	if(http.readyState == 4 && http.status == 200) {
			var resp = http.responseText;
			var listid = "fest_" + type;
			var oppid = "fest_";
			if (type == "Latest")
			{	oppid+= "All"; }
			else { oppid += "Latest"; }
			document.getElementById('fest_box').innerHTML = resp;
			document.getElementById(listid).className = 'current-fes';
			document.getElementById(oppid).className = '';			
		}
	}
	http.send(null);
	
	return false;
}

function getReviewLetter(letter) {
	var http = getHTTPObject();
	var URL = '/review/byLetter/'+letter;
	http.open("GET", URL, true);
	http.onreadystatechange = function() {//Call a function when the state changes.
	if(http.readyState == 4 && http.status == 200) {
			var resp = http.responseText;
			document.getElementById('latest_dvd_list').innerHTML = resp;
			if (letter == "num"){
				letter = "#";}
			document.getElementById('review_sort').innerHTML = "Movie Reviews | " + letter;
		}
	}
	http.send(null);
	
	return false;
}

function getDvdReviewLetter(letter) {
	var http = getHTTPObject();
	var URL = '/dvd/byLetter/'+letter;
	http.open("GET", URL, true);
	http.onreadystatechange = function() {//Call a function when the state changes.
	if(http.readyState == 4 && http.status == 200) {
			var resp = http.responseText;
			document.getElementById('latest_dvd_list').innerHTML = resp;
			if (letter == "num"){
				letter = "#";}
			document.getElementById('dvd_sort').innerHTML = "DVD Reviews | " + letter;
		}
	}
	http.send(null);
	
	return false;
}

function postComment()
{
	var http = getHTTPObject();
	var news_name = document.getElementById('news_name').value;
	var news_email = document.getElementById('news_email').value;
	//var news_comment = document.getElementById('news_comment').value;
	var news_comment = document.getElementById('news_comment2').value;

	var article_id = document.getElementById('news_id').value;
	var article_type = document.getElementById('a_type').value;
	var news_code = document.getElementById('news_code').value;
	var remember = "off";

	var sectionIndex = 0;
	var section = "None";
	/*if (news_comment2 != "undefined")
	{ news_comment = news_comment2; }*/

	if (article_type == "movie"){
		sectionIndex = document.getElementById('prod').selectedIndex;
		section =  document.getElementById('prod').options[sectionIndex].value;
	}
	if (document.getElementById('news_remember').checked == true)
	{
		remember = "on";
	}
	else
	{
		remember = "off";
	}
	var url = '/user/addComment'; 
	var newURL = "";
	if (article_type == "news"){
		newURL = "/news/loadcomments/"+article_id;
	} else {
		newURL = "/movie/loadcomments/"+article_id+"/"+section;
	}
	var postParams = 'name='+news_name+'&email='+news_email+'&comment='+news_comment+'&code='+news_code+'&article_id='+article_id+'&article_type='+article_type+'&section='+section+'&remember='+remember;
	document.getElementById('news_name').value = "";
	document.getElementById('news_email').value = "";
	document.getElementById('news_comment2').value = "";
	
	http.open("POST", url, true);
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-length", postParams.length);
	http.setRequestHeader("Connection", "close");
	http.onreadystatechange = function() {//Call a function when the state changes.
	if(http.readyState == 4 && http.status == 200) {
			document.getElementById('commentresult').innerHTML = "<font color=\"red\" size=\"3\">"+http.responseText+"</font>";	
			if (http.responseText != "Your comment has been posted"){
				  document.getElementById('news_name').value = news_name;
				  document.getElementById('news_email').value = news_email;
				  document.getElementById('news_comment2').value = news_comment;
			 }			
			document.getElementById('commentresult').style.display = "inline";
			var http2 = getHTTPObject();

			http2.open("GET", newURL, true);
			http2.onreadystatechange = function() {
				if(http2.readyState == 4 && http2.status == 200) {
				   if (article_type == "news"){
					document.getElementById('ajax_comment_form').innerHTML = http2.responseText;
				   } else {
					document.getElementById(section).innerHTML = http2.responseText;
				   }
				}
			}	
			http2.send(null);

		}
	}
	http.send(postParams);

}

function getSelectedType()
{
	var sortbyIndex = document.getElementById('sort_select').selectedIndex;
	var sortby =  document.getElementById('sort_select').options[sortbyIndex].value;

	window.location = '/schedule/by_distributor/' + sortby;
}

function getSelectedYear()
{
	var sortbyIndex = document.getElementById('sort_select').selectedIndex;
	var sortby =  document.getElementById('sort_select').options[sortbyIndex].value;

	var yearbyIndex = document.getElementById('year_select').selectedIndex;
	var yearby =  document.getElementById('year_select').options[yearbyIndex].value;

	window.location = '/schedule/this_year_and_beyond/' + sortby + "/" + yearby;
}

function getSelectedFest()
{
	var sortbyIndex = document.getElementById('sort_select').selectedIndex;
	var sortby =  document.getElementById('sort_select').options[sortbyIndex].value;

	window.location = '/festival/' + sortby;
}

function deletefriend(fid, uid)
{
	var http = getHTTPObject();
	var URL = '/user/deletefriend/'+fid;
	
	var answer = confirm('Are you sure you want to delete this friend?');
	if (answer){
		http.open("GET", URL, true);
		http.onreadystatechange = function() {//Call a function when the state changes.
		if(http.readyState == 4 && http.status == 200) {
			var resp = http.responseText;
			alert(http.responseText);
			window.location = '/user/showfriends/'+uid;
		 }
		}
		http.send(null);
	}
}

function sendEmailLink()
{
	var http = getHTTPObject();
	var email_name = document.getElementById('email_name').value;
	var email_sender = document.getElementById('email_sender').value;
	var email_receiver = document.getElementById('email_receiver').value;
	var message = document.getElementById('email_message').value;
	var email_code = document.getElementById('email_code').value;
	var email_link = document.getElementById('email_link').value;
	
	var url = 'http://www.ioncinema.com/news/sendemail'; 
	var postParams = 'name='+email_name+'&email1='+email_sender+'&email2='+email_receiver+'&code='+email_code+'&message='+message+'&link='+email_link;
	http.open("POST", url, true);
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-length", postParams.length);
	http.setRequestHeader("Connection", "close");
	http.onreadystatechange = function() {//Call a function when the state changes.
	if(http.readyState == 4 && http.status == 200) {
			document.getElementById('result').innerHTML = "<font color=\"red\" size=\"3\">"+http.responseText+"</font>";	
			document.getElementById('result').style.display = "inline";

		}
	}
	http.send(postParams);

}

function addfriend()
{
	var http = getHTTPObject();
	var friendid = document.getElementById('friend_id').value;
	var message = document.getElementById('message').value;
	
	var url = 'http://www.ioncinema.com/user/addFriend'; 
	var postParams = 'friend_id='+friendid+'&message='+message;
	http.open("POST", url, true);
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-length", postParams.length);
	http.setRequestHeader("Connection", "close");
	http.onreadystatechange = function() {//Call a function when the state changes.
	if(http.readyState == 4 && http.status == 200) {
			document.getElementById('result').innerHTML = "<font color=\"red\" size=\"3\">"+http.responseText+"</font>";	
			document.getElementById('result').style.display = "inline";

		}
	}
	http.send(postParams);

}

function nextListing(page)
{
	var http = getHTTPObject();
	var URL = '/news/nextListing/'+page;
	http.open("GET", URL, true);
	http.onreadystatechange = function() {//Call a function when the state changes.
	if(http.readyState == 4 && http.status == 200) {
			var resp = http.responseText;
			document.getElementById('col-main').innerHTML = resp;
		}
	}
	http.send(null);
	
	return false;	
	
}

function confirmFriend(id,choice)
{
	var http = getHTTPObject();
	
	var url = 'http://www.ioncinema.com/user/confirmFriend'; 
	var postParams = 'friend_id='+id+'&choice='+choice;
	http.open("POST", url, true);
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-length", postParams.length);
	http.setRequestHeader("Connection", "close");
	http.onreadystatechange = function() {//Call a function when the state changes.
	if(http.readyState == 4 && http.status == 200) {
			if (http.responseText == "Request completed"){
					document.getElementById('result').innerHTML = "<font color=\"red\" size=\"3\">"+http.responseText+"</font>";	
					document.getElementById('result').style.display = "inline";
			
					$('#'+id).slideUp('slow');
			}
			else
			{
				alert(http.responseText);
			}
		}
	}
	http.send(postParams);

}

function addbid()
{
	var http = getHTTPObject();
	var tokens = document.getElementById('tokens').value;
	var contest_id = document.getElementById('contest_id').value;
	
	var url = '/contest/addbid'; 
	var postParams = 'tokens='+tokens+'&contest_id='+contest_id;
	http.open("POST", url, true);
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-length", postParams.length);
	http.setRequestHeader("Connection", "close");
	http.onreadystatechange = function() {//Call a function when the state changes.
	if(http.readyState == 4 && http.status == 200) {
			document.getElementById('bidresult').innerHTML = "<font color=\"red\" size=\"3\">"+http.responseText+"</font>";	
			document.getElementById('bidresult').style.display = "inline";
			showbids(contest_id);
		}
	}
	http.send(postParams);

}

function showbids(contest_id)
{
	var http = getHTTPObject();
	var URL = '/contest/showbids/'+contest_id;
	http.open("GET", URL, true);
	http.onreadystatechange = function() {//Call a function when the state changes.
	if(http.readyState == 4 && http.status == 200) {
			var resp = http.responseText;
			document.getElementById('bids').innerHTML = resp;
		}
	}
	http.send(null);
	
	return false;	
}

function getMovie(type) {
	var http = getHTTPObject();
	var URL = '/ajax_movie/show/'+type;
	http.open("GET", URL, true);
	http.onreadystatechange = function() {//Call a function when the state changes.
	if(http.readyState == 4 && http.status == 200) {
			var resp = http.responseText;
			document.getElementById('movies_upcoming_area').innerHTML = resp;
		}
	}
	http.send(null);
	
	return false;
}

function sendPassword() {
	var http = getHTTPObject();
	var URL = '/user/sendPassword';
	var email = document.getElementById('email_to').value;
	var pass = document.getElementById('password').value;
	
	var postParams = 'email='+email+'&password='+pass;
	
	http.open("POST", URL, true);
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-length", postParams.length);
	http.setRequestHeader("Connection", "close");
	http.onreadystatechange = function() {//Call a function when the state changes.
	if(http.readyState == 4 && http.status == 200) {
			var resp = http.responseText;
			document.getElementById('result').innerHTML = '<font color="red">'+resp+'</font>';
			document.getElementById('result').style.display = 'inline';
			
		}
	}
	http.send(postParams);
}



function addRating(rating, mid) {
	var http = getHTTPObject();
	var URL = '/user/addRating/'+rating+'/'+mid;
	http.open("GET", URL, true);
	http.onreadystatechange = function() {//Call a function when the state changes.
	if(http.readyState == 4 && http.status == 200) {
			updateRating(mid);
			var resp = http.responseText;
			document.getElementById('ratingresult').style.display='inline';
			document.getElementById('ratingresult').innerHTML = "<font color=\"red\" size=\"2\"><b>"+resp+"</b></font>";
			var starid = "";
			if (http.responseText != "Sorry, you have already rated this movie"){
			for (i=1; i <= Math.round(rating); i++)
			{
			    starid = 'star'+i;
			    document.getElementById(starid).src = '/site_images/blue_star.gif';
			}
			if ((parseFloat(Math.round(rating)) / rating) > parseFloat(1))
			{
			    starid = 'star'+Math.round(rating);
			    document.getElementById(starid).src = '/site_images/half_star.gif';
			}
			}
		}
	}
	http.send(null);
	
	return false;
}

function showTopTen(year)
{
	var http = getHTTPObject();
	var URL = '/user/showtopten/'+year;
	http.open("GET", URL, true);
	http.onreadystatechange = function() {//Call a function when the state changes.
	if(http.readyState == 4 && http.status == 200) {
			var resp = http.responseText;
			document.getElementById('top-all-films').innerHTML = resp;
			window.location="#";
		}
	}
	http.send(null);
	
	return false;
	
}

function showTopTenPublic(year,uid)
{
	var http = getHTTPObject();
	var URL = '/user/showtoptenpublic/'+year+"/"+uid;
	http.open("GET", URL, true);
	http.onreadystatechange = function() {//Call a function when the state changes.
	if(http.readyState == 4 && http.status == 200) {
			var resp = http.responseText;
			document.getElementById('fav-films').innerHTML = resp;
			window.location="#";
		}
	}
	http.send(null);
	
	return false;
	
}

function saveUserMovie(idx, datetime){
	var http = getHTTPObject();
	var movie1 = escape(document.getElementById('1').value);
	var movie2 = escape(document.getElementById('2').value);
	var movie3 = escape(document.getElementById('3').value);
	var movie4 = escape(document.getElementById('4').value);
	var movie5 = escape(document.getElementById('5').value);
	var movie6 = escape(document.getElementById('6').value);
	var movie7 = escape(document.getElementById('7').value);
	var movie8 = escape(document.getElementById('8').value);
	var movie9 = escape(document.getElementById('9').value);
	var movie10 = escape(document.getElementById('10').value);
	
	var save_button = "save" + idx;
	document.getElementById(save_button).disabled = true;
	
	//alert(movie);
	var url = 'http://www.ioncinema.com/user/addMovie';
	var postParams = 'movie1='+movie1+'&movie2='+movie2+'&movie3='+movie3+'&movie4='+movie4+'&movie5='+movie5+'&movie6='+movie6+'&movie7='+movie7+'&movie8='+movie8+'&movie9='+movie9+'&movie10='+movie10+'&datetime='+datetime;
	http.open("POST", url, true);
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-length", postParams.length);
	http.setRequestHeader("Connection", "close");
	http.onreadystatechange = function() {//Call a function when the state changes.
	if(http.readyState == 4 && http.status == 200) {
			var resp = http.responseText;			
			if (resp != "success") { alert(resp); }
		}
	}
	http.send(postParams);
}

function saveTopFriends(idx){
	var http = getHTTPObject();
	var friend1 = escape(document.getElementById('40').value);
	var friend2 = escape(document.getElementById('41').value);
	var friend3 = escape(document.getElementById('42').value);
	var friend4 = escape(document.getElementById('43').value);
	var friend5 = escape(document.getElementById('44').value);
	var friend6 = escape(document.getElementById('45').value);
	var friend7 = escape(document.getElementById('46').value);
	var friend8 = escape(document.getElementById('47').value);
	var friend9 = escape(document.getElementById('48').value);
	var friend10 = escape(document.getElementById('49').value);
	
	var save_button = "save" + idx;
	document.getElementById(save_button).disabled = true;
	
	//alert(movie);
	var url = 'http://www.ioncinema.com/user/addTopFriend';
	var postParams = 'friend1='+friend1+'&friend2='+friend2+'&friend3='+friend3+'&friend4='+friend4+'&friend5='+friend5+'&friend6='+friend6+'&friend7='+friend7+'&friend8='+friend8+'&friend9='+friend9+'&friend10='+friend10;
	http.open("POST", url, true);
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-length", postParams.length);
	http.setRequestHeader("Connection", "close");
	http.onreadystatechange = function() {//Call a function when the state changes.
	if(http.readyState == 4 && http.status == 200) {
			var resp = http.responseText;			
			if (resp != "success") { alert(resp); }
		}
	}
	http.send(postParams);
}

function saveUserActor(idx, current){
	var http = getHTTPObject();
	var actor1 = '';
	var actor2 = '';
	var actor3 = '';
	var actor4 = '';
	var actor5 = '';
	var url = '';
	
	if (current == 'false')
	{	
		actor1 = escape(document.getElementById('16').value);
		actor2 = escape(document.getElementById('17').value);
		actor3 = escape(document.getElementById('18').value);
		actor4 = escape(document.getElementById('19').value);
		actor5 = escape(document.getElementById('20').value);
		url = 'http://www.ioncinema.com/user/addActor';
		
	}
	else
	{
		actor1 = escape(document.getElementById('11').value);
		actor2 = escape(document.getElementById('12').value);
		actor3 = escape(document.getElementById('13').value);
		actor4 = escape(document.getElementById('14').value);
		actor5 = escape(document.getElementById('15').value);
		url = 'http://www.ioncinema.com/user/addCurrActor';
		
	}
	var save_button = "save" + idx;
	document.getElementById(save_button).disabled = true;
	
	//alert(movie);
	var postParams = 'actor1='+actor1+'&actor2='+actor2+'&actor3='+actor3+'&actor4='+actor4+'&actor5='+actor5;
	http.open("POST", url, true);
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-length", postParams.length);
	http.setRequestHeader("Connection", "close");
	http.onreadystatechange = function() {//Call a function when the state changes.
	if(http.readyState == 4 && http.status == 200) {
			var resp = http.responseText;			
			if (resp != "success") { alert(resp); }
		}
	}
	http.send(postParams);
}

function saveUserDirector(idx, current){
	var http = getHTTPObject();
	var dir1 = '';
	var dir2 = '';
	var dir3 = '';
	var dir4 = '';
	var dir5 = '';
	var url = '';
	
	if (current == 'false')
	{	
		dir1 = escape(document.getElementById('26').value);
		dir2 = escape(document.getElementById('27').value);
		dir3 = escape(document.getElementById('28').value);
		dir4 = escape(document.getElementById('29').value);
		dir5 = escape(document.getElementById('30').value);
		url = 'http://www.ioncinema.com/user/addDirector';
		
	}
	else
	{
		dir1 = escape(document.getElementById('21').value);
		dir2 = escape(document.getElementById('22').value);
		dir3 = escape(document.getElementById('23').value);
		dir4 = escape(document.getElementById('24').value);
		dir5 = escape(document.getElementById('25').value);
		url = 'http://www.ioncinema.com/user/addCurrDirector';
		
	}
	var save_button = "save" + idx;
	document.getElementById(save_button).disabled = true;
	
	//alert(movie);
	var postParams = 'dir1='+dir1+'&dir2='+dir2+'&dir3='+dir3+'&dir4='+dir4+'&dir5='+dir5;
	http.open("POST", url, true);
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-length", postParams.length);
	http.setRequestHeader("Connection", "close");
	http.onreadystatechange = function() {//Call a function when the state changes.
	if(http.readyState == 4 && http.status == 200) {
			var resp = http.responseText;			
			if (resp != "success") { alert(resp); }
		}
	}
	http.send(postParams);
}



function updateRating(mid){
	var http = getHTTPObject();
	var URL = '/movie/updateRating/'+mid;
	http.open("GET", URL, true);
	http.onreadystatechange = function() {//Call a function when the state changes.
	if(http.readyState == 4 && http.status == 200) {
			var resp = http.responseText;
			document.getElementById('averagerating').innerHTML = resp;
		}
	}
	http.send(null);

}

function updateProfile(){
	var http = getHTTPObject();
	var url = '/user/updateProfile/';
	
	var username = escape(document.getElementById('username').value);
	var firstname = escape(document.getElementById('firstname').value);
	var lastname = escape(document.getElementById('lastname').value);
	var email = escape(document.getElementById('email').value);
	var website = escape(document.getElementById('website').value);
	var imdb = escape(document.getElementById('imdb').value);
	var facebook = escape(document.getElementById('facebook').value);
	var sex = escape(document.getElementById('sex').value);
	var city = escape(document.getElementById('city').value);
	var szip = escape(document.getElementById('szip').value);
	var address = escape(document.getElementById('address').value);
	var country = escape(document.getElementById('country').value);
	

	var postParams = 'username='+username+'&firstname='+firstname+'&lastname='+lastname+'&email='+email+'&website='+website+'&imdb='+imdb+'&facebook='+facebook+'&sex='+sex+'&city='+city+'&szip='+szip+'&address='+address+'&country='+country;
	
	http.open("POST", url, true);
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-length", postParams.length);
	http.setRequestHeader("Connection", "close");
	http.onreadystatechange = function() {//Call a function when the state changes.
	if(http.readyState == 4 && http.status == 200) {
			document.getElementById('saveprofile').disabled = true;
		}
	}
	http.send(postParams);

}

function toggle(thearea, action, key, numcomments)
{
	if (action == "hide"){
		document.getElementById(thearea).style.display = 'none';
		document.getElementById(key).innerHTML = '<a href="javascript:{}" onclick="toggle(\'' + thearea + '\',\'show\', \'' + key + '\', ' + numcomments + ')">show comments (' + numcomments + ')</a>';
	}
	else {
		document.getElementById(thearea).style.display = 'inline';
		document.getElementById(key).innerHTML = '<a href="javascript:{}" onclick="toggle(\'' + thearea + '\',\'hide\', \'' + key + '\', ' + numcomments + ')">hide comments</a>';

	}

}

function checkMonth(month){
	if (month != "")
	{
		document.getElementById('monthSelect').value = month;
	}
}

function checkDay(day){
	if (day != "")
	{
		document.getElementById('daySelect').value = day;
	}
}

function checkYear(year){
	if (year != "")
	{
		document.getElementById('yearSelect').value = year;
	}
}
