// JavaScript Document

var baselink = "../";

// AJAX object

var responseDiv = "";

function ajaxObject(url, callbackFunction, responseDiv) { 
responseDiv = responseDiv;
var that=this;        
this.updating = false;  
this.abort = function() {    
if (that.updating) {      
that.updating=false;      
that.AJAX.abort();      
that.AJAX=null;    
}  
}  
this.update = function(passData,postMethod) {
if (that.updating) { return false; }    
that.AJAX = null;                              
if (window.XMLHttpRequest) {                    
that.AJAX=new XMLHttpRequest();                  
} else {                                        
that.AJAX=new ActiveXObject("Microsoft.XMLHTTP");    
}                                                 
if (that.AJAX==null) {                                   
return false;                                   
} else {      
that.AJAX.onreadystatechange = function() {          
if (that.AJAX.readyState==4) {                       
that.updating=false;                          
that.callback(that.AJAX.responseText,that.AJAX.status,that.AJAX.responseXML,responseDiv);                  
that.AJAX=null;                                                 
}                                                            
}                                                              
that.updating = new Date();                                    
if (/post/i.test(postMethod)) { 

// encode all POST data

var str = ""; 
for(var i = 0;i < passData.elements.length;i++) { 
switch(passData.elements[i].type){ 
case "text": 
case "textarea": 
case "password": 
if (!passData.elements[i].disabled) str += passData.elements[i].name + "=" + encodeURIComponent(passData.elements[i].value) + "&"; 
break; 
case "hidden": 
// hidden cannot be disabled 
str += passData.elements[i].name + "=" + encodeURIComponent(passData.elements[i].value) + "&"; 
break; 
case "checkbox": 
case "radio": 
if(passData.elements[i].checked && !passData.elements[i].disabled) str += passData.elements[i].name + "=" + encodeURIComponent(passData.elements[i].value) + "&"; 
break; 
case "select-one": 
if (!passData.elements[i].disabled) str += passData.elements[i].name + "=" + encodeURIComponent(passData.elements[i].options[passData.elements[i].selectedIndex].value) + "&"; 
break; 
case "select-multiple": 
if (!passData.elements[i].disabled){ 
for (var j = 0; j < passData.elements[i].length; j++){ 
var optElem = passData.elements[i].options[j]; 
if (optElem.selected == true){ 
str += passData.elements[i].name + "[]" + "=" + encodeURIComponent(optElem.value) + "&"; 
} 
} 
} 
break; 
} 
} 
// strip final &amp; 

str = str.substr(0,(str.length - 1));

// end secure

var uri=urlCall+'?'+that.updating.getTime();        
that.AJAX.open("POST", uri, true);        
that.AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=UTF-8");        
that.AJAX.setRequestHeader("Content-Length", str.length);        
that.AJAX.send(str);      
} else {        
var uri=urlCall+'?'+passData+'&timestamp='+(that.updating.getTime());         
that.AJAX.open("GET", uri, true);                                     
that.AJAX.send(null);                                               
}                    
return true;                                                 
}                                                                             
}  
var urlCall = url; 
this.callback = callbackFunction || function () { };
}

// processData process ajaxObject response: optional
// ajaxObject processes task and ignores response when processData is not used
// different functions can be made to serve different purposes

function processResponse(responseText, responseStatus, responseXML, responseDiv) {  
	if (responseStatus==200 || responseStatus==304) {    
		parent.top.document.getElementById(''+responseDiv+'').innerHTML=responseText; 
	} else {    
		//showPop('connection'); 
	} 
}

// use when waiting needs to be shown , and timeout

function processWait(request,div,action){
	if (request.updating) {  
		parent.top.document.getElementById('' + div + '').innerHTML = '' + action + '';
	} else { 
		alert('this object is idle');
	}
}

function timezone(id){
now = new Date()
    offset = now.getTimezoneOffset();
	document.getElementById(id).value=offset;
}

// LINKS

function menulink(cl,d){
	var i,ob,tA,h=document.location.href;
	if(document.getElementById){
	ob=(d)?document.getElementById(d):document;
	if(ob){
	tA=ob.getElementsByTagName('A');
	for(i=0;i<tA.length;i++){
	if(tA[i].href==h){
	tA[i].className=cl;
}}}}}

function menulink2(cl,d){
	var i,ob,tA,h=document.location.href;
	if(document.getElementById){
	ob=(d)?document.getElementById(d):document;
	if(ob){
	tA=ob.getElementsByTagName('A');
	for(i=0;i<tA.length;i++){
	if(tA[i].href==h){
	tA[i].className=cl;
}}}}}


// CHECK MESSAGES

