//AvMatch javascript functions 
//copyright MM 2008, 09, 10
//formSubmit takes the form name and source value and passes it to php.

var c=0;
var t;
var timer_is_on=0;

var ftc=0;
var ft;
var flash_title_on = 0;

var doc_title = document.title;
var flash_title = "";

var windowstatus = 1;

var userAgent = navigator.userAgent.toLowerCase();
var pattern = /msie/;
var pattern6 = /msie 6.0/;
var pattern7 = /msie 7.0/;
var firefoxpattern = /firefox/;

if(pattern.test(userAgent)){
	document.onfocusout = function(){ setwindowstatus("blurry"); }
	document.onfocusin = function(){ setwindowstatus("focus"); }	
}else{
	window.onblur = function(){ setwindowstatus("blurry"); }
	window.onfocus = function(){ setwindowstatus("focus"); }
}

function setwindowstatus(word){
	if(word == "blurry"){
		windowstatus = 0;
	}else if(word == "focus"){
		windowstatus = 1;
		//flashTitle();
	}
}

function flashTitleMail(returnedtext){
	
	if(returnedtext == "logout"){
		window.location.reload();
	}else if(returnedtext != "zero"){
		//start flashing the top
		if (!flash_title_on || (flash_title_on == 1 && returnedtext != flash_title)){
			clearTimeout(ft);
			flash_title = returnedtext;
		  flash_title_on=1;
		  flashCount();
	  }
	}else{
		//stop flashing the top
		clearTimeout(ft);
		flash_title_on = 0;
	}
}

function statusMailCount(){
	if(document.getElementById('mailinfo')){
		var params = "mail=count&page="+jpage+"&sp="+jsubpage;
		makeHttpRequest("jscript/AjxStatusMail.php", flashTitleMail, 'POST', params);
	}
}


function flashCount(){
	ftc=ftc+1;
	
	if(ftc%2 == 0){
		document.title = doc_title;
		dur = 500;
	}else{
		document.title = flash_title;
		dur = 1500; //1500 = 1.5 secs
	}
	
	ft=setTimeout("flashCount()",dur);
}


function updateMail(returnedtext){
	//alert(returnedtext);
	if(returnedtext == "logout"){
	window.location.reload();
	}else{
	document.getElementById('mailinfo').innerHTML = returnedtext;
	}
}

function statusMailUpdate(){
	if(document.getElementById('mailinfo')){
		var params = "mail=check&page="+jpage+"&sp="+jsubpage;
		makeHttpRequest("jscript/AjxStatusMail.php", updateMail, 'POST', params);
	}
}

function updateAlerts(returnedtext){
	//alert(returnedtext);
	if(returnedtext == "logout"){
		window.location.reload();
	}else{
		
		var parser;
		var xmlDoc;

		if (window.DOMParser){
	  	parser=new DOMParser();
	  	xmlDoc=parser.parseFromString(returnedtext,"text/xml");
	  }else{ // Internet Explorer
		  xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
		  xmlDoc.async="false";
		  xmlDoc.loadXML(returnedtext);
	  }
	  
	  var tab = xmlDoc.getElementsByTagName("alerts");
	  var mail_count = tab[0].attributes.getNamedItem("mail_count").nodeValue;
	  var chat_count = tab[0].attributes.getNamedItem("chat_count").nodeValue;
		
		var alertsinfo = tab[0].firstChild.nodeValue;
		document.getElementById('mailinfo').innerHTML = alertsinfo;
		
		if(mail_count > 0 || chat_count > 0){
			//start flashing the top
			clearTimeout(ft);				
			if(mail_count > 0) flash_title = "New Mail!"; //document.getElementById("mailsound").Play();
			if(chat_count > 0) flash_title = "New Chat!"; 
			if(chat_count > 0 && windowstatus == 0 && (!newchatwin || (newchatwin && newchatwin.closed)) ) document.getElementById("chatsound").Play();
			if(chat_count > 0 && mail_count > 0) flash_title = "New Chat & New Mail!";
		  flash_title_on=1;
		  flashCount();
		}else if(mail_count == 0 && chat_count == 0){
			//stop flashing the top
			clearTimeout(ft);
			flash_title_on = 0;
		}
	}
}

function statusAlertsUpdate(){
	if(document.getElementById('mailinfo')){
		var params = "alerts=check&page="+jpage+"&sp="+jsubpage;
		makeHttpRequest("jscript/AjxStatusMail.php", updateAlerts, 'POST', params);
	}
}

function timedCount(){

if(c > 0){ statusAlertsUpdate(); } //statusMailUpdate(); statusMailCount();

c=c+1;
	
	if(c > 420){
		stopCount();
	}else{
		t=setTimeout("timedCount()",30000); //60000 = 1 min
	}
}

function doTimer()
{
if (!timer_is_on)
  {
  timer_is_on=1;
  timedCount();
  }
}

function stopCount()
{
clearTimeout(t);
timer_is_on=0;
}

function formSubmit(form,source){		
	form.whichsource.value=source;
	form.submit();
}
	
function sortSubmit(form,sort,source){
	//alert(form);
	//form = var1;
	form.sb.value=sort;
	form.whichsource.value=source;
	form.submit();		
}

