function URLEncode(plaintext)
{
	if (typeof(plaintext) == 'undefined') return '';
	return encodeURIComponent(plaintext);
}

function URLDecode(encoded) {
	if (typeof(encoded) == 'undefined') return '';
	return decodeURIComponent(encoded);
}

function error_filler(t, where, url) {
	$(where).innerHTML = '<div class="error">Error <b>' + t.status + '</b> in <b>' + url + '</b>: <b>' + t.statusText + '</b></div>';
}

var last_response_text = '';

function ajax_load(config) { //url, pars, where, evalonsuccess, hideloading) {
	if ((config.where != '') && (typeof(config.where) != 'undefined')) {
		if ($(config.where) != null) {
			if (config.hideloading == true) {
				//do nothing
			} else {
				var toinsert = '<span style="background:#CCFFCC;border:1px solid #77CC77;padding:3px;position:absolute;z-index:2">Loading...</span>'; //hardcoded loading
				$(config.where).innerHTML = toinsert + $(config.where).innerHTML;
			}
		} else {
			alert('id="' + config.where + '" not found. cannot load "' + config.url + '"');
		}
	}
	
	var myAjax = new Ajax.Request(
		config.url,
		{
			method: 'get',
			parameters: config.pars,
			onSuccess: function(t) {
				do_the_update = true;
				if (config.hideloading == true) {
					if (last_response_text == t.responseText) {
						do_the_update = false;
					} else {
						last_response_text = t.responseText;
					}
				}
				if ((do_the_update) && (config.where != '')) {
					$(config.where).innerHTML = t.responseText;
				}
				eval(config.onsuccess);
				t.responseText.evalScripts();
			},
			onFailure: function(t) {
				error_filler(t, config.where, config.url);
			}
		}
	);
}
function CheckFieldLength(id,count,maxchars) {
  var len = id.value.length;
  if (len > maxchars) {
    id.value = id.value.substring(0,maxchars);
    len = maxchars;
    document.getElementById(count).style.color = 'red';
    alert('Sorry, you have reached the character limit');    
  }
  if (len < maxchars-29) {
		document.getElementById(count).style.color = 'black';
	} else if (len < maxchars-14) {
		document.getElementById(count).style.color = 'orange';
	} else {
		document.getElementById(count).style.color = 'red';
	}
  document.getElementById(count).innerHTML = len;
}

var doi = 0;
function add_table_for_specialities(max) {
	if (doi < max) last_specialitie = max;
		else last_specialitie = doi;
//			alert(last_specialitie);
		for (i=1;i<=last_specialitie;i++)
		{
//			alert($('specialitie_'+i).value);
			if ($('specialitie_'+i).value == '') { var k = 1; break; } else k = 2;
		}
	if (k == 2)
	{
		last_specialitie++;
		tr=document.createElement('tr');
		td=document.createElement('td');
		td.align='right';
		td.innerHTML=last_specialitie+'.';
		tr.appendChild(td);
		td=document.createElement('td');
		td.innerHTML='<input type="text" style="width:190px" name="specialitie['+last_specialitie+']" id="specialitie_'+last_specialitie+'"/>'
		tr.appendChild(td);
		last_specialitie++;
		td=document.createElement('td');
		td.align='right';
		td.innerHTML=last_specialitie+'.';
		tr.appendChild(td);
		td=document.createElement('td');
		td.innerHTML='<input type="text" style="width:190px" name="specialitie['+last_specialitie+']" id="specialitie_'+last_specialitie+'"/>'
		tr.appendChild(td);
		$('table_for_specialities').appendChild(tr);
		if (doi < max) doi = max + 2;
			else doi = doi + 2;
		$('no_new_row_sp').innerHTML = '';
	}
	else $('no_new_row_sp').innerHTML = '<span class="warning">You dont need another row</span>';
}
var unu = 0;
function add_product_and_service(max) {
	if (unu < max) last_product_and_service = max;
		else last_product_and_service = unu;
		for (i=1;i<=last_product_and_service;i++)
		{
//			alert($('specialitie_'+i).value);
			if ($('product_'+i).value == '') { var k = 1; break; } else k = 2;
		}
	if (k == 2)
	{
		last_product_and_service++;
		tr=document.createElement('tr');
		td=document.createElement('td');
		td.align='right';
		td.innerHTML=last_product_and_service+'.';
		tr.appendChild(td);
		td=document.createElement('td');
		td.innerHTML='<input type="text" style="width:190px" name="product['+last_product_and_service+']" id="product_'+last_product_and_service+'"/>';
		tr.appendChild(td);
		last_product_and_service++;
		td=document.createElement('td');
		td.align='right';
		td.innerHTML=last_product_and_service+'.';
		tr.appendChild(td);
		td=document.createElement('td');
		td.innerHTML='<input type="text" style="width:190px" name="product['+last_product_and_service+']" id="product_'+last_product_and_service+'"/>';
		tr.appendChild(td);
		$('table_for_products_and_services').appendChild(tr);
		if (unu < max) unu = max + 2;
			else unu = unu + 2;
		$('no_new_row').innerHTML = '';
	}
	else $('no_new_row').innerHTML = '<span class="warning">You dont need another row</span>';
}