function checkmsg() {
	setTimeout("checkmsg()", 30000);
	checkMsg2 = new ajaxObject(baselink+'mail/mailCheck3.php', processResponse, 'messages');
	checkMsg2.update();
} 

// KEEP WM LOGGED IN

function loggedin() {
	setTimeout("loggedin()", 60000);
	dologgedin = new ajaxObject(baselink+'admin/wm_log.php', processResponse, 'log');
	dologgedin.update();
} 


function showPop(type,txt,url) {
	
	var type2 = type;
	var header;
	var txt2;
	
	if(type2 == "disclaimer"){
		
	header = 'Rules';
	loadRules = new ajaxObject(baselink+'inc/disclaimer.php',processResponse,'pop_text');
	loadRules.update();
	txt2 = "<div style=\"height:50px; width:500px;padding-top:100px;text-align:center\"><img src=\"/gfx/wait.gif\" width=\"220\" height=\"19\"></div>";
    
    } else if(type2 == "approved"){
		
	header = 'Grrrrr!';
	txt2 = 'Your profile has not beed approved yet. <br/><br/>You will be notified by email when your profile is approved.<br/><br/>If you received the approval email while being online, please log out and log in again in order for your account to be adjusted.';
	
	} else if(type2 == "connection"){
		
	header = 'Grrrrr!';
	txt2 = 'There seems to be a problem with your connection. <br/><br/>Re-load this page and try again, and/or check your internet connection.';
    
    } else if(type2 == "profile"){
		
	header = 'Grrrrr!';
	txt2 = '<h2>You don\'t have a profile yet.</h2> To add locations and feedbacks to the Guide you need to create a profile first. <br/><br/> <a href=\"../my/?prof_edit\" class=\"high_lite\">Click here</a> to create a profile now, or wait till your profile is approved.';
        
    } else if(type2 == "activate"){
		
	header = 'Success!';
	txt2 = txt;
        
    } else if(type2 == "photos"){
		
	header = 'Info';
	loadPhotoInfo = new ajaxObject(baselink+'info/photos.php',processResponse,'pop_text');
	loadPhotoInfo.update();
	txt2 = "<div style=\"height:50px; width:500px;padding-top:100px;text-align:center\"><img src=\"/gfx/wait.gif\" width=\"220\" height=\"19\"></div>";
    
    } else if(type2 == "guidephotos"){
		
	header = 'Info';
	loadPhotoInfo = new ajaxObject(baselink+'info/text.php',processResponse,'pop_text');
	loadPhotoInfo.update('infotype=guidephotos','GET');
	txt2 = "<div style=\"height:50px; width:500px;padding-top:100px;text-align:center\"><img src=\"/gfx/wait.gif\" width=\"220\" height=\"19\"></div>";
        
    } else if(type2 == "prof_deleted"){
		
	header = 'Profile deleted';
	txt2 = 'Your profile is deleted.<br/><br/>You must create a new profile within 30 days or your account will be deleted.';
        
	} else if(type2 == "account_deleted"){
		
	header = 'Account deleted';
	txt2 = 'Your account is deleted.<br/><br/>We\'re sorry to see you go...<br/><br/>Please feel free to create a new account at any given time.';
    
     } else if(type2 == "membersonly"){
		
	header = 'Members Only';
	txt2 = '<img src=\"/gfx/members_only_01.jpg\" width=\"520\" height=\"80\" /><h3 style=\"font-size:13px; margin-top:15px\">Woofnude.com is a community site for BEARS, HAIRY MEN, CUBS, BLOKES and admirers who like to be NUDE - indoors but especially outdoors! We protect the privacy of our members - to see all profiles you must have a profile with at least one NUDE photo of yourself.<br /><br /> If you already have a profile, login now, otherwise make a new profile first.<br /><br />Mike - Woofnude.com</h3>';
		
	} else if(type2 == "access"){
		
	header = 'Warning';
	txt2 = '<form action=\"'+url+'index.php\" method=\"post\" name=\"warning\" style=\"margin:0\">Woofnude.com is an adult site and contains sexually explicit material. <br /><br />By entering this site I attest that I am at least 18 years of age, and/or of legal age to receive, view and possess such material in the the legal jurisdiction in which I live. <br /><br />I will not allow any person not of legal age to view such materials. <br /><br />I attest that viewing of such material in my governmental jurisdiction is legal, and understand that I am solely responsible for ascertaining the legality of viewing such material in my legal jurisdiction. <br /><br /> <br /><input name=\"accept\" type=\"hidden\" value=\"1\" /><input name=\"warning\" type=\"submit\" value=\"I AGREE\" style=\"width:125px; height45px\" /> <input name=\"leave\" type=\"button\" value=\"LEAVE\" onclick=\"window.location = \'http://www.google.com\'\" style=\"width:125px; height45px\" /></form>';
        
    } else if(type2 == "searchinfo"){
		
	header = 'Search Info';
	txt2 = '<strong>Example search:</strong> If you\'re looking for a guy with \"bear\" in his profile name, just enter \"bear\" in the Profile Name field and hit the Search button: all profiles with \"bear\" will be shown, i.e. \'bearguy\', \'somebear\', \'thisbear\', \'thatbear\', etc. </br></br>If you know the guy lives in New York, just add United States and New York to your search and you will see all profiles names with \"bear\" in it in New York. </br></br><strong>Tip:</strong> Use less search terms to find more profiles.';        
		
	} else if(type2 == "del_id"){
		
	header = 'Delete Account';
	txt2 = ''+txt+' <br /><br /><br /><form action=\"../inc/delaccount.php\" method=\"post\"><input name=\"yes\" type=\"submit\" value=\"yes\" style=\"width:125px; height45px\" /> <input name=\"no\" type=\"button\" value=\"no\" onclick=\"hidePop()\" style=\"width:125px; height45px\" /></form>';
		
	} else if(type2 == "del_prof"){
		
	header = 'Delete Profile';
	txt2 = ''+txt+' <br /><br /><br /><form action=\"../inc/delprof.php\" method=\"post\"><input name=\"yes\" type=\"submit\" value=\"yes\" style=\"width:125px; height45px\" /> <input name=\"no\" type=\"button\" value=\"no\" onclick=\"hidePop()\" style=\"width:125px; height45px\" />';
		
	} else if(type2 == "change_email"){
		
	header = 'Change Email';
	changeMail = new ajaxObject(baselink+'inc/access.php',processResponse,'pop_text');
	changeMail.update('poptype=changeemail','GET');
	txt2 = "<div style=\"height:50px; width:100%;padding-top:100px;text-align:center\"><img src=\"/gfx/wait.gif\" width=\"220\" height=\"19\"></div>";
		
	} else if(type2 == "change_pass"){
		
	header = 'Change Password';
	changePass = new ajaxObject(baselink+'inc/access.php',processResponse,'pop_text');
	changePass.update('poptype=changepassword','GET');
	txt2 = "<div style=\"height:50px; width:100%;padding-top:100px;text-align:center\"><img src=\"/gfx/wait.gif\" width=\"220\" height=\"19\"></div>";
		
	} else if(type2 == "emailerror"){
		
	header = 'Grrrrr!';
	txt2 = txt + "<br/><br/><a href=\"javascript:void(0)\" onclick=\"showPop('change_email')\">try again</a>";
		
	} else if(type2 == "passerror"){
		
	header = 'Grrrrr!';
	txt2 = txt + "<br/><br/><a href=\"javascript:void(0)\" onclick=\"showPop('change_pass')\">try again</a>";	
		
	} else if(type2 == "choose"){
		
	header = 'Alert';
	txt2 = '<form action=\"'+url+'\" method=\"post\" name=\"warning\" style=\"margin:0\">'+txt+' <br /><br /> <br /><input name=\"accept\" type=\"hidden\" value=\"1\" /><input name=\"warning\" type=\"submit\" value=\"I AGREE\" style=\"width:125px; height45px\" /></form>';
    
   } else if(type2 == "success"){
		
	header = 'Success!';
	txt2 = txt;
		
	} else if(type2 == "loginerror"){
		
	header = 'Grrrrr!';
	txt2 = txt;
		
	} else if(type2 == "login"){
		
	header = 'Member access';
	memberLogin = new ajaxObject(baselink+'inc/access.php', processResponse, 'pop_text');
	memberLogin.update('poptype=login','GET');
	txt2 = "<div style=\"height:50px; width:500px;padding-top:100px;text-align:center\"><img src=\"/gfx/wait.gif\" width=\"220\" height=\"19\"></div>";
            
    } else if(type2 == "loginpop"){
		
	header = 'Member access';
	memberLogin = new ajaxObject(baselink+'inc/access.php', processResponse, 'pop_text');
	memberLogin.update('poptype=loginpop','GET');
	txt2 = "<div style=\"height:50px; width:500px;padding-top:100px;text-align:center\"><img src=\"/gfx/wait.gif\" width=\"220\" height=\"19\"></div>";
		
	} else if(type2 == "apply"){
		
	header = 'Sign up';
	memberNew = new ajaxObject(baselink+'inc/access.php', processResponse, 'pop_text');
	memberNew.update('poptype=apply','GET');
	txt2 = "<div style=\"height:50px; width:500px;padding-top:100px;text-align:center\"><img src=\"/gfx/wait.gif\" width=\"220\" height=\"19\"></div>";
            
    } else if(type2 == "resend"){
		
	header = 'Re-send';
	memberNew = new ajaxObject(baselink+'inc/access.php', processResponse, 'pop_text');
	memberNew.update('poptype=resend','GET');
	txt2 = "<div style=\"height:50px; width:500px;padding-top:100px;text-align:center\"><img src=\"/gfx/wait.gif\" width=\"220\" height=\"19\"></div>";
		
	} else if(type2 == "warning"){
	
	header = 'Warning';
	txt2 = txt;
		
	} else if(type2 == "error"){
		
	header = 'Grrrrr!';
	txt2 = txt;
		
	} else {
		
	header = 'Grrrrr!';
	txt2 = txt;
	}	
	
	parent.top.document.getElementById('pop').style.display = "block";
	parent.top.document.getElementById('pop_content').style.display = "block";
	parent.top.document.getElementById('pop_text').innerHTML= txt2;
	parent.top.document.getElementById('pop_header').innerHTML = header;
	}
	
	// CLOSE POP
	