function sortSubmit2(form,sort,source){
	//alert(source);
	//form = var1;
	//form.sb.value=sort;
	form.whichsource.value=source;
	form.submit();
}
	
function formSubmitId(form,source,id,aname){			

	var tess = source + id;		
	if (source == 'delete'){
	pass=confirm('Are you sure you want to delete '+aname+'?'+' This cannot be undone!');		
			source = '';
			if (pass == true){		
			source = 'delete';
			}
		}
			//alert(form);
	form.whichsource.value=source;
	form.whichid.value=id;
	form.whichname.value=aname;
	form.submit();
}

function formSubmitIdOrd(form,source,id,order_id){			
	
	form.whichsource.value=source;
	form.whichid.value=id;
	form.order.value=order_id;
}


//showimage is a simple function that switches the main image with the clicked thumb image :)
function showimage(source){
	document.main.src = source;
}

function showPollResults(returnedtext){
	//alert(returnedtext);
	document.getElementById('pollresults').innerHTML = returnedtext;
	document.getElementById('pollresults').style.display = 'block';
	document.getElementById('polloptions').style.display = 'none';
	document.getElementById('pollstate').innerHTML = "<div class='lgrey' style='width: 100%; float: left; text-align: left; '>Thank you for voting.</div>";
	
}

function submitPoll(){
	
	var vote = document.getElementById('pollradioselect').value;
	var poll = document.getElementById('poll').value;
	var params = "poll="+poll+"&vote="+vote;
	makeHttpRequest("jscript/poll.php", showPollResults, 'POST', params);
}

function nameCheckResults(returnedtext){

	if(returnedtext != 'error'){
		
		//alert(returnedtext);
		if(returnedtext == '110'){
			document.getElementById('nameerror').innerHTML = '';
			document.getElementById('namecheckimg').src = dir+'checked.png';
		}else if(returnedtext == '109'){
			document.getElementById('nameerror').innerHTML = '*One of your words is not on our approved word list! See our word list page above for approved words.';
			document.getElementById('namecheckimg').src = dir+'checked_fail.png';
		}else if(returnedtext == '108'){
			document.getElementById('nameerror').innerHTML = '*You have too many words! You can have a maximum of five approved words.';
			document.getElementById('namecheckimg').src = dir+'checked_fail.png';
		}else if(returnedtext == '107'){
			document.getElementById('nameerror').innerHTML = '*This name is not available! Please try a new combination of words.';
			document.getElementById('namecheckimg').src = dir+'checked_fail.png';
		}else if(returnedtext == '106'){
			document.getElementById('nameerror').innerHTML = '*Your name contains illegal characters! You can use English alphabet letters and spaces only.';
			document.getElementById('namecheckimg').src = dir+'checked_fail.png';
		}else if(returnedtext == '105'){
			document.getElementById('nameerror').innerHTML = '*Your name is too long! Total character count, including spaces, can be 24.';
			document.getElementById('namecheckimg').src = dir+'checked_fail.png';
		}
		
	}

}

function nameChecker(){
	
	var name2check = '';

	var field1 = document.getElementById('prof_name_conf').value;
	
	if(field1 != ''){
		name2check = field1.replace(/ /gi, "_");
	}
	
	if(name2check == ''){
		document.getElementById('namecheckimg').src = dir+'checked_fail.png';
		document.getElementById('nameerror').innerHTML = '*You must have a basic profile name to publish your profile.';
	}
	
	if(name2check != '' && name2check.length < 3){
		//not long enough 
		document.getElementById('nameerror').innerHTML = '*Your name is too short! It must be 3 characters or longer. See the Word List menu above for approved words.';
		document.getElementById('namecheckimg').src = dir+'checked_fail.png';
		
	}else if(name2check != '' && name2check.length > 2 ){
		//ok now check it against the database
		var params = "namecheck="+name2check;
		makeHttpRequest("jscript/ajxNameCheck.php", nameCheckResults, 'POST', params);
	}
}

function buyMessImageResult(returnedtext){
	
	if(returnedtext != 'error'){
		
		//alert(returnedtext);
		if(returnedtext == '110'){ //transaction success
			
			document.getElementById('buyimagesbutton').style.display = 'none';
			document.getElementById('buyimagesbusy').style.display = 'none';
			document.getElementById('imagesleft').innerHTML = "Message Images Left: <b>4</b>";
			document.getElementById('imagesleft').style.display = 'block';
			document.getElementById('imageuploadfield').disabled=false;
			
		}else if(returnedtext == '109' || returnedtext == '105' ){ //transaction failed
			document.getElementById('buyimagesbutton').style.display = 'none';
			document.getElementById('buyimagesbusy').style.display = 'none';
			document.getElementById('imagesleft').className = 'redtext';
			document.getElementById('imagesleft').innerHTML = "Transaction failed. Please reload page & try again.";
			document.getElementById('imagesleft').style.display = 'block';
		}
	}
}

function buyMessageImages(){

	document.getElementById('buyimagesbutton').style.display = 'none';
	document.getElementById('buyimagesbusy').style.display = 'block';

	var params = "buyimages=4";
	makeHttpRequest("jscript/AjxImageBuy.php", buyMessImageResult, 'POST', params);

}

