function preloadImages() { //v1.2
    var imgFiles = preloadImages.arguments;
    var preloadArray = new Array();
    for (var i=0; i<imgFiles.length; i++) {
      preloadArray[i] = new Image;
      preloadArray[i].src = imgFiles[i];
    }
}


function wordcount(textblock,display){
  var y=textblock.value;
  var r = 0;
  a=y.replace('\n',' ');
  a=a.split(' ');
  for (z=0; z<a.length; z++) {
	if (a[z].length > 0) {
	  r++;
	}
  } 
  display.value=r;
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  var win = window.open(theURL,winName,features);
  win.focus();
  return false;
}

function getCities(postcode, form) {
	if((postcode != '') && (postcode.length >= 3)) {
		var pcodeRE = /^[0-9]{3,4}$/;
		if(!pcodeRE.test(postcode)) {
			alert('Invalid postcode entered.');
			form.pcode.focus();
		} else {
		        http.open('POST', '/settings/getcities.pl');
		        http.onreadystatechange = function() { handleGetCitiesResponse(form) };
	        	http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	        	var reqparam = 'pcode=' + postcode;
		        http.send(reqparam);	
		}
	}
}

function clearcities(dropdown) {
  for(var i = (dropdown.options.length-1); i >= 0; i--) {
    dropdown.options[i]=null;
  }
}

function handleGetCitiesResponse(form) {
     if(http.readyState == 4){
        if(http.status == 200) {
	  var dropdown = form.city_id;

	  clearcities(dropdown);
	  
          var responseXML = http.responseXML;

	  var citylist = responseXML.getElementsByTagName("city");
	
	  if(form.cityfilledpcode) {
		form.cityfilledpcode.value = form.pcode;
	  }
	  var citytomatch = -1;
	  if(form.selectedcity_id) {
	  	citytomatch = form.selectedcity_id.value;
	  }

	  for(var i = 0 ; i < citylist.length ; i++) {

	    var city = citylist[i];
	    var cityname = city.getElementsByTagName("cityname")[0].firstChild.nodeValue;
	    var cityid = city.getElementsByTagName("cityid")[0].firstChild.nodeValue;
	    var cityOption = new Option(cityname, cityid);
	    if((citytomatch > 0) && (cityid == citytomatch)) {
		    cityOption.selected = true;
	    } else if(i == 0) {
		    cityOption.selected = true;
	    }
	    dropdown.options[dropdown.options.length] = cityOption;
	  }
	  	  
        } else {
          //AJAXError('Get cities returned ' + http.status);
        }
     }
}


function reportPhoto(photo_id, photoform) {
	http.open('POST', '/reportphoto.shtml');
	http.onreadystatechange = handleReportPhotoResponse;
        http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	var reqparam = 'photo_id=' + photo_id + '&reason=' + photoform.reason.value + '&comments=' + photoform.comments.value;
        http.send(reqparam);
}

function handleReportPhotoResponse() {
     if(http.readyState == 4){
	if(http.status == 200) {
          var responseText = http.responseText;
  	  ReplaceText('reportphoto', responseText);
	  ShowText('reportphoto');
	  HideText('reportphoto_form');
        } else {
	  AJAXError('Report photo returned ' + http.status);
	}
     }
}

function grantPrivatePhotos(user_id, person, person2) {
        http.open('POST', '/grantphotoaccess.shtml');
        http.onreadystatechange = handlegrantPrivatePhotos;
        http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        var reqparam = 'user_id=' + user_id + '&person=' + person + '&person2=' + person2;
        http.send(reqparam);
}

function handlegrantPrivatePhotos() {
     if(http.readyState == 4){
        if(http.status == 200) {
          var responseText = http.responseText;
          ReplaceText('privphotosmessage', responseText);
	}else {
          AJAXError('Grant Private Photos returned ' + http.status);
        }
     }
}