function hidePop() {
	document.getElementById('pop').style.display = "none";    
	document.getElementById('pop_content').style.display = "none";
	}
    
    function showWait(){
    	
	document.getElementById('pop').style.display = "block";
	document.getElementById('pop_wait').style.display  = "block";
		
   }

function firstTime() {
	setTimeout("window.location='../my/'", 2000);
} 

function setinnerHTML(id,txt){
	document.getElementById(id).innerHTML= txt;
}

	// VALIDATE LOGIN
	
	function validatelogin(type) {
	
var theMessage = "";
var type;
var noErrors = theMessage

		if(!/\S/.test(document.getElementById('email').value)){
theMessage = theMessage + "Please enter your email address<br/>";
		}
		
		if(!/\S/.test(document.getElementById('pass').value)){
theMessage = theMessage + "Please enter your password<br/>";
		}
		
		if (theMessage == noErrors) {
			doLogin = new ajaxObject(baselink+'inc/login.php', processResponse, 'login'); // create request with url
			doLogin.update(document.getElementById('loginform'),'POST'); // start request with object (the form) and type (POST), can be left empty for GET unless there are variables after ?
			processWait(doLogin,'login','<br /><img src=\"'+baselink+'gfx/wait.gif\"><br /><br /><strong>please wait while you are being logged in</strong>'); // show and check while waiting for the form to be processed
	return true;

} else {
	
	if(type == "home"){
		showPop('loginerror',theMessage);
	} else {
	theMessage = theMessage + "<br/><a href=\"javascript:void(0)\" onclick=\"showPop('login')\">try again</a>";
	showPop('error',theMessage);
	}
	
return false;
}
	}
	
	
	// VALIDATE RESEND
	
	function validateresend(type) {
	
		if(!/\S/.test(document.getElementById('email3').value)){
			showPop('error','Please enter your email address');
		} else {
			doResend = new ajaxObject(baselink+'inc/resend.php', processResponse, 'resend');
			doResend.update(document.getElementById('resendform'),'POST');
			processWait(doResend,'resend','<br /><img src=\"'+baselink+'gfx/wait.gif\"><br /><br /><strong>please wait while we fetch your login data</strong>');
return true;
}
}