function enablePoll(choice){
	document.getElementById('pollradioselect').value = choice;
	var pollb = "<a href='javascript:void(0);' ><img border='0' src='"+langdir+'submitg.gif'+"' name='submitpoll' onclick='submitPoll()' />";
	if(document.getElementById('pollsubmit'))document.getElementById('pollsubmit').innerHTML = pollb;
}

function showHidePoll(){

	var shpr = document.getElementById('pollresultsswitch');
	shpr.innerHTML = 'bitch';

	with (document.getElementById('pollresults').style){ 
		showswitch = display!='none' ? 0 : 1;
		display = display!='none' ? 'none' : 'block';
		shpr.innerHTML = display!='none' ? 'hide results' : 'show results';
  }
  
  with (document.getElementById('polloptions').style){
   	display = display!='none' ? 'none' : 'block';
  }
  
  with (document.getElementById('pollsubmit').style){ 
   	display = display!='none' ? 'none' : 'block';
  }
}


function showHide2(id){

  with (document.getElementById(id).style)
    { showswitch = display!='none' ? 0 : 1 }
  with (document.getElementById(id).style)
    { 
      if(showswitch == 0){display = 'block'}else{
      display = display!='none' ? 'none' : 'block'}
    }

  if((id == 'part1')&& (showswitch == 1)){

    document.getElementById('part2').style.display = 'none';
    document.getElementById('myslbut').className = 'profmenu'; 
    document.getElementById('myrlbut').className = 'profmenu2';
    document.getElementById('myslbut2').className = 'profmenu';
    document.getElementById('myrlbut2').className = 'profmenu2';
    document.getElementById('onpart').value = '1';
  }
  
  if((id == 'part2')&& (showswitch == 1)){
    document.getElementById('part1').style.display = 'none';
    document.getElementById('myslbut').className = 'profmenu2';
    document.getElementById('myrlbut').className = 'profmenu';
    document.getElementById('myslbut2').className = 'profmenu2';
    document.getElementById('myrlbut2').className = 'profmenu';
    document.getElementById('onpart').value = '2';
  }
}


function showHide4(id){

  with (document.getElementById(id).style)
    { showswitch = display!='none' ? 0 : 1 }
  with (document.getElementById(id).style)
    { 
      if(showswitch == 0){display = 'block'}else{
      display = display!='none' ? 'none' : 'block'}
    }

  if((id == 'reply1')&& (showswitch == 1)){
    
    document.getElementById('reply2').style.display = 'none';
    document.getElementById('replybut1').className = 'profmenu';
    document.getElementById('replybut2').className = 'profmenu2';
    //document.getElementById('onpart').value = '1';

  }
  
  if((id == 'reply2')&& (showswitch == 1)){

    document.getElementById('reply1').style.display = 'none';
    document.getElementById('replybut1').className = 'profmenu2';
    document.getElementById('replybut2').className = 'profmenu';
    //document.getElementById('onpart').value = '2';
  }
}

function showHideImage(id){

var srcimg = 'img' + id;
var thumbimg = 'thumb' + id;

	with(document.getElementById(id).style){ picswitch = display!='none' ? 0 : 1 }
	with(document.getElementById(id).style){ display = display!='none' ? 'none' : 'block' }
	//with(document.getElementById(thumbimg).style){ display = display!='none' ? 'none' : 'block' }

	if(( picswitch == 0)){
		document.getElementById(srcimg).src = dir + 'show1.gif';
	}else if (( picswitch == 1)){
		document.getElementById(srcimg).src = dir + 'hide1.gif';
	}
		
}

function showHideMes(id){

var srcimg = 'img' + id;

with (document.getElementById(id).style)
{ picswitch = display!='none' ? 0 : 1 }
with (document.getElementById(id).style)
{ display = display!='none' ? 'none' : 'block' }

	if (( picswitch == 0)){
	//alert (id);
	document.getElementById(srcimg).src = dir + 'show1.gif';
	  if(id == 'qbrowse'){document.getElementById('columntitlebrowse').className = 'browsemargin10';}
	}else if (( picswitch == 1)){
	document.getElementById(srcimg).src = dir + 'hide1.gif';
	  if(id == 'qbrowse'){document.getElementById('columntitlebrowse').className = 'browsemargin' ;}
	}
		
}

function showHideBrowse(id){
	if(id == 'basicbrowse'){
		document.getElementById(id).style.display = 'block';
		document.getElementById('advbrowse').style.display = 'none';
		document.search.browsesearch.value = 'basicbrowse';
		document.browse.browsesearch.value = 'basicbrowse';
	}else if( id == 'advbrowse'){
		document.getElementById(id).style.display = 'block';
		document.getElementById('basicbrowse').style.display = 'none';
		document.search.browsesearch.value = 'advbrowse';
		document.browse.browsesearch.value = 'advbrowse';
	}
}