function revokePrivatePhotos(user_id, person, person2) {
        http.open('POST', '/revokephotoaccess.shtml');
        http.onreadystatechange = handlerevokePrivatePhotos;
        http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        var reqparam = 'user_id=' + user_id + '&person=' + person + '&person2=' + person2;
        http.send(reqparam);
}

function handlerevokePrivatePhotos() {
     if(http.readyState == 4){
        if(http.status == 200) {
          var responseText = http.responseText;
          ReplaceText('privphotosmessage', responseText);
	}else {
          AJAXError('Revoke Private Photos returned ' + http.status);
        }
     }
}

function reportCommentForAbuse(comment_id) {
        http.open('POST', '/reportcomment.shtml');
	http.onreadystatechange = handlereportCommentForAbuse;
        http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        var reqparam = 'comment_id=' + comment_id;
        http.send(reqparam);
}

function handlereportCommentForAbuse() {
     if(http.readyState == 4){
        if(http.status == 200) {
          var responseXML = http.responseXML;
          var comment_id = responseXML.getElementsByTagName('comment_id')[0].firstChild.data;
          if(comment_id) {
	      ReplaceText('abusedeletecomment_' + comment_id, responseXML.getElementsByTagName('response')[0].firstChild.data);
          } else {
            alert(responseXML.getElementsByTagName('error')[0].firstChild.data);
          }
        } else {		
          AJAXError('Report Comment For Abuse returned ' + http.status);
        }
     }
  
}


function deleteComment(comment_id) {
        http.open('POST', '/deletecomment.shtml');
	http.onreadystatechange = handledeleteComment;
        http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        var reqparam = 'comment_id=' + comment_id;
        http.send(reqparam);	
}

function handledeleteComment() {
     if(http.readyState == 4){
        if(http.status == 200) {
          var responseXML = http.responseXML;
          var comment_id = responseXML.getElementsByTagName('comment_id')[0].firstChild.data;
	  if(comment_id) {
            ReplaceText('abusedeletecomment_' + comment_id, responseXML.getElementsByTagName('response')[0].firstChild.data);
 	  } else {
	    alert(responseXML.getElementsByTagName('error')[0].firstChild.data);
	  } 
        }else {		
          AJAXError('Delete Comment returned ' + http.status);
        }
     }
  
}

function showLayer(layerid) {
	document.getElementById(layerid).style.visibility = 'visible';
}

function hideLayer(layerid) {
	document.getElementById(layerid).style.visibility = 'hidden';
}


function updateTopMate(user_id, selectbox ) {
	var topmateval = selectbox.value;

        http.open('POST', '/updatetopmate.shtml');
        http.onreadystatechange = function() { handleupdateTopMate(selectbox) };
        http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        var reqparam = 'user_id=' + user_id + '&topmateval=' + topmateval;
        http.send(reqparam);

}

function handleupdateTopMate(selectbox) {
     if(http.readyState == 4){
        if(http.status == 200) {
          var responseXML = http.responseXML;
	  selectbox.className = responseXML.getElementsByTagName('newclass')[0].firstChild.data;
	  ReplaceText('numtopmates', responseXML.getElementsByTagName('nummates')[0].firstChild.data);

	  if(responseXML.getElementsByTagName('reason')[0].hasChildNodes()) {
		alert(responseXML.getElementsByTagName('reason')[0].firstChild.data);
	        // change the value back.
	        selectbox.options[0].selected = true;
	        selectbox.options[0].selected = false;
	  }

        }else {
          AJAXError('Update Top Mate returned ' + http.status);
        }
     }
}


function removeFromFriends(user_id) {
        http.open('POST', '/removefriend.shtml');
        http.onreadystatechange = handleremoveFromFriends;
        http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        var reqparam = 'user_id=' + user_id;
        http.send(reqparam);
}

function handleremoveFromFriends() {
     if(http.readyState == 4){
        if(http.status == 200) {
          var responseText = http.responseText;
  	  ReplaceText('onfriendslistmessage', responseText);	  
	} else {
          AJAXError('Remove From Friends returned  ' + http.status);
       }
     } 
}