// VALIDATE INVITE
	
	function validateInvite() {
	
		if(!/\S/.test(document.getElementById('invite_email').value)){
			showPop('error','Please enter the email address of the person you\'re inviting');
        } else if(!/\S/.test(document.getElementById('invite_name').value)){
			showPop('error','Please enter the name of the person you\'re inviting');
		} else {
			doInvite = new ajaxObject(baselink+'inc/invite.php', processResponse, 'inviteform');
			doInvite.update(document.getElementById('doinvite'),'POST');
			processWait(doInvite,'inviteform','<br /><img src=\"'+baselink+'gfx/wait.gif\"><br /><br /><strong>please wait while we send your invitation</strong>');
return true;
}
}

// VALIDATE APPLY


function validateapply(type) {
	
var theMessage = "";
var type;
var noErrors = theMessage

		if(!/\S/.test(document.getElementById('email2').value)){
theMessage = theMessage + "Please enter your email address<br/>";
		}

		if(!/\S/.test(document.getElementById('pass2').value)){
theMessage = theMessage + "Please enter your password<br/>";
		}

if ( document.applyform.age.checked == false )
    {
theMessage = theMessage + "Please confirm that you're 18 or older<br/>";
    }		
		if (theMessage == noErrors) {
			doApply = new ajaxObject(baselink+'inc/apply.php', processResponse, 'apply'); // create request with url
			doApply.update(document.getElementById('applyform'),'POST'); // start request with object (the form) and type (POST), cab be left empty for GET
			processWait(doApply,'apply','<br /><img src=\"'+baselink+'gfx/wait.gif\"><br /><br /><strong>please wait while we create your ID</strong>'); // show and check while waiting for the form to be processed
return true;

} else {
	
	if(type == 'home'){
		showPop('applyerror',theMessage);
	} else {
	theMessage = theMessage + "<br/><a href=\"javascript:void(0)\" onclick=\"showPop('apply')\">try again</a>";
	showPop('error',theMessage);
	}	

return false;
}
}		

	// HIDE DIVS - COMBO
	