//dispeditsearch
function showHideEdit(id){
	
	with (document.getElementById(id).style)
	{ picswitch = display!='none' ? 0 : 1 }
	with (document.getElementById(id).style)
	{ display = display!='none' ? 'none' : 'block' }
	//document.getElementById('advoptions').style.display = 'none';
	
	if (picswitch == 0){
		document.getElementById('edit').src = langdir+'editplus.gif';
		document.getElementById('dispeditsearch').value='0';
	}else if(picswitch == 1){
		document.getElementById('edit').src = langdir+'editminus.gif';
		document.getElementById('dispeditsearch').value='1';
	}
	
}

function showHideFlag(id){
	
	with (document.getElementById(id).style)
	{ picswitch = display!='none' ? 0 : 1 }
	with (document.getElementById(id).style)
	{ display = display!='none' ? 'none' : 'block' }
	//document.getElementById('advoptions').style.display = 'none';
	
	if (picswitch == 0){
		document.getElementById('flag').src = langdir+'flag_open.gif';
		//document.getElementById('dispeditsearch').value='0';
	}else if(picswitch == 1){
		document.getElementById('flag').src = langdir+'flag_close.gif';
		//document.getElementById('dispeditsearch').value='1';
	}
	
}

//this function is used in advanced search and checks for check boxes if they are checked
//if none are checked, then it hides the nice to have, must have
function ShowPriority(thisform,thisname, id){

var myArray = thisform.elements[thisname];

	var show = 0;
	
	for(var i = 0; i < myArray.length; i++) {
		if(myArray[i].checked == true){
			show = 1;
		}
	}
	if(thisname == "seekrl[]" && thisform.elements['priority_basicrl'][0].checked){
		show = 0;
	}

	if(show == 1){
		document.getElementById(id).style.display = 'block';
	}else{
		document.getElementById(id).style.display = 'none';
	}

}


//this function shows the priority radio buttons for basic rl info advanced search form
function basicRL(vari){
	if(vari == 2){
		document.getElementById('priority_genderrl').style.display = 'block';
		document.getElementById('priority_agerl').style.display = 'block';
		document.getElementById('priority_seekrl').style.display = 'block';
	}else if(vari == 1){
		document.getElementById('priority_genderrl').style.display = 'none';
		document.getElementById('priority_agerl').style.display = 'none';
		document.getElementById('priority_seekrl').style.display = 'none';
	}
}

function enableDelete(thisname, thisvalue){
	
	var delbutton;
	
	//savedsearches
	
	if(thisvalue > 1){
		delbutton = "<a href='javascript:showDialog();' ><img class='qbrowse' src='"+dir+"del_x.gif' name='delete' border='0' alt='delete' title='delete saved search' /></a>";
		document.getElementById('delsearch').innerHTML = delbutton;	
		//document.getElementById('delsearch').disabled = false;
	}else{
		delbutton = "<img class='qbrowse' src='"+dir+"del_x_gry.gif' name='delete' border='0'/>";
		document.getElementById('delsearch').innerHTML = delbutton;
	}
}


function closeDialog(){		
 		var w = document.getElementById("overlay");
 		w.style.display="none";
 		w.style.visibility="hidden";
 		w.style.zIndex="-1"; 		 		
 		var x = document.getElementById("dialogtop_content");
 		var y = document.getElementById("dialogtext");
 		x.removeChild(x.childNodes[1]);
 		y.removeChild(y.childNodes[0]);
 			if(document.getElementById('sortmenu')){
	 			document.getElementById('sortmenu').style.display = "block";
	 		}
 	}
 	
function confirmDialog(form,conftype){		
 		var w = document.getElementById("overlay");
 		w.style.display="none";
 		w.style.visibility="hidden";
 		w.style.zIndex="-1"; 		 		
 		var x = document.getElementById("dialogtop_content");
 		var y = document.getElementById("dialogtext");
 		x.removeChild(x.childNodes[1]);
 		y.removeChild(y.childNodes[0]); 		
			if(conftype == 1 && conftype == 2){
				document.getElementById('sortmenu').style.display = "block";	
			}		
		if(conftype == 1){
			form.whichsource.value='delete';
			form.submit();
		}else if(conftype == 2){
			if(form == "signup"){window.location = "http://www.avmatch.com/?page=register";}
			if(form == "login"){window.location = "http://www.avmatch.com/?page=login";}
			if(form == "profile"){window.location = "http://www.avmatch.com/?page=my_profile";}
		}else if(conftype == 3){
			form.whichsource.value='block';
			form.submit();
		}else if(conftype == 4){
			form.whichsource.value='unblock';
			form.submit();
		}else if(conftype == 5){
			form.whichsource.value='addfav';
			form.submit();
		}else if(conftype == 6){
			form.whichsource.value='remfav';
			form.submit();
		}
 	}
 	