function removeFromHotList(user_id) {
        http.open('POST', '/removehotlist.shtml');
        http.onreadystatechange = handleremoveFromHotList;
        http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        var reqparam = 'user_id=' + user_id;
        http.send(reqparam);
}

function handleremoveFromHotList() {
     if(http.readyState == 4){
        if(http.status == 200) {
          var responseText = http.responseText;
  	  ReplaceText('onhotlistmessage', responseText);	  
	} else {
          AJAXError('Remove From Hot List returned  ' + http.status);
	}
     } 
}

function grantActivities(user_id, person, person2) {
        http.open('POST', '/grantactivitiesaccess.shtml');
        http.onreadystatechange = handlegrantActivities;
        http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        var reqparam = 'user_id=' + user_id + '&person=' + person + '&person2=' + person2;
        http.send(reqparam);
}

function handlegrantActivities() {
     if(http.readyState == 4){
        if(http.status == 200) {
          var responseText = http.responseText;
          ReplaceText('activitiesmessage', responseText);
	}else {
          AJAXError('Grant Activities returned ' + http.status);
        }
     }
}

function revokeActivities(user_id, person, person2) {
        http.open('POST', '/revokeactivitiesaccess.shtml');
        http.onreadystatechange = handlerevokeActivities;
        http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        var reqparam = 'user_id=' + user_id + '&person=' + person + '&person2=' + person2;
        http.send(reqparam);
}

function handlerevokeActivities() {
     if(http.readyState == 4){
        if(http.status == 200) {
          var responseText = http.responseText;
          ReplaceText('activitiesmessage', responseText);
	}else {
          AJAXError('Revoke Activities returned ' + http.status);
        }
     }
}

function uncheckFirst(fieldname) {
	document.getElementsByName(fieldname)[0].checked = false;
}

function uncheckAll(fieldname) {
	fieldset = document.getElementsByName(fieldname);
	for (i = 0; i < fieldset.length; i++) {
		fieldset[i].checked = false ;
	}
}

function checkAll(fieldname) {
	fieldset = document.getElementsByName(fieldname);
	for (i = 0; i < fieldset.length; i++) {
		fieldset[i].checked = true;
	}
}


function quoteComment(comment_id, commentmaker, comment) {
	
	ShowText('commentquoting');
	ReplaceText('commentquotename', commentmaker);
	ReplaceText('commentquotetext', comment);
	document.addcomment_form.quoting_comment_id.value = comment_id;

	HideText('commentreply');
	document.addcomment_form.reply_comment_id.value = '';
	
}

function cancelQuoteComment() {
	HideText('commentquoting');
        document.addcomment_form.quoting_comment_id.value = '';
}


function replyComment(comment_id, commentmaker, comment) {
	ShowText('commentreply');
	ReplaceText('commentreplyname', commentmaker);
	ReplaceText('commentreplytext', comment);
	document.addcomment_form.reply_comment_id.value = comment_id;

	HideText('commentquoting');
	document.addcomment_form.quoting_comment_id.value = '';
	
}

function cancelReplyComment() {
        HideText('commentreply');
        document.addcomment_form.reply_comment_id.value = '';
}

function reportBlogCommentForAbuse(comment_id) {
        http.open('POST', '/reportcomment_blog.shtml');
	http.onreadystatechange = handlereportBlogCommentForAbuse;
        http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        var reqparam = 'comment_id=' + comment_id;
        http.send(reqparam);
}

function handlereportBlogCommentForAbuse() {
     if(http.readyState == 4){
        if(http.status == 200) {
          var responseXML = http.responseXML;
          var comment_id = responseXML.getElementsByTagName('comment_id')[0].firstChild.data;
          if(comment_id) {
	      ReplaceText('abusedeletecomment_' + comment_id, responseXML.getElementsByTagName('response')[0].firstChild.data);
          } else {
            alert(responseXML.getElementsByTagName('error')[0].firstChild.data);
          }
        } else {		
          AJAXError('Report Blog Comment For Abuse returned ' + http.status);
        }
     }
  
}