function hideCombo(id1,id2) {
	document.getElementById(id1).style.display = "none";
	document.getElementById(id2).style.display = "none";
	}
	
	// SHOW DIVS - COMBO
	
function showCombo(id1,id2) {
	document.getElementById(id1).style.display = "block";
	document.getElementById(id2).style.display = "block";
	}
	
	// HIDE DIV
	
function hidestuff(id) {
	document.getElementById(id).style.display = "none";
	}
	
	// SHOW DIV
	
function showstuff(id) {
	document.getElementById(id).style.display = "block";
	}
	
	// UNDERLINE LINK
	
function underlineLink(id1,id2){
	document.getElementById(id1).style.textDecoration='underline';
	document.getElementById(id2).style.textDecoration='none';
	}
    

	// LIMIT TEXT IN FIELDS

function limitText(limitField, limitCount, limitNum) {
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	} else {
		limitCount.value = limitNum - limitField.value.length;
		}
	}    
	
	// SEND REPLY

function mailreply(num){
	if(/\S/.test(document.getElementById('text'+num).value)){
		sendReply(num);
	} else 
 		alert("You did not enter any text for your message")
	}
    
    function sendReply(num){
    doSendReply = new ajaxObject(baselink+'mail/mailSendreply.php', processResponse, 'reply'+num+'');
	doSendReply.update(document.getElementById('domail'),'POST');
	processWait(doSendReply,'reply'+num+'','<div align=\"center\" style=\"height:150px;background:url(../gfx/prof_top_bg.png) #FFF repeat-x bottom;border-bottom: #999 1px solid;\"><br /><br /><img src=\"../gfx/wait.gif\"><br /><br /><strong>...sending mail...<br /><br /><br /><br /></strong></div>');
    }
    
    // SET MAIL ICON TO 'OPENED'
    
    function setOpened(num){
    document.getElementById('mailicon'+num).src = '../gfx/mail1.gif';
    }
	
	// SET MAIL ICON TO 'SENT'
	
function setSent(num){
	document.getElementById('mailicon'+num).src = '../gfx/mail2.gif';
	}

	// OPEN REPLY FORM

function writemail(num,id,box) {  
  if (document.getElementById('mail_content'+num).style.display = "none")
    {
    document.getElementById('reply'+num).style.display = "block";
  	}
    doWriteMail = new ajaxObject(baselink+'mail/mailReply.php', processResponse, 'reply'+num+'');
	doWriteMail.update('id='+id+'&nums='+num+'&box='+box+'','GET');
	processWait(doWriteMail,'reply' +num+'','<div align=\"center\" style=\"background:url(../gfx/prof_top_bg.png) #FFF repeat-x bottom;border-bottom: #999 1px solid;\"><br /><br /><img src=\"../gfx/wait.gif\" alt=\"\"><br /><br /><strong>...mailform loading...<br /><br /><br /><br /></strong></div>');
  }
  
  // ADD FEEDBACK
  
  function checkFeedback(num){
	if(/\S/.test(document.getElementById('text'+num).value)){
		addFeedback(num);
	} else {
    showPop('error','You did not enter any text for your feedback');
	}
    }
    
    function addFeedback(num){
    doAddFeedback = new ajaxObject(baselink+'guide/addFeedback.php', processResponse, 'feedback'+num+'');
	doAddFeedback.update(document.getElementById('doguide'+num),'POST');
	processWait(doAddFeedback,'feedback'+num+'','<div align=\"center\" style=\"height:150px\"><br /><br /><img src=\"../gfx/wait.gif\"><br /><br /><strong>...adding feedback...<br /><br /><br /><br /></strong></div>');
    }
    
    function reportGD(num,id){
    doReportGD = new ajaxObject(baselink+'guide/guideFunctions.php', processResponse, 'reportGD'+num+'');
		doReportGD.update('reportGD='+id+'','GET');
        processWait(doReportGD,'reportGD'+num+'','<img src=\"'+baselink+'gfx/wait_s.gif\" alt=\"\" align=\"absmiddle\" border=\"0\">&nbsp;&nbsp;reporting...');
    }
    
    function reportFB(id){
    doReportFB = new ajaxObject(baselink+'guide/guideFunctions.php', processResponse, 'reportFB'+id+'');
		doReportFB.update('reportFB='+id+'','GET');
        processWait(doReportFB,'reportFB'+id+'','<img src=\"'+baselink+'gfx/wait_s.gif\" alt=\"\" align=\"absmiddle\" border=\"0\">&nbsp;&nbsp;reporting...');
    }
  
  // ADD TO MY LOCATIONS
  
  function setDest(id,change){
	 doSetDest = new ajaxObject(baselink+'guide/guideFunctions.php', processResponse, 'set'+change+'');
		doSetDest.update('setid='+id+'','GET');
        processWait(doSetDest,'set'+change+'','<img src=\"'+baselink+'gfx/wait_s.gif\" alt=\"\" align=\"absmiddle\" border=\"0\">&nbsp;&nbsp;adding...');
}

 // REMOVE FROM MY LOCATIONS
  
  function delDest(id,change){
	 doDelDest = new ajaxObject(baselink+'guide/guideFunctions.php', processResponse, 'del'+change+'');
		doDelDest.update('delid='+id+'&divid='+change+'','GET');
        processWait(doDelDest,'del'+change+'','<img src=\"'+baselink+'gfx/wait_s.gif\" alt=\"\" align=\"absmiddle\" border=\"0\">&nbsp;&nbsp;deleting...');
}
  
	// SET STATUS OF OPENED MAIL
  
  function setStatus(id){
	 doSetStatus = new ajaxObject(baselink+'mail/mailSetStatus.php', processResponse, 'change');
	doSetStatus.update('id='+id+'','GET');
}
  
 	// OPEN PROFILE POPUP