function isInteger(inputfield, inputevent) {
	var key;
	var keychar;

	if (window.event) {
		key = window.event.keyCode;
	} else if (inputevent) {
		key = inputevent.which;
	} else {
		return true;
	}
	
	keychar = String.fromCharCode(key);
	// control keys
	if ((key==null) || (key==0) || (key==8) ||
    		(key==9) || (key==13) || (key==27)) {
		return true;

	// numbers
	} else if (("0123456789").indexOf(keychar) > -1) {
		return true;
		
	} else {
		return false;
	}
}


//*** http://advertising.superpages.com/ ***/


function checkTelNo (telNo)
{
    if (telNo.value == "") return;
    if (telNo.value.match (".[0-9]{3}.[0-9]{3}-[0-9]{4}") == null)
    {
        if (telNo.value.match ("[0-9]{10}") != null)
            formatTelNo (telNo)              
    }
}

function formatTelNo (telNo)
{
    // If it's blank, save yourself some trouble by doing nothing.
    if (telNo.value == "") return;

    

    var phone = new String (telNo.value);
    
    phone = phone.substring(0,14);

    /*
    "." means any character. If you try to use "(" and ")", the regular expression becomes 
    complicated sice both are reserve characters and escaping them sometimes fails. So just 
    use "." for any character and replace it later.
    */
    if (phone.match (".[0-9]{3}.[0-9]{3}-[0-9]{4}") == null)
    {
        /*
        Following "if" is for user making any changes to the formatted tel. no. If you don't put this 
        "if" condition, the user can not correct a digit by first deleting it and then entering a 
        correct one, since this will fire two "onkeyup" events : first one on deleting a 
        character and second one on entering the correct one. The first "onkeyup" event will fire this 
        function which will reformatt the tel no before the user gets a chace to correct the digit. This 
        will surely confuse the user. The "if" condition below eliminates that.
        */
        if (phone.match (".[0-9]{2}.[0-9]{3}-[0-9]{4}|" + ".[0-9].[0-9]{3}-[0-9]{4}|" +
            ".[0-9]{3}.[0-9]{2}-[0-9]{4}|" + ".[0-9]{3}.[0-9]-[0-9]{4}") == null)
        {
            /*
            You will reach here only if the user is still typing the number or if he/she has 
            messed up already formatted number. 
            */
            var phoneNumeric = phoneChar = "", i;
            // Loop thru what user has entered.
            for (i=0;i<phone.length;i++)
            {
                // Go thru what user has entered one character at a time.
                phoneChar = phone.substr (i,1);
    
                // If that character is not a number or is a White space, ignore it. Only if it is a digit, 
                // concatinate it with a number string.
                if (!isNaN (phoneChar) && (phoneChar != " ")) phoneNumeric = phoneNumeric + phoneChar;
            }
    
            phone = "";
            // At this point, you have picked up only digits from what user has entered. Loop thru it.
            for (i=0;i<phoneNumeric.length;i++)
            {
                // If it's the first digit, throw in "(" before that.
                if (i == 0) phone = phone + "(";
                // If you are on the 4th digit, put ") " before that.
                if (i == 3) phone = phone + ") ";
                // If you are on the 7th digit, insert "-" before that.
                if (i == 6) phone = phone + "-";
                // Add the digit to the phone charatcer string you are building.
                phone = phone + phoneNumeric.substr (i,1)
            }
        }
    }
    else
    { 
        // This means the tel no is in proper format. Make sure by replacing the 0th, 4th and 8th character.
        phone = "(" + phone.substring (1,4) + ") " + phone.substring (5,8) + "-" + phone.substring(9,13); 
    }
    // So far you are working internally. Refresh the screen with the re-formatted value.
    if (phone != telNo.value) telNo.value = phone;
}

