var main_script_url = "/cgi-bin/members/execute.pl";
	
function slide_section(p_idx,idx){
	//var obj = document.getElementById('slide_section_'+p_idx+'_panel_'+idx);
	//if(obj) obj.style.display = 'block';
	if(!document.all){
		eval("slide_section_"+p_idx+"_"+idx+".slideit();");
		//random_#p_idx#_#idx#
		//slide_section_#p_idx#_#idx#
		var t = setTimeout("togglePanels('random_"+p_idx+"_"+idx+"');",1000);
	}else{
		togglePanels('slide_section_'+p_idx+'_panel_'+idx);
	}
}

function set_and_submit_form(frmname,dataset,val_list,confirm){
	var frmObj = document.forms[frmname];
	var confirm_result = (confirm == '')?1:window.confirm(confirm);
	if(frmObj){
		var data = dataset.split(',');
		//alert('Data: '+data);
		for(var idx=0;idx<data.length;idx++){
			var pair = data[idx];
			var bits = pair.split('=');
			//alert('Pair: '+pair);
			
			var name = bits[0];
			var value = bits[1];
			
			var obj = document.forms[frmname][name];
			if(obj){
				obj.value = value;
			}else{
				alert('Could not set '+name+' in form '+frmname+' to '+value);
			}
		}
		
		if(val_list != ''){			//IF VAL LIST IS PRESENT CHECK AGAINST FORM FIRST
			if(confirm_result) submit_form(frmname,val_list);
		}else{
			if(confirm_result) frmObj.submit();
		}
	}else{
		alert("Cant find form object with name '"+frmname+"'");
	}
}

function set_form_fields(frmname,dataset,confirm){
	var frmObj = document.forms[frmname];
	var confirm_result = (confirm == '')?1:window.confirm(confirm);
	if(frmObj){
		if(confirm_result){
			var data = dataset.split(',');
			//alert('Data: '+data);
			for(var idx=0;idx<data.length;idx++){
				var pair = data[idx];
				var bits = pair.split('=');
				//alert('Pair: '+pair);
				
				var name = bits[0];
				var value = bits[1];
				
				var obj = document.forms[frmname][name];
				if(obj){
					obj.value = value;
				}else{
					alert('Could not set '+name+' in form '+frmname+' to '+value);
				}
			}
		}
	}else{
		alert("Cant find form object with name '"+frmname+"'");
	}
}

function copyToField(sourcefield,destfieldname){
	//alert(sourcefield+" <=> "+destfieldname);
	var sourceObj = document.getElementById(sourcefield);
	var destObj = document.getElementById(destfieldname);
	if(destObj && sourceObj){
		destObj.value = sourceObj.value;
	}
}

function toggleAtoZ(targetcontainer,targetid){
	var containerObj = document.getElementById(targetcontainer);
	if(containerObj){
		var elements = containerObj.getElementsByTagName("div");
		//alert(elements.length);
		for(var x=0;x<elements.length;x++){
			var eObj = elements[x];
			if(eObj && eObj.id){
				//alert(eObj.id);
				var display = (eObj.id.search(targetid) != -1 || eObj.id.search('layer_') == -1)?"block":"none";
				eObj.style.display = display;
			}
		}
	}else{
		alert("Can't find a to z container obj.");
	}
}


function toggleAtoZLayersWithContent(targetcontainer,targetids){
	var containerObj = document.getElementById(targetcontainer);
	if(containerObj){
		var elements = containerObj.getElementsByTagName("div");
		//alert(elements.length);
		var target_list = ','+targetids+','; 
		for(var x=0;x<elements.length;x++){
			var eObj = elements[x];
			if(eObj && eObj.id){
				//alert(eObj.id);
				var display = (target_list.search(','+eObj.id+',') != -1 || eObj.id.search('layer_') == -1)?"block":"none";
				eObj.style.display = display;
			}
		}
	}else{
		alert("Can't find a to z container obj.");
	}
}

function togglePanels(ids){
	//alert("ID LIST: "+ids);
	var elements = ids.split(',');
	for(var x=0;x<elements.length;x++){
		var obj = document.getElementById(elements[x]);
		if(obj){
			obj.style.display = (obj.style.display == 'none')?'block':'none';
			//alert("SET TO: "+obj.style.display);
		}
	}
}

function show_a_to_z_item(section,type,passed_id){
	//alert("Show "+type+" from the "+section+" section >>> ITEM: "+passed_id);
	if(section == 'visual_art' || section == 'dance' || section == 'performance_art'){
		if(type == 'galleries'){
			location.href = main_script_url+'?ac=view_gallery&galleryid='+passed_id;
		}else if(type == 'profiles'){
			location.href = main_script_url+'?ac=view_profile&profileid='+passed_id;
		}
	}else if(section == 'music'){
		if(type == 'selection'){
			location.href = main_script_url+'?ac=view_gallery&galleryid='+passed_id;
		}else if(type == 'profiles'){
			location.href = main_script_url+'?ac=view_profile&profileid='+passed_id;
		}
	}else if(section == 'writing'){
		if(type == 'writings'){
			location.href = main_script_url+'?ac=view_collection&collectionid='+passed_id;
		}else if(type == 'profiles'){
			location.href = main_script_url+'?ac=view_profile&profileid='+passed_id;
		}
	}else{
		alert("No programing for section - '"+section+"'");
	}
}