function deleteBlogComment(comment_id) {
	http = createRequestObject();
        http.open('POST', '/deletecomment_blog.shtml');
	http.onreadystatechange = handledeleteBlogComment;
        http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        var reqparam = 'comment_id=' + comment_id;
        http.send(reqparam);	
}

function handledeleteBlogComment() {
     if(http.readyState == 4){
        if(http.status == 200) {
	  var responseXML = http.responseXML;
          var comment_id = responseXML.getElementsByTagName('comment_id')[0].firstChild.data;
	  if(comment_id) {
            ReplaceText('abusedeletecomment_' + comment_id, responseXML.getElementsByTagName('response')[0].firstChild.data);
 	  } else {
	    alert(responseXML.getElementsByTagName('error')[0].firstChild.data);
	  } 
        }else {		
          AJAXError('Delete Comment returned ' + http.status);
        }
     }
  
}

function manageInsertTemplate(selectField) {
	if(selectField.value == -1) {
	   document.location.href = '/members/mail/mail-templates.shtml';
	} else {
		if(selectField.value > 0) {
		        http = createRequestObject();
        		http.open('POST', '/gettemplate.shtml');
		        http.onreadystatechange = handleGetTemplate;
		        http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		        var reqparam = 'template_id=' + selectField.value;
		        http.send(reqparam);
		}
		document.sendmessage.template_id.value = selectField.value;
		selectField.selectedIndex = 0;

	}

}
function handleGetTemplate() {
     if(http.readyState == 4){
        if(http.status == 200) {
          var responseText = http.responseText;
	  var body = document.getElementById('body');
	  body.value = body.value + responseText;

	}else {
          AJAXError('Get Template returned ' + http.status);
        }
     }

}


function ratePhoto(photocontestentry_id, photoform) {
	http.open('POST', '/ratephoto.shtml');
	http.onreadystatechange = handleRatePhotoResponse;
        http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	var rating = 0;

	for (var i=0; i < photoform.rating.length; i++) {
	  if(photoform.rating[i].checked) {
	    rating = photoform.rating[i].value;
	  }
        }
	var reqparam = 'photocontestentry_id=' + photocontestentry_id + '&rating=' + rating + '&comments=' + photoform.comment.value;
        http.send(reqparam);
}

function handleRatePhotoResponse() {
     if(http.readyState == 4){
	if(http.status == 200) {
	  var responseXML = http.responseXML;
          var allowed = responseXML.getElementsByTagName('allowed')[0].firstChild.data;
	  if(allowed == 1) {
	    HideText('ratephoto');	
	    ShowText('votecounted');
	    HideText('commentshidden');
	    ShowText('comments');
	    ShowText('viewallcomments');
 	  } else {
	    alert(responseXML.getElementsByTagName('reason')[0].firstChild.data);
	  } 
        } else {
	  AJAXError('Rate photo returned ' + http.status);
	}
     }
}




function reportContestCommentForAbuse(comment_id) {
        http.open('POST', '/reportcontestcomment.shtml');
	http.onreadystatechange = handlereportContestCommentForAbuse;
        http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        var reqparam = 'contestcomment_id=' + comment_id;
        http.send(reqparam);
}

function handlereportContestCommentForAbuse() {
     if(http.readyState == 4){
        if(http.status == 200) {
          var responseXML = http.responseXML;
          var comment_id = responseXML.getElementsByTagName('comment_id')[0].firstChild.data;
          if(comment_id != 0) {
	      ReplaceText('abusedeletecomment_' + comment_id, responseXML.getElementsByTagName('response')[0].firstChild.data);
          } else {
            alert(responseXML.getElementsByTagName('response')[0].firstChild.data);
          }
        } else {		
          AJAXError('Report Contest Comment For Abuse returned ' + http.status);
        }
     }
  
}