function add_date() {
//	alert('Monday -> '+document.getElementById('Monday').checked+', Tuesday -> '+document.getElementById('Tuesday').checked);
	ajax_load({
		url: root_address+'ajax.timeframe.php',
		pars: 'random='+Math.random() + '&Monday=' + $F('Monday') + 
										'&Tuesday=' + $F('Tuesday') + 
										'&Wednesday=' + $F('Wednesday') + 
										'&Thursday=' + $F('Thursday') + 
										'&Friday=' + $F('Friday') +
										'&Saturday=' + $F('Saturday') +
										'&Sunday=' + $F('Sunday') +
										'&hrs_from=' + $F('time_from') +
										'&hrs_to=' + $F('time_to'),
		hideloading: true,
		where: 'hrs_op'
	});
	
	document.getElementById('Monday').checked = false;
	document.getElementById('Tuesday').checked = false;
	document.getElementById('Wednesday').checked = false;
	document.getElementById('Thursday').checked = false;
	document.getElementById('Friday').checked = false;
	document.getElementById('Saturday').checked = false;
	document.getElementById('Sunday').checked = false;
}

function getHistoryMessage(date, groupid, groupname)
{
	ajax_load({
		url: root_address+'ajax.history_messages.php',
		pars: 'random=' + Math.random() + '&month=' + date +
							              '&groupid=' + groupid +
							              '&groupname=' + groupname,
		hideloading: true,
		where: 'allmessages'
	});
	
	
}

function echo() {
	
	if (document.getElementById('time_from').value == 'Open') { document.getElementById('time_to').value = document.getElementById('time_from').value; }
	else if (document.getElementById('time_from').value == 'Closed') { document.getElementById('time_to').value = document.getElementById('time_from').value; }
}

function printPage() {
  if (window.print)
    window.print()
  else
    alert("Sorry, your browser doesn't support this feature.");
}

function checkRewrite(rew) {
	if ($(rew).value != '') return $(rew).value;
	else return 0;
}function select(name, name_old, lvl, org_id)
{
	var pars='random='+Math.random()+'&name='+name+'&name_old='+name_old+'&lvl='+lvl+'&org_id='+org_id;where='tasks-container';
	var config=Array();config.url=root_address+'ajax.chaps_name.php';
	config.pars=pars;config.where=where;config.hideloading=true;ajax_load(config);
};

function select_(name, name_old, lvl, org_id)
{
	var pars='random='+Math.random()+'&name='+name+'&name_old='+name_old+'&lvl='+lvl+'&org_id='+org_id;where='tasks-container_';
	var config=Array();config.url=root_address+'ajax.chaps_name.php';
	config.pars=pars;config.where=where;config.hideloading=true;ajax_load(config);
};function getInfo(room_id) {
	ajax_load({
		where: 'chat_div',
		url: 'chat.php',
		pars: 'mode=refresh&room_id=' + room_id + '&random=' + Math.random(),
		hideloading: true
	});
}

function getInfo2(room_id) {
	ajax_load({
		where: '',
		url: 'chat.php',
		pars: 'mode=send&room_id=' + room_id + '&msg=' + URLEncode($('chat_textinput').value) + '&random=' + Math.random(),
		hideloading: true
	});
}

function chat_send(room_id){
	getInfo2(room_id);
	$('chat_textinput').value = '';
	$('chat_textinput').focus();
}


function chat_go(room_id){
	getInfo(room_id);
	window.setTimeout("chat_go(" + room_id + ")", 2000);
}
function chatrooms_select(care) {
	d = $('rooms_table');
	if (care == 1) {
		Element.addClassName(d, 'selunu');
		Element.removeClassName(d, 'seldoi');
		Element.show('rooms_table_1');
		Element.hide('rooms_table_2');
	} else {
		Element.removeClassName(d, 'selunu');
		Element.addClassName(d, 'seldoi');
		Element.hide('rooms_table_1');
		Element.show('rooms_table_2');
	}
}
function totype_select(what) {
	$('totype_div_organizations').style.display = 'none';
	$('totype_div_specific').style.display = 'none';
	$('totype_div_chapters').style.display = 'none';
	$('totype_div_' + what).style.display = 'block';
	return false;
}
function URLEncode(plaintext)
{
	if (typeof(plaintext) == 'undefined') return '';
	// The Javascript escape and unescape functions do not correspond
	// with what browsers actually do...
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";

	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
	    if (ch == " ") {
		    encoded += "+";				// x-www-urlencoded, rather than %20
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
/*			    alert( "Unicode Character '" 
                        + ch 
                        + "' cannot be encoded using standard URL encoding.\n" +
				          "(URL encoding only supports 8-bit characters.)\n" +
						  "A space (+) will be substituted." );
*/
				encoded += "+";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	} // for

	return encoded;
}