function profpop(url) {
	newwindow=window.open(url,'prof','height=700,width=610,resizable=0,scrollbars=1,top=25,left=25');
	if (window.focus) {newwindow.focus()}
	return false;
}

	// OPEN SUPPORT POPUP

function popupform(myform, windowname){
if (!window.focus)return true;
window.open('', windowname, 'height=550,width=690');
myform.target=windowname;
return true;
}

	// OPEN PHOTO POPUP

function photopop(url){
	newwindow=window.open(url,'photo','height=700,width=570,top=25,right=25,scrollbars=no,menubar=no');
	if (window.focus) {newwindow.focus()}
	return false;
	}	
	
	// CHECK IF NICK IS VALID 
	
function checknick(source) {
	var nick = document.getElementById(source).value;
	doCheckNick = new ajaxObject(baselink+'inc/checknick.php', processResponse, 'checknick');
	doCheckNick.update('nick='+nick+'','GET');
  }

	// RELOAD FORM PULLDOWN MENU TO CITIES
  
function setcity(source) {
	var dropdownIndex = document.getElementById(source).selectedIndex;
	var country = document.getElementById(source)[dropdownIndex].value;
	doSetCity = new ajaxObject(baselink+'inc/setcity.php', processResponse, 'newcity');
	doSetCity.update('country='+country+'','GET');
	processWait(doSetCity,'newcity','<img src=\"'+baselink+'gfx/wait_s.gif\" alt=\"\" align=\"absmiddle\">&nbsp;&nbsp;loading cities');
	}
	
	// RELOAD FORM PULLDOWN MENU TO CITIES
	
function setcity2(source,country) {
	var cc = country;
	var k = document.getElementById(source).options.selectedIndex; 
	var to = document.getElementById(source).options[k].value;
	doSetCity2 = new ajaxObject(baselink+'inc/setcity2.php', processResponse, 'city');
	doSetCity2.update('state='+to+'&country='+cc+'','GET');
	processWait(doSetCity2,'city','<img src=\"'+baselink+'gfx/wait_s.gif\" alt=\"\" align=\"absmiddle\">&nbsp;&nbsp;loading cities');	
  }
  
  // RELOAD FORM PULLDOWN MENU TO STATES/PROVINCES 
	
function setstate2(source) {
	var k = document.getElementById(source).options.selectedIndex; 
	var to = document.getElementById(source).options[k].value;
	doSetState2 = new ajaxObject(baselink+'inc/setstate.php', processResponse, 'state');
	doSetState2.update('country='+to+'','GET');
	processWait(doSetState2,'state','<img src=\"'+baselink+'gfx/wait_s.gif\" alt=\"\" align=\"absmiddle\">&nbsp;&nbsp; states/provinces');
  }
	
	// RELOAD FORM PULLDOWN MENU TO STATES/PROVINCES AND CITIES 
	