function showDialog(delname,diagtype){
	
	var w = document.getElementById("overlay");	
	var x = document.getElementById("dialogtop_content");
	var y = document.getElementById("dialogtext");
	var z = document.getElementById("dialogbuttons");
	var xz = document.getElementById("dialogbuttons");
	
	//var userAgent = navigator.userAgent.toLowerCase();		
	//alert(!pattern7.test(userAgent));
		
	if(pattern6.test(userAgent) && !pattern7.test(userAgent)){
		//alert("IE 6!");
		var bwidth = document.documentElement.clientWidth;		
		w.style.position="absolute";
		w.style.width = bwidth + "px";
		w.style.backgroundImage="url(../"+dir+"spacer.gif)";
		
		if(document.getElementById('sortmenu')){
		 document.getElementById('sortmenu').style.display = "none";
		}
	}

	if(diagtype == 1){
		dialogTitle = document.createTextNode("Confirmation");
		//dialogBody = document.createTextNode("Would you like to delete '"+delname+"'? It cannot be undone.");
		var dialogBody2 = "Would you like to delete '"+delname+"'? It cannot be undone.";
		var buttons = "<a href='javascript:void(0);' ><img src='"+langdir+"ok.gif' alt='ok' border='0' onclick='confirmDialog(search,1);return false;' /></a>&nbsp;&nbsp;&nbsp;<a href='javascript:void(0);' ><img src='"+langdir+"cancelr.gif' alt='cancel' id='edit' border='0' onclick='closeDialog();' /></a>";
	}else if(diagtype == 2 || diagtype == 3){
		dialogTitle = document.createTextNode("Try our Advanced Search Tool!");
		//dialogBody = document.createTextNode("Our new advanced search tool allows you to narrow down your search results to help you find better matches! You can currently specify up to 50 qualities, and you can also save multple searches and return to them later. <b>This special too is available only to our members with a profile!</b> Not a member yet? Sign up today and start searching for your AvMatch!");
		var dialogBody2 = "Our new advanced search tool allows you to narrow down your search results to help you find better matches! Some of the features include: <ul><li>Search by avatar type</li><li>Average time spent in-world</li><li>Languages spoken</li><li>Type of relationship they are seeking</li><li>In-world activities</li><li>Real life age and gender</li><li>Save multple searches and more!</li></ul><b>This special tool is available only to our members with a profile!</b> ";
		var buttons = "<a href='javascript:void(0);' ><img src='"+langdir+"signup.gif' alt='login' border='0' onclick='confirmDialog(\"signup\",2);return false;' /></a>&nbsp;&nbsp;&nbsp;<a href='javascript:void(0);' ><img src='"+langdir+"loging.gif' alt='login' border='0' onclick='confirmDialog(\"login\",2);return false;' /></a>&nbsp;&nbsp;&nbsp;<a href='javascript:void(0);' ><img src='"+langdir+"closer.gif' alt='close' border='0' onclick='closeDialog();' /></a>";
		if(diagtype == 3){
			dialogBody2 = dialogBody2 + "Create your profile today and start searching for your AvMatch!";
			buttons = "<a href='javascript:void(0);' ><img src='"+langdir+"continueg.gif' alt='continue' border='0' onclick='confirmDialog(\"profile\",2);return false;' /></a>&nbsp;&nbsp;&nbsp;<a href='javascript:void(0);' ><img src='"+langdir+"closer.gif' alt='close' border='0' onclick='closeDialog();' /></a>";
		}else{
			dialogBody2 = dialogBody2 + "Not a member yet? Sign up today and start searching for your AvMatch!";
		}
	}else if(diagtype == 4){
		dialogTitle = document.createTextNode("Confirmation");		
		//dialogBody = document.createTextNode("Would you like to add '"+delname+"' to your blocked profiles list?");
		var dialogBody2 = "Would you like to add <b>'"+delname+"'</b> to your blocked profiles list?";
		var buttons = "<a href='javascript:void(0);' ><img src='"+langdir+"ok.gif' alt='ok' border='0' onclick='confirmDialog(flagblock,3);return false;' /></a>&nbsp;&nbsp;&nbsp;<a href='javascript:void(0);' ><img src='"+langdir+"cancelr.gif' alt='cancel' id='edit' border='0' onclick='closeDialog();' /></a>";
	}else if(diagtype == 5){
		dialogTitle = document.createTextNode("Flag Profile");
		var dialogBody2 = "This feature will be available very soon!";
		var buttons = "<a href='javascript:void(0);' ><img src='"+langdir+"ok.gif' alt='ok' border='0' onclick='closeDialog();' /></a>&nbsp;";
	}else if(diagtype == 6){
		dialogTitle = document.createTextNode("Confirmation");
		var dialogBody2 = "Would you like to remove <b>'"+delname+"'</b> from your blocked profiles list?";
		var buttons = "<a href='javascript:void(0);' ><img src='"+langdir+"ok.gif' alt='ok' border='0' onclick='confirmDialog(flagblock,4);return false;' /></a>&nbsp;&nbsp;&nbsp;<a href='javascript:void(0);' ><img src='"+langdir+"cancelr.gif' alt='cancel' id='edit' border='0' onclick='closeDialog();' /></a>";
	}else if(diagtype == 7){
		dialogTitle = document.createTextNode("Confirmation");		
		var dialogBody2 = "Would you like to add <b>'"+delname+"'</b> to your favorite profiles list?";
		var buttons = "<a href='javascript:void(0);' ><img src='"+langdir+"ok.gif' alt='ok' border='0' onclick='confirmDialog(flagblock,5);return false;' /></a>&nbsp;&nbsp;&nbsp;<a href='javascript:void(0);' ><img src='"+langdir+"cancelr.gif' alt='cancel' id='edit' border='0' onclick='closeDialog();' /></a>";
	}else if(diagtype == 8){
		dialogTitle = document.createTextNode("Confirmation");		
		var dialogBody2 = "Would you like to remove <b>'"+delname+"'</b> from your favorite profiles list?";
		var buttons = "<a href='javascript:void(0);' ><img src='"+langdir+"ok.gif' alt='ok' border='0' onclick='confirmDialog(flagblock,6);return false;' /></a>&nbsp;&nbsp;&nbsp;<a href='javascript:void(0);' ><img src='"+langdir+"cancelr.gif' alt='cancel' id='edit' border='0' onclick='closeDialog();' /></a>";
	}
	
	//You can currently specify multple features and options, and you can also save multple searches and return to them later.
	x.appendChild(dialogTitle);
	//y.appendChild(dialogBody);
	y.innerHTML = dialogBody2;
	xz.innerHTML = buttons; 
	w.style.zIndex="1000";
	w.style.display="block";
	w.style.visibility="visible";
}