function toggle_list_item(id){
	var obj = document.getElementById(id);
	if(obj) obj.className = (obj.className == 'off')?'on':'off';
} 

function toggle_a_to_z_item(id){
	var obj = document.getElementById(id);
	if(obj) obj.className = (obj.className == 'off')?'on':'off';
} 

function bounce_secure(){
//	var href = location.href;
//	if(href.search('https://') == -1){
//		location.href = href.replace('http://','https://');
//	}
}

function popup_control(url,type,title,width,height){
	//alert("URL: "+url+"  Window Type: "+windowtype);
	if(url != 0 && url != '' && location.href != url){
		OpenWindow(new Array(0,url,title,width,height,0,1,0,0,0,0,0));		
	}
}

function toggle_div_group(containerid,execptionid){
	var containerObj = document.getElementById(containerid);
	if(containerObj){
		var elements = containerObj.getElementsByTagName("div");
		//alert(elements.length);
		for(var x=0;x<elements.length;x++){
			var eObj = elements[x];
			if(eObj && eObj.id){
				//alert(eObj.id);
				var display = (eObj.id == execptionid)?"block":"none";
				eObj.style.display = display;
			}
		}
	}else{
		alert("Can't find container obj '"+containerid+"'");
	}
}

function close_upload_popup(){
	var uploadPopup = document.getElementById('upload_popup');
	if(uploadPopup){
		var iframe = document.getElementById('upload_iframe');
		if(iframe) iframe.src = "/images/spacer.gif";
		uploadPopup.style.display = 'none';
		toggle_popup_underlay(0);
	}else{
		alert("Can't find upload popup div");
	}
}

function OpenWindow(action) {
	//alert(action[1]);
	var wf = "";
	wf = wf + "top=10,left=10";
	wf = wf + ",width=" + action[3];
	wf = wf + ",height=" + action[4];
	wf = wf + ",resizable=" + (action[5] ? "yes" : "no");
	wf = wf + ",scrollbars=" + (action[6] ? "yes" : "no");
	wf = wf + ",menubar=" + (action[7] ? "yes" : "no");
	wf = wf + ",toolbar=" + (action[8] ? "yes" : "no");
	wf = wf + ",directories=" + (action[9] ? "yes" : "no");
	wf = wf + ",destination=" + (action[10] ? "yes" : "no");
	wf = wf + ",status=" + (action[11] ? "yes" : "no");
	return window.open(action[1],action[2],wf);
}

function toggle_popup_underlay(onoff){
	var layerObj = document.getElementById('transparent_layer');
	var contentTab = document.getElementById('content_table');
	if(layerObj){
		var setHeight = (contentTab)?contentTab.clientHeight:1000;
		if(onoff) window.scrollTo(0,0);
		layerObj.style.display = (onoff)?'block':'none';
		layerObj.style.height = setHeight+'px';
		//alert(setHeight);
	}
}

function reply_to_message(messageid,onoff){
	toggle_popup_underlay(onoff);
	var contactObj = document.getElementById('contact_popup');
	var contactIframe = document.getElementById('contact_iframe');
	if(contactObj && contactIframe){
		contactIframe.src = (onoff)?main_script_url + "?ac=send_reply_to_message&messageid="+messageid:"/images/spacer.gif";
		contactObj.style.display = (onoff)?'block':'none';
	}else{
		alert("Contact panel ssi not present in page..");
	}
}

function contact_user(profileid,onoff){
	toggle_popup_underlay(onoff);
	var contactObj = document.getElementById('contact_popup');
	var contactIframe = document.getElementById('contact_iframe');
	if(contactObj && contactIframe){
		//CANCEL BUBBLE CODE
		//if (!e) var e = window.event;
		//e.cancelBubble = true;
		//if (e.stopPropagation) e.stopPropagation();

		contactIframe.src = (onoff)?main_script_url + "?ac=contact_user&profileid="+profileid:"/images/spacer.gif";
		contactObj.style.display = (onoff)?'block':'none';
	}else{
		alert("Contact panel ssi not present in page..");
	}
}

function speak_section_of_text(targetformid,onoff){
	toggle_popup_underlay(onoff);
	var targetObj = document.getElementById(targetformid);
	var speechDiv = document.getElementById('speech_popup');
	var speechIframe = document.getElementById('speech_iframe');
	if(speechIframe){
		if(targetObj){
			var passText = escape(targetObj.innerHTML);
			speechIframe.src = (onoff)?"/cgi-bin/infxwidgets/widget-speech.pl?mode=iframe&text="+passText:"/images/spacer.gif";
			speechDiv.style.display='block';
		}else if(targetformid == -1 && onoff == 0){
			speechIframe.src = "/images/spacer.gif";
			speechDiv.style.display='none';
		}else{
			alert("Target object '"+targetformid+"'not found can speak text..");
			toggle_popup_underlay(0);
		}
	}else{
		alert("Speech panel ssi not present in page..");
	}
}

function view_profile(profileid){
	//CANCEL BUBBLE CODE
	//if (!e) var e = window.event;
	//e.cancelBubble = true;
	//if (e.stopPropagation) e.stopPropagation();
	if(profileid != ''){
		location.href = main_script_url + "?ac=view_profile&profileid="+profileid;
	}else{
		alert("No profile ID specified..");
	}
}

function load_link(url){
	if(url != '' && url != location.href){
		location.href = url;
	}
}