function deleteSelectedFriends() {
	x=document.getElementsByClassName('_friends_'); 
	for (i=0; i<x.length; i++) 
		if (x[i].checked == true)
			delete_friend(x[i].id);
}

function delete_friend(id) {
	ajax_load({
		url: root_address+'ajax.delete_friend.php',
		pars: 'random='+Math.random() + '&id=' + id,
		hideloading: true
	});
}

function deleteSelectedViewers() {
	x=document.getElementsByClassName('_friends_'); 
	for (i=0; i<x.length; i++) 
		if (x[i].checked == true)
			delete_viewer(x[i].id);
}

function delete_viewer(id) {
	ajax_load({
		url: root_address+'ajax.delete_viewer.php',
		pars: 'random='+Math.random() + '&id=' + id,
		hideloading: true
	});
}

function deleteSelectedAlbums() {
	x=document.getElementsByClassName('album'); 
	for (i=0; i<x.length; i++) 
		if (x[i].checked == true)
			delete_albums(x[i].id);
}

function delete_albums(id) {
	ajax_load({
		url: root_address+'ajax.delete_albums.php',
		pars: 'random='+Math.random() + '&id=' + id +
										'&gid=' + $('gid').value +
										'&gname=' + $('gname').value,
		hideloading: true
	});
}

function deleteFromGroup() {
	x=document.getElementsByClassName('delete_gr'); 
	for (i=0; i<x.length; i++) 
		if (x[i].checked == true)
			delete_fromGroup(x[i].id);
}

function delete_fromGroup(id) {
	ajax_load({
		url: root_address+'ajax.delete_fromGroup.php',
		pars: 'random='+Math.random() + '&id=' + id +
										'&gid=' + $('gid').value +
										'&gname=' + $('gname').value,
		hideloading: true
	});
}
function deleteFromDB(what, id) {
	ajax_load({
		url: root_address+'ajax.delete_record.php',
		pars: 'random='+Math.random() + '&id=' + id +
										'&what=' +what,
		hideloading: true
	});
}
function update_grinfo(id, email, notify, leave) {	
	ajax_load({
		url: root_address+'ajax.update_grinfo.php',
		pars: 'random='+Math.random() + '&id=' + id +
									  	'&email=' + email +
									  	'&notify=' + notify +
										'&leave=' + leave,
		hideloading: true,
		where: 'group_information_' + id
	});
}

function invite(action, id, fromid) {
	ajax_load({
		url: root_address+'ajax.invite.php',
		pars: 'random='+Math.random() + '&id=' + id +
										'&fromid=' + fromid +
									  	'&action=' + action,
		hideloading: true
	});
}

function add_signature(signature, message, orgid) {
	ajax_load({
		url: root_address+'ajax.profile_send_mess.php',
		pars: 'random='+Math.random() + '&signature=' + signature +
										'&message=' + message +
										'&orgid=' + orgid,
		hideloading: true,
		where: 'messge_textarea'
	});
}

function profileEdit(action, owner, friend) {
	ajax_load({
		url: root_address+'ajax.profile_edit.php',
		pars: 'random='+Math.random() + '&action=' + action +
										'&owner=' + owner +
										'&friend=' + friend,
		hideloading: true,
		where: 'update_profile'
	});
}

function addFr(action, owner, friend) {
	ajax_load({
		url: root_address+'ajax.profile_edit.php',
		pars: 'random='+Math.random() + '&action=' + action +
										'&owner=' + owner +
										'&friend=' + friend,
		hideloading: true,
		where: 'update_profile'
	});
}

function view_printable(){
	x = document.getElementsByClassName('noprint');
	for (i=0;i<x.length;i++) {
		x[i].style.display='none';
	}
}