function hideNotice(){
	if(document.getElementById("success")){
		document.getElementById("success").style.display = 'none';
	}
	
}

function addRemImage(myval, parent_id){
	
	var imageuploadform = 'imageuploadform';
	var showimagediv = 'showimagediv';
	var removeimagediv = 'removeimagediv';
	var uploadfieldid = 'imageuploadfield';
	
	if(myval == 3){
		document.getElementById(imageuploadform).style.display = 'block';
		document.getElementById(showimagediv).style.display = 'none';
		document.getElementById(removeimagediv).style.display = 'block';
	}
	
	if(myval == 4){
		document.getElementById(imageuploadform).style.display = 'none';
		document.getElementById(showimagediv).style.display = 'block';
		document.getElementById(removeimagediv).style.display = 'none';
		document.getElementById(uploadfieldid).value = '';
	}
	
}

function addRemFlickr(myval, parent_id){

//imageuploadform

	var flickrchanged = 0;
	var postflickrid = "postflickr";
	var postflickr_icon_id = "postflickr_icon";
	var flickrfieldid = "flickrlinkfield";
	var attachfieldsid = "attachfields";

	if(parent_id > 0){
		postflickrid = "postflickr"+parent_id;
		postflickr_icon_id = "postflickr_icon"+parent_id;
		flickrfieldid = "flickrlinkfield"+parent_id;
		attachfieldsid = "attachfields"+parent_id;
	}
	//on mouse down
	if(myval == 2 && flickrchanged == 0 && document.getElementById(flickrfieldid).value == initflick){
		document.getElementById(flickrfieldid).value = "";
		document.getElementById(flickrfieldid).focus();
		flickrchanged = 1;
	}

	if(myval == 3){
		document.getElementById(postflickrid).style.display = 'block';
		//document.getElementById(attachfieldsid).style.display = 'block';
		document.getElementById(postflickr_icon_id).style.display = 'none';
	}
	
	if(myval == 4){
		document.getElementById(postflickrid).style.display = 'none';
		//document.getElementById(attachfieldsid).style.display = 'none';
		document.getElementById(postflickr_icon_id).style.display = 'block';
		document.getElementById(flickrfieldid).value = initflick;
	}
}


//this function limits the #characters on a text input field
//id = id of text field, totchars = max # chars, writefield - div to update with #chars left
function remainChars(id,totchars, writefield){
	var len = document.getElementById(id).value.length;
	if(len > totchars){
		document.getElementById(id).value = document.getElementById(id).value.substring(0,totchars);
		var len = document.getElementById(id).value.length;	
	}
	var numleft = totchars - len;
	if (numleft == 0){
		document.getElementById(writefield).innerHTML = "You've reached " + totchars + " characters!";
	}else{
		document.getElementById(writefield).innerHTML = "";
	}
}

function dupSearchField(searchfield){
	//alert(searchfield);
	document.getElementById('searchfield1').value = searchfield;
	document.getElementById('searchfield2').value = searchfield;
}

//this function shows/hides the remember me login feature
function showRemem(thisform, thisname){
var hiddenname = thisform.usernameh.value;
var hiddenpass = thisform.userpassh.value;
var field = 'password';
//var hiddenname = document.logform.usernameh.value;
//var hiddenname = document.getElementById('usernameh').value;
	if(hiddenname != '' && hiddenpass != ''){ 
		if(thisform.username.value != hiddenname || thisform.passw.value != hiddenpass){
			document.getElementById('remembox').style.display = 'block';
		}else if(thisform.username.value == hiddenname && thisform.passw.value == hiddenpass){
			document.getElementById('remembox').style.display = 'none';
		}
	}
}

var newchatwin = false;
function popChat(url){
	if(newchatwin == false || newchatwin.closed){
		newchatwin=window.open(url,'chat',"height=380,width=620,top=200,left=260,scrollbars=no,resizable=yes");
		if(!firefoxpattern.test(userAgent)){ newchatwin.blur(); } 
		if (window.focus) {newchatwin.focus();}
	}else{
		if(!firefoxpattern.test(userAgent)){ newchatwin.blur(); } //newchatwin.blur();
		if (window.focus) {newchatwin.focus();}
	}
}