function setstate(source) {
	var k = document.getElementById(source).options.selectedIndex; 
	var to = document.getElementById(source).options[k].value;
		
    doGetState = new ajaxObject(baselink+'inc/setstate.php',processResponse,'state');
	doGetState.update('country='+to+'','GET');
    processWait(doGetState,'state','<img src=\"'+baselink+'gfx/wait_s.gif\" alt=\"\" align=\"absmiddle\">&nbsp;&nbsp; states/provinces');
        
    doGetCities = new ajaxObject(baselink+'inc/setcity3.php',processResponse,'city');
	doGetCities.update('country='+to+'','GET');
    processWait(doGetCities,'city','<img src=\"'+baselink+'gfx/wait_s.gif\" alt=\"\" align=\"absmiddle\">&nbsp;&nbsp;loading cities');
  }
  
  
	// RELOAD FORM PULLDOWN MENU TO CITIES > LOCATION
	
function setcity_loc(source,country) {
	var cc = country;
	var k = document.getElementById(source).options.selectedIndex; 
	var to = document.getElementById(source).options[k].value;
	doSetCity2 = new ajaxObject(baselink+'inc/setcity_loc.php', processResponse, 'city_loc');
	doSetCity2.update('state='+to+'&country='+cc+'','GET');
	processWait(doSetCity2,'city_loc','<img src=\"'+baselink+'gfx/wait_s.gif\" alt=\"\" align=\"absmiddle\">&nbsp;&nbsp;loading cities');	
  }
  
  // RELOAD FORM PULLDOWN MENU TO STATES/PROVINCES AND CITIES > LOCATION
	
function setstate_loc(source) {
	var k = document.getElementById(source).options.selectedIndex; 
	var to = document.getElementById(source).options[k].value;
	doSetState2 = new ajaxObject(baselink+'inc/setstate_loc.php', processResponse, 'state_loc');
	doSetState2.update('country='+to+'','GET');
	processWait(doSetState2,'state_loc','<img src=\"'+baselink+'gfx/wait_s.gif\" alt=\"\" align=\"absmiddle\">&nbsp;&nbsp; states/provinces');
  }
  
function deleteAll(){
	doDeleteAll = new ajaxObject(baselink+'mail/delall.php',processResponse,'change');
    doDeleteAll.update(document.getElementById('domail'),'POST');
	}

function saveAll(){
	doSaveAll = new ajaxObject(baselink+'mail/saveall.php',processResponse,'change');
    doSaveAll.update(document.getElementById('domail'),'POST');
	}
    
function loadMail(mailbox) {
	doloadMail = new ajaxObject(baselink+'mail/mailFunctions.php',processResponse,'showmail');
	doloadMail.update('box='+mailbox,'GET');
	processWait(doloadMail,'showmail','<img src=\"../gfx/wait_s.gif\" style=\"margin:25px 0 25px 0\">');
	}
    	
function processMail(msgid,type,profid,divid) {
	doprocessMail = new ajaxObject(baselink+'mail/mailFunctions.php',processResponse,'mail_content'+divid);
	doprocessMail.update('type='+type+'&msgid='+msgid+'&profid='+profid+'','GET');
	processWait(doprocessMail,'mail_content'+divid,'<div style=\"width:100%; text-align:center \"><img src=\"../gfx/wait_s.gif\" style=\"margin:25px 0 25px 0\"></div>');
	}
    
function closebox(id) {  
	document.getElementById(id).style.display='none';  
}
  
function setprefs(source, value, div) {
	doSetPrefs= new ajaxObject(baselink+'inc/setprefs.php',processResponse,''+div+'');
	doSetPrefs.update('source='+source+'&value='+value+'','GET');
	processWait(doSetPrefs,''+div+'','<img src=\"'+baselink+'gfx/wait_s.gif\">');
	}
	
function validatewmlogin() {
	
var theMessage = "";
var noErrors = theMessage

		if(!/\S/.test(document.getElementById('username').value)){
theMessage = theMessage + "\n Please enter your username";
		}
		
		if(!/\S/.test(document.getElementById('pass').value)){
theMessage = theMessage + "\n Please enter your password";
		}
		
		if (theMessage == noErrors) {
        
    doAdminLogin = new ajaxObject(baselink+'admin/wm_login.php', processResponse, 'wmlogin');
	doAdminLogin.update(document.getElementById('wmloginform'),'POST');
	processWait(doAdminLogin,'wmlogin','please wait while you are being logged in');

return true;

} else {

alert(theMessage);
return false;
}
	}

function validatechange_p(){
	
	var theMessage = "";
	var noErrors = theMessage
	
	if(!/\S/.test(document.getElementById('new_pass').value)){
	theMessage = theMessage + "Please enter your new password<br/>";
	}
	
	if(!/\S/.test(document.getElementById('new_pass2').value)){
	theMessage = theMessage + "Please enter your new password again<br/>";
	}
	
	if (theMessage == noErrors) {
			doPassChange = new ajaxObject(baselink+'inc/change_password.php', processResponse, 'change_p');
			doPassChange.update(document.getElementById('change_p'),'POST');
			processWait(doPassChange,'change_p','<img src=\"../gfx/wait.gif\">');
	return true;

	} else {

	theMessage = theMessage + "<br/><a href=\"javascript:void(0)\" onclick=\"showPop('change_pass')\">try again</a>";
	showPop('error',theMessage);
	return false;
	}	
}