function clearProfileMessageBox() {
	$('message').value = '';
	$('subject').value = '';
}

function validate(validare)
{
	if (validare == 'no_way')  {
		return true;
	}
	if(document.frm_reg.fname.value.length<1)
	{
		alert('Please enter your first name..!');
		document.frm_reg.fname.focus();
		return false;
	}
	if(document.frm_reg.lname.value.length<1)
	{
		alert('Please enter your last name..!');
		document.frm_reg.lname.focus();
		return false;
	}
	if(document.frm_reg.username.value.length<4)
	{
		alert('Please enter your username more than 4 letters..!');
		document.frm_reg.username.focus();
		return false;
	}
	if(document.frm_reg.newemail.value.length<2)
	{
		alert('Please enter your valid email address..!');
		document.frm_reg.newemail.focus();
		return false;
	}
	if(document.frm_reg.address.value.length<10)
	{
		alert('Please enter your address more than 10 letters..!');
		document.frm_reg.address.focus();
		return false;
	}
	if(document.frm_reg.zipcode.value.length<2)
	{
		alert('Please enter your zipcode..!');
		document.frm_reg.zipcode.focus();
		return false;
	}
	if(document.frm_reg.s_code.value.length<3)
	{
		alert('Please enter a valid security code..!');
		document.frm_reg.s_code.focus();
		return false;
	}
return true;
}

<!--******************************** by mahesh **************************************-->
function showemailmodify(id1,id2)
{
	document.getElementById(id1).style.display = 'block';
	document.getElementById(id2).style.display = 'none';
}

function valid(form_id,contact_email)
{
if(document.fm.contact_name.value=="")
	{
		alert('Please enter valid contact name');
		document.fm.contact_name.focus();
		return false;
	}
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   var address = document.forms[form_id].elements[contact_email].value;
   if(reg.test(address) == false)
    {
      alert('Invalid Email Address');
	  document.fm.contact_email.focus();
      return false;
   }
	if(document.fm.contact_phone.value=="")
	{
		alert('Please enter valid contact phone no');
		document.fm.contact_phone.focus();
		return false;
	}	
	return true;
}






function event_valid()
{
if(document.fm.event_name.value=="")
	{
		alert('Please enter valid event name');
		document.fm.event_name.focus();
		return false;
	}

	
	if(document.fm.event_date_Year.value=="")
	{
		alert('Please select date');
		document.fm.event_date_Year.focus();
		return false;
	}	
	
	if(document.fm.event_place.value=="")
	{
		alert('Please enter place/venue');
		document.fm.event_place.focus();
		return false;
	}	
	
	if(document.fm.event_address.value=="")
	{
		alert('Please enter address');
		document.fm.event_address.focus();
		return false;
	}	
	
	if(document.fm.event_city.value=="")
	{
		alert('Please enter city');
		document.fm.event_city.focus();
		return false;
	}	
	
	if(document.fm.event_state.value=="")
	{
		alert('Please enter state');
		document.fm.event_state.focus();
		return false;
	}
	
		if(document.fm.event_zip.value=="")
	{
		alert('Please enter zip code');
		document.fm.event_zip.focus();
		return false;
	}

	return true;
}
<!-- **************************************end***************************************** -->

function do_groups_category_search() {
	ajax_load({
		where: 'group_category_results_div',
		url: root_address + 'request.groups.create.find_cat.php',
		pars: 's=' + encodeURIComponent($F('group_category_search')) + '&random=' + Math.random(),
		hideloading: false
	});
}function quickpoll_save(answer_id) {
	ajax_load({
		where: 'quick_poll_div',
		url: 'quickpoll.php',
		pars: 'answer_id=' + answer_id + '&random=' + Math.random(),
		hideloading: true
	});
}
function do_the_body_scroll() {
	if ($('organization_id'))	$('organization_id'	).style.position = 'static';
	if ($('college_id'))		$('college_id'		).style.position = 'static';
	if ($('state_id'))			$('state_id'		).style.position = 'static';
	if ($('chapter_id'))		$('chapter_id'		).style.position = 'static';
}
function do_table_search() {
	$('table_search_spinner').style.visibility = 'visible';
	ajax_load(
		{
			url: root_address+'chapters_add_results',
			pars: 'search_var=' + encodeURIComponent($F('table_search_form')) + '&ajax=true&random=' + Math.random(),
			where: 'search_results',
			onsuccess: "$('table_search_spinner').style.visibility = 'hidden';",
			hideloading: true
		}
	);
}
var upgraded_shown = false;
function please_upgrade() {
	if (!upgraded_shown) {
		new Effect.SlideDown('the_upgrade_div');
		upgraded_shown = true;
	}
}