var newwindow;
function popup(url){ 
	newwindow=window.open(url,'name',"height=630,width=390,top=200,left=260,scrollbars=yes");
	if (window.focus) {newwindow.focus()}
}

function PopWindow(mypage, myname, w, h, scroll){
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
	win = window.open(mypage, myname, winprops)
	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

//-----------------------
//new showHid function that sets and reads help info cookie
function showHide(id){
var srcimg = 'img' + id;

var chelp1 = 0; //default - this variable will be set into cookie
var chelp2 = 0;
var chelp3 = 0;
var chelp4 = 0;
var chelp5 = 0;
var chelp6 = 0;
var chelp7 = 0;

var showhelpgif = langdir+'showhelp.gif';

var hidehelpgif = langdir+'hidehelp.gif';

var allcookies = document.cookie;

 var cookies = allcookies.replace(/ /g, '').split(';');
  for(var i = 0; i < cookies.length; i++) {
    // Does this cookie string begin with the name we want?
    //alert(cookies[i]);
    if (cookies[i].substring(0, cookie_prefix+"help".length+1) == (cookie_prefix+"help" + "=")) {        
        var cookie = cookies[i];
        break;
    }
  }
  if(cookie == null){
  }else{
    var cookval = decodeURIComponent(cookie.substring(cookie_prefix+"help=".length));
    var helpvalues = cookval.split('|');
    chelp1 = helpvalues[0];
    chelp2 = helpvalues[1];
    chelp3 = helpvalues[2];
    chelp4 = helpvalues[3];
    chelp5 = helpvalues[4];
    chelp6 = helpvalues[5];
    chelp7 = helpvalues[6];
  }

with (document.getElementById(id).style)
{ picswitch = display!='none' ? 0 : 1 }
with (document.getElementById(id).style)
{ display = display!='none' ? 'none' : 'block' }
	if (( picswitch == 0) && (id == 'help1')){
	//alert (id);
	document.getElementById(srcimg).src = showhelpgif;
	chelp1 = 0;
	}else if (( picswitch == 1) && (id == 'help1')){
	document.getElementById(srcimg).src = hidehelpgif;
	chelp1 = 1;
	}
	
	if (( picswitch == 0) && (id == 'help2')){
	//alert (id);
	document.getElementById(srcimg).src = showhelpgif;	
	chelp2 = 0;
	}else if (( picswitch == 1) && (id == 'help2')){
	document.getElementById(srcimg).src = hidehelpgif;
	chelp2 = 1;
	}
	
	if (( picswitch == 0) && (id == 'help3')){
	//alert (id);
	document.getElementById(srcimg).src = showhelpgif;
	chelp3 = 0;
	}else if (( picswitch == 1) && (id == 'help3')){
	document.getElementById(srcimg).src = hidehelpgif;
	chelp3 = 1;
	}
	
	if (( picswitch == 0) && (id == 'help4')){
	//alert (id);
	document.getElementById(srcimg).src = showhelpgif;
	chelp4 = 0;
	}else if (( picswitch == 1) && (id == 'help4')){
	document.getElementById(srcimg).src = hidehelpgif;
	chelp4 = 1;
	}
	
	if (( picswitch == 0) && (id == 'help5')){
	//alert (id);
	document.getElementById(srcimg).src = showhelpgif;
	chelp5 = 0;
	}else if (( picswitch == 1) && (id == 'help5')){
	document.getElementById(srcimg).src = hidehelpgif;
	chelp5 = 1;
	}
	
	if (( picswitch == 0) && (id == 'help6')){
	//alert (id);
	document.getElementById(srcimg).src = showhelpgif;
	chelp6 = 0;
	}else if (( picswitch == 1) && (id == 'help6')){
	document.getElementById(srcimg).src = hidehelpgif;
	chelp6 = 1;
	}
	
	if (( picswitch == 0) && (id == 'help7')){
	//alert (id);
	document.getElementById(srcimg).src = showhelpgif;
	chelp7 = 0;
	}else if (( picswitch == 1) && (id == 'help7')){
	document.getElementById(srcimg).src = hidehelpgif;
	chelp7 = 1;
	}
		
	//write the cookie because this function was called and something changed
  days = 365; // -ve for deleting it.
  var date = new Date();
  date.setTime(date.getTime ()+(days*24*60*60*1000));
  var expires = "; expires="+date.toGMTString();
	//alert(chelp1);
	document.cookie = cookie_prefix+"help=" + chelp1 + "|" + chelp2 + "|" + chelp3 + "|" + chelp4 + "|" + chelp5 + "|" + chelp6 + "|" + chelp7 + expires + "; path=/";
		
}

//---------------------------
//new setHelp function that sets basic help(in page) & cookie info for default help settings

function setHelp(helpswitch){
  var allcookies = document.cookie;
  //0 is hidden 
  var help1 = 0;
  var help2 = 0;
  var help3 = 0;
  var help4 = 0;
  var help5 = 0;
  var help6 = 0;
  var help7 = 0;

	var showhelpgif = langdir+'showhelp.gif';

	var hidehelpgif = langdir+'hidehelp.gif';

  var cookies = allcookies.replace(/ /g, '').split(';');
  for(var i = 0; i < cookies.length; i++) {
    // Does this cookie string begin with the name we want?
    //alert(cookies[i]);
    if (cookies[i].substring(0, cookie_prefix+"help".length+1) == (cookie_prefix+"help" + "=")) {        
        var cookie = cookies[i];
        break;
    }
  }
  if(cookie == null){
    //couldn't find the cookie - do this
    days = 365; // -ve for deleting it.
    var date = new Date();
    date.setTime(date.getTime ()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
       
    var setval = encodeURIComponent("0|0|0|0|0|1|1");
    //cookie doesn't exist yet, so let's set it /*"; max-age=" + (60*60*24*365) +*/
    document.cookie = cookie_prefix+"help=" + setval + expires + "; path=/";
  }else{
    var cookval = decodeURIComponent(cookie.substring(cookie_prefix+"help=".length));
    var helpvalues = cookval.split('|');
    help1 = helpvalues[0];
    help2 = helpvalues[1];
    help3 = helpvalues[2];
    help4 = helpvalues[3];
    help5 = helpvalues[4];
    help6 = helpvalues[5];
    help7 = helpvalues[6];
  }
    
  //ok we either read the cookie values or we wrote them
  if(helpswitch == 1){
    if(help1 == 1){
      //alert("help1");
      document.getElementById("help1").style.display = 'block';
      document.getElementById("imghelp1").src = hidehelpgif;
    }else{
      document.getElementById("help1").style.display = 'none';
      document.getElementById("imghelp1").src = showhelpgif;
    }
    if(help2 == 1){
      //alert("help2");
      document.getElementById("help2").style.display = 'block';
      document.getElementById("imghelp2").src = hidehelpgif;
    }else{
      //document.getElementById("help2").style.display = 'none';
      //document.getElementById("imghelp2").src = showhelpgif;
    }
  }else if(helpswitch == 2){
    if(help4 == 1){
      //alert("help4");
      document.getElementById("help4").style.display = 'block';
      document.getElementById("imghelp4").src = hidehelpgif;
    }else{
      document.getElementById("help4").style.display = 'none';
      document.getElementById("imghelp4").src = showhelpgif;
    }
      if(help5 == 1){
      //alert("help4");
      document.getElementById("help5").style.display = 'block';
      document.getElementById("imghelp5").src = hidehelpgif;
    }else{
      document.getElementById("help5").style.display = 'none';
      document.getElementById("imghelp5").src = showhelpgif;
    }
  }else if(helpswitch == 3){
  	
  	if(help3 == 1){
      //alert("help3");
      document.getElementById("help3").style.display = 'block';
      document.getElementById("imghelp3").src = hidehelpgif;
    }else{
      document.getElementById("help3").style.display = 'none';
      document.getElementById("imghelp3").src = showhelpgif;
    }
  
  }else if(helpswitch == 4 && document.getElementById("help6")){
  	
	  	if(help6 == 1){
	      document.getElementById("help6").style.display = 'block';
	      document.getElementById("imghelp6").src = hidehelpgif;
	    }else{
	      document.getElementById("help6").style.display = 'none';
	      document.getElementById("imghelp6").src = showhelpgif;
	    }    
	    if(help7 == 1){
	      document.getElementById("help7").style.display = 'block';
	      document.getElementById("imghelp7").src = hidehelpgif;
	    }else{
	      document.getElementById("help7").style.display = 'none';
	      document.getElementById("imghelp7").src = showhelpgif;
	    }
  }

}


function makeHttpRequest( to_url, callback_function, methtype, params, return_xml  ){
 
 var http_request, response, i;

 var activex_ids = ['MSXML2.XMLHTTP.3.0', 'MSXML2.XMLHTTP', 'Microsoft.XMLHTTP'];

 if (window.XMLHttpRequest) { // Mozilla, Safari, IE7+...
   http_request = new XMLHttpRequest();
   if (http_request.overrideMimeType) {
   		http_request.overrideMimeType('text/html');
  		//http_request.overrideMimeType('text/xml');
   }
 } else if (window.ActiveXObject) { // IE6 and older
   for (i = 0; i < activex_ids.length; i++) {
     try {
       http_request = new ActiveXObject(activex_ids[i]);
     } catch (e) {}
   }
 }

 if (!http_request) {
   //write custom function to prompt user with this
   //alert('Unfortunately your browser doesn’t support this feature.');
   return false;
 }

 http_request.onreadystatechange = function() {
   if (http_request.readyState !== 4) {
       // not ready yet
       return;
   }
   if (http_request.status !== 200) {
     // ready, but not OK
     //write custom pop up for this error
     //alert('There was a problem with the request.(Code: ' + http_request.status + ')');
     return;
   }
   if (return_xml) {
     response = http_request.responseXML;
   } else {
     response = http_request.responseText;
   }
   // invoke the callback
   callback_function(response);
 };
	//'GET'
 	http_request.open(methtype, to_url, true);
 
 	if(methtype == 'POST'){
 		http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		//http_request.setRequestHeader("Content-length", params.length);
		//http_request.setRequestHeader("Connection", "close");
 		http_request.send(params);
	}else{
 		http_request.send(null);
	}
}