function validatechange_e(){
	
	var theMessage = "";
	var noErrors = theMessage
	
	if(!/\S/.test(document.getElementById('email').value)){
	theMessage = theMessage + "Please enter your new email<br/>";
	}
	
	if(!/\S/.test(document.getElementById('email2').value)){
	theMessage = theMessage + "Please enter your new email again<br/>";
	}
		
	if (theMessage == noErrors) {
			doEmailChange = new ajaxObject(baselink+'inc/change_email.php', processResponse, 'change_e');
			doEmailChange.update(document.getElementById('change_e'),'POST');
			processWait(doEmailChange,'change_e','<img src=\"../gfx/wait.gif\">');
	return true;

	} else {
		
	theMessage = theMessage + "<br/><a href=\"javascript:void(0)\" onclick=\"showPop('change_email')\">try again</a>";
	showPop('error',theMessage);
	return false;
	}
}

// RESET RADIO GROUP TO UNSELECTED STATE

function resetGroup(radioObj, newValue) {
	if(!radioObj)
		return;
	var radioLength = radioObj.length;
	if(radioLength == undefined) {
		radioObj.checked = (radioObj.value == newValue.toString());
		return;
	}
	for(var i = 0; i < radioLength; i++) {
		radioObj[i].checked = false;
		if(radioObj[i].value == newValue.toString()) {
			radioObj[i].checked = true;
		}
	}
} 

function check_boxes(cbname,state,formname) {
	frmobj = document.forms[formname];
 for (i = 0; i < frmobj.elements.length; i++) {
 if (frmobj.elements[i].name == cbname) {
 frmobj.elements[i].checked = state; }
 }
}
	
function confirmDelete(img) {
        doDeletePhoto = new ajaxObject(baselink+'inc/delphoto.php',processResponse,'showphotos');
		doDeletePhoto.update('img='+img+'','GET');
        processWait(doDeletePhoto,'imgbox'+img,'<div style=\"width:100%;padding-top:25px;text-align:center\"><img src=\"'+baselink+'gfx/wait_s.gif\"><br/><br/>...deleting photo...</div>');
	}
	
function confirmMain(img) {
        doSetMain = new ajaxObject(baselink+'inc/setmain.php',processResponse,'showphotos');
		doSetMain.update('img='+img+'','GET');
        processWait(doSetMain,'imgbox'+img,'<div style=\"width:100%;padding-top:25px;text-align:center\"><img src=\"'+baselink+'gfx/wait_s.gif\"><br/><br/>...updating photo...</div>');
	}
    
function loadPhotos() {
	doLoadPhotos = new ajaxObject(baselink+'my/showphotos.php',processResponse,'showphotos');
	doLoadPhotos.update('load','GET');
    processWait(doLoadPhotos,'showphotos','<div style=\"width:760px;height:100px;padding-top:25px;text-align:center\"><img src=\"'+baselink+'gfx/wait_s.gif\"><br/><br/>...loading photos...</div>');
	}
	
function showphoto() {
  document.getElementById('photo').style.display='block';document.getElementById('screen').style.display='block';
  }
  function hidephoto() {
  document.getElementById('photo').style.display='none';document.getElementById('screen').style.display='none';
  }
  
// FLASH TITLE BAR WHEN NEW MESSAGE ARRIVES

var timer = "";

function titlebar(val)
{
	//var msg  = "New message";
	var speed = 500;
	var pos = val;

	//var msg1  = "    !! "+msg+" !!";
	//var msg2  = "    "+msg+"  ";
	
	var msg1  = "Woofnude.com";
	var msg2  = "New message";

	if(pos == 0){
		masg = msg1;
		pos = 1;
	}
	else if(pos == 1){
		masg = msg2;
		pos = 0;
	}

	document.title = masg;
	timer = window.setTimeout("titlebar("+pos+")",speed);
}

function titlebarstop(){	
	window.clearTimeout(timer);
	document.title = "Woofnude.com | Barenaked Bears & Blokes!";	
}

 function showDate(type) {     
 var date_bar    = document.getElementById('date_bar');     
 var date_div   = document.getElementById('date_div');     
 date_bar.style.display  = ((type=='6') || (type=='9'))?'block':'none';      
 date_div.style.display = ((type=='6') || (type=='9'))?'block':'none';
}

function swap(me,main,alt) {
me.innerHTML = (me.innerHTML == main) ? alt : main;
}