function please_upgrade_close() {
	if (upgraded_shown) {
		new Effect.SlideUp('the_upgrade_div');
		upgraded_shown = false;
	}
}
var next_upload_id = 0;
var the_justclassic = false;
var upload_to_set = 'not_yet_set';

function get_next_image_upload_place(justclassic) {
	if (justclassic == true) the_justclassic = true;
	plh = $('image_uploads_placeholder');
	var nnn = document.createElement('div');
	plh.appendChild(nnn);
	next_upload_id++;
	upload_to = upload_to_set;
	if ((flash_is_ok) && (the_justclassic != true)) {
		nnn.innerHTML = '<div id="image_upload_div_' + next_upload_id + '">' +
						'<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"' +
						'width="300" height="50"' +
						'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab">' +
						'<param name="movie" value="' + root_address + '_private/uploader.swf?id=' + next_upload_id + '&root_address=' + URLEncode(root_address) + '&upload_to=' + upload_to + '" />' +
						'<param name="menu" value="false" />' +
						'<param name="quality" value="high" />' +
						'<param name="wmode" value="transparent" /><param name="bgcolor" value="#ffffff" />' +
						'<embed src="' + root_address + '_private/uploader.swf?id=' + next_upload_id + '&root_address=' + URLEncode(root_address) + '&upload_to=' + upload_to + '" menu="false" quality="high" wmode="transparent" bgcolor="#ffffff" ' +
						'width="300" height="50" name="uploader" align="middle"' +
						'play="true"' +
						'loop="false"' +
						'quality="high"' +
						'allowScriptAccess="sameDomain"' +
						'type="application/x-shockwave-flash"' +
						'pluginspage="http://www.macromedia.com/go/getflashplayer">' +
						'<\/embed>' +
						'<\/object>' +
						'</div>' +
						'';
	} else {
		if ($('user_files_add_section_classic_span')) Element.hide('user_files_add_section_classic_span');
		nnn.innerHTML = '<div id="image_upload_div_' + next_upload_id + '">' +
						'<div class="image_upload_div">' +
						'<table border="0"><tr><td height="40">' +
						'<form id="image_upload_form_' + next_upload_id + '" target="image_upload_iframe_' + next_upload_id + '" action="' + root_address + 'ajax.upload.php" enctype="multipart/form-data" method="post">' +
						'<input type="hidden" name="MAX_FILE_SIZE" value="200000000" />' + //hardcoded max size 200 mega
						'<input type="hidden" name="id" value="' + next_upload_id + '" />' +
						'<input type="hidden" name="upload_to" value="' + upload_to + '" />' +
						'<span id="image_upload_span_' + next_upload_id + '">' +
						'<input id="file_' + next_upload_id + '" name="file_' + next_upload_id + '" type="file" value="file_' + next_upload_id + '" onchange="return upload_file(' + next_upload_id + ')" />' +
						'</span>' +
						'</form>' +
						'</td></tr></table>' +
						'</div>' +
						'</div>' +
						'<iframe name="image_upload_iframe_' + next_upload_id + '" width="400" height="200" style="display:none"></iframe>' +
						'';
	}
}

var upload_files_currently_uploading = 0;

function upload_file(id) {
	upload_files_currently_uploading++;
	Element.hide('image_uploads_save_div');
	Element.show('image_uploads_please_wait');
	if (upload_files_currently_uploading < 3) {
		get_next_image_upload_place();
	}
	obj = $('file_' + id);
	
	localfilename = obj.value;
	localfilename = localfilename.replace(/\\/g, '/');
	localfilename = localfilename.substring(localfilename.lastIndexOf('/') + 1);
	
	frm = $('image_upload_form_' + id);
	frm.submit();
	dv = $('image_upload_div_' + id);
	str = '';
	str += '<div class="image_upload_div"><table border="0" cellspacing="0" cellpadding="0"><tr><td height="40">';
	str += '<div style="border:1px solid #CCCCCC">'
	str += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="20" height="20" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab"><param name="movie" value="' + root_address + '_private/loading.swf" /><param name="menu" value="false" /><param name="quality" value="best" /><param name="wmode" value="transparent" /><param name="bgcolor" value="#ffffff" /><param name="scale" value="noscale" /><embed src="' + root_address + '_private/loading.swf" menu="false" quality="best" wmode="transparent" bgcolor="#ffffff" scale="noscale" width="20" height="20" align="middle" play="true" loop="false" quality="high" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed></object>';
	str += '</div>'
	str += '</td><td>&nbsp;</td><td>Uploading <b>' + localfilename + '</b></td></tr></table></div>';
	dv.innerHTML = str;
}