function deleteContestComment(comment_id) {
        http.open('POST', '/deletecontestcomment.shtml');
	http.onreadystatechange = handledeleteContestComment;
        http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        var reqparam = 'contestcomment_id=' + comment_id;
        http.send(reqparam);	
}

function handledeleteContestComment() {
     if(http.readyState == 4){
        if(http.status == 200) {
          var responseXML = http.responseXML;
          var comment_id = responseXML.getElementsByTagName('comment_id')[0].firstChild.data;
	  if(comment_id != 0) {
            ReplaceText('abusedeletecomment_' + comment_id, responseXML.getElementsByTagName('response')[0].firstChild.data);
 	  } else {
	    alert(responseXML.getElementsByTagName('response')[0].firstChild.data);
	  } 
        }else {		
          AJAXError('Delete Contest Comment returned ' + http.status);
        }
     }
  
}

function reportMailAbuse(mail_id, comment) {
        http.open('POST', '/reportmailabuse.shtml');
        http.onreadystatechange = handlereportMailAbuse;
        http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        var reqparam = 'mail_id=' + mail_id + '&comment=' + comment;
        http.send(reqparam);
}

function handlereportMailAbuse() {
     if(http.readyState == 4){
        if(http.status == 200) {
	  var responsetext  = http.responseText;
	  ReplaceText('reportstatus', responsetext);
	  HideText('reportabuse');
        }else {
          AJAXError('Report Mail Abuse returned ' + http.status);
        }
     }

}

function reportSpam(mail_id, comment) {
        http.open('POST', '/reportspam.shtml');
        http.onreadystatechange = handlereportSpam;
        http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        var reqparam = 'mail_id=' + mail_id + '&comment=' + comment;

        http.send(reqparam);
}

function handlereportSpam() {
     if(http.readyState == 4){
        if(http.status == 200) {
	  var responsetext  = http.responseText;
	  ReplaceText('reportstatus', responsetext);
	  HideText('reportspam');
        }else {
          AJAXError('Report Spam returned ' + http.status);
        }
     }

}


function getfeaturedhotties() {
        http.open('GET', '/featuredhotties.shtml');
        http.onreadystatechange = handlegetfeaturedhotties;
        http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        http.send('');
}

function handlegetfeaturedhotties() {
     if(http.readyState == 4){
        if(http.status == 200) {
	  var responsetext  = http.responseText;
	  ReplaceText('featuredhotties', responsetext);
        }else {
          //AJAXError('getfeaturedhottie returned ' + http.status);
        }
     }


}


function getmembercount() {
  var localhttp = createRequestObject()
  localhttp.open('GET', '/membercount.shtml');
  localhttp.onreadystatechange = function() { handlegetmembercount(localhttp) };
  localhttp.send('');
}

function handlegetmembercount(localhttp) {
     if(localhttp.readyState == 4){
        if(localhttp.status == 200) {
	  var responsetext  = localhttp.responseText;
	  ReplaceText('membercount', responsetext);
        }else {
          //AJAXError('getmembercount returned ' + localhttp.status);
        }
     }

}


function selectPromo(textbox) {
	var i
	for (i = 0; i < textbox.form.payment.length; i++) {
		if (textbox.form.payment[i].value == 6) {
			textbox.form.payment[i].checked = true
		}
	}
}

function setPayPalPaymentManual(form, duration) {
  // set the 1 month if specified 
  form.action='https://www.paypal.com/cgi-bin/webscr';
  if (duration == 1) {
    form.item_name.value = '1 Month Subscription';
    form.item_number.value = '5-1';
    form.a3.value = '29.95';
    form.p3.value = '30';
  } else { // default is 3
    form.item_name.value = '3 Month Subscription';
    form.item_number.value = '5-3';
    form.a3.value = '44.85';
    form.p3.value = '90';
  }
  
  
}

function setPayPalPayment(form, button_id) {
  form.action='https://www.paypal.com/cgi-bin/webscr';
  form.hosted_button_id.value = button_id
    
}

// return the value of the radio button that is checked
// return an empty string if none are checked, or
// there are no radio buttons
function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