function upload_file_finished_callback(id, message, errid) {
	if (upload_files_currently_uploading >= 3) {
		get_next_image_upload_place();
	}
	upload_files_currently_uploading--;
	if (upload_files_currently_uploading == 0) {
		Element.show('image_uploads_save_div');
		Element.hide('image_uploads_please_wait');
	}
	msg = '';
	if (message == 'success') {
		msg = 'Done'; //hardcoded
		upload_file_close(id);
	} else {
		msg = 'Uploading Error ' + errid + ': '; //hardcoded
		switch (errid) {
			case '101':
				msg += 'Cannot insert file into database'; //hardcoded
			break;
		}
		msg += '<br />';
		msg += '<a href="javascript:;" onclick="this.blur();upload_file_close(\'' + id + '\', 1)">Hide</a>'; //hardcoded
	}
	message = '<div class="image_upload_div"><table border="0" cellspacing="0" cellpadding="0"><tr><td height="40">' + msg + '</td></tr></table></div>';
	
	dv = $('image_upload_div_' + id);
	if (dv) {
		dv.innerHTML = message;
	} else {
		alert('File is too large'); //file too large maybe, but the form doesn't submit...
	}
}

function upload_file_close(id, timeout) {
	if (!timeout) timeout = 1000;
	setTimeout("Effect.BlindUp('image_upload_div_" + id + "', {duration: 2.0});", timeout);
}

function flashUploader(status, filename, divid) {
	if (status == 'success') { //finished uploading
		if (upload_files_currently_uploading >= 3) {
			get_next_image_upload_place();
		}
		upload_files_currently_uploading--;
		if (upload_files_currently_uploading == 0) {
			Element.show('image_uploads_save_div');
			Element.hide('image_uploads_please_wait');
		}
		upload_file_close(divid);
	} else if (status == 'select') { //beginning uploading
		upload_files_currently_uploading++;
		Element.hide('image_uploads_save_div');
		Element.show('image_uploads_please_wait');
		if (upload_files_currently_uploading < 3) {
			get_next_image_upload_place();
		}
	}
}
function uploader_submit(id, onbegin, formname, root_address) {
	if (formname) {
		f = $(formname);
		f._old_target = f.target;
		f.target = 'iframe_' + id;
		
		f._old_action = f.action
		f.action = root_address + 'upload.php';
		
		f._old_enctype = f.enctype;
		f.enctype = 'multipart/form-data';
		
		f._old_method = f.method;
		f.method = 'post';
		
		$('stupid_uploader_id').value = id;
		
		f.submit();
		
		f.target = f._old_target;
		f.action = f._old_action;
		f.enctype = f._old_enctype;
		f.method = f._old_method;
	} else {
		$('form_' + id).submit();
	}
	
	Element.hide('span_complete_' + id);
	Element.hide('span_input_' + id);
	Element.show('span_uploading_' + id);
	filename = $('input_' + id).value;
	filename = filename.replace(/\\/g, '/');
	filename = filename.substr(filename.lastIndexOf('/') + 1);
	if (filename == '') {
		filename = 'file deleted';
		Element.hide('span_delete_' + id);
	} else {
		Element.show('span_delete_' + id);
	}
	$('span_filename_' + id).innerHTML = filename;
	$('span_filename2_' + id).innerHTML = filename;
	//$('span_input_' + id).innerHTML = '';
	$('span_input_' + id).innerHTML = $('span_input_' + id).innerHTML;
	eval(onbegin);
}

var string_to_execute = '';

function execute(str) {
	top.string_to_execute = str;
}

setInterval('execute_the_string()', 100);

function execute_the_string() {
	if ((string_to_execute) && (string_to_execute != '')) {
		eval(string_to_execute);
		string_to_execute = '';
	}
}

