/***********************************************
* Switch Content script- © Dynamic Drive (www.dynamicdrive.com)
* This notice must stay intact for legal use. Last updated April 2nd, 2005.
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

/*
var enablepersist="off" //Enable saving state of content structure using session cookies? (on/off)
var collapseprevious="yes" //Collapse previously open content when opening present? (yes/no)

var contractsymbol='- ' //HTML for contract symbol. For image, use: <img src="whatever.gif">
var expandsymbol='+ ' //HTML for expand symbol.
var currentemail="";

function getElementbyClass(rootobj, classname){
var temparray=new Array()
var inc=0
var rootlength=rootobj.length
for (i=0; i<rootlength; i++){
if (rootobj[i].className==classname)
temparray[inc++]=rootobj[i]
}
return temparray
}

function sweeptoggle(ec){
var thestate=(ec=="expand")? "block" : "none"
var inc=0
while (ccollect[inc]){
ccollect[inc].style.display=thestate
inc++
}
revivestatus()
}


function contractform(omit){

	var inc=0
	while (ccollect[inc]){
	if (ccollect[inc].id!=omit)
	ccollect[inc].style.display="none"
	inc++
	}

}

function expandform(curobj, cid){
	clearForm();
	disableFormObjects(false);

	var spantags=curobj.getElementsByTagName("SPAN")
	var showstateobj=getElementbyClass(spantags, "showstate")
	if (ccollect.length>0){
	if (collapseprevious=="yes")
	contractform(cid)
	document.getElementById(cid).style.display=(document.getElementById(cid).style.display!="block")? "block" : "none"
	if (showstateobj.length>0){ //if "showstate" span exists in header
		if (collapseprevious=="no")
			showstateobj[0].innerHTML=(document.getElementById(cid).style.display=="block")? contractsymbol : expandsymbol
		else
			revivestatus()
	}

}



}
*/

/** New stuff **/

function showContactForm(name, id){
	
	// load the selected name's content into form
	$('#contactdialog span#name').html(name);
	$('#contactdialog input#contactid').val(id);
	
	// reset all form fields
	$('#contactdialog .contactinput').removeAttr('disabled').val('');
	$('#contactdialog input#send_button').removeClass('accentbutton').val('Submit');

	// display form
	$('#contactdialog').jqmShow();

}

/** End New Stuff **/

/*
function changename(name, email, position){
	document.getElementById("n").innerHTML=name;
	//document.getelementbyid('test').onclick='alert(\'hello js 2\')'); 
	currentemail = email;

	// move the contact form
	// position = 'top' || 'bottom
	// div id = sub_form

	switch(position) {
		case "top":
			document.getElementById('sub_form').style.top="200px";
			break;
		case "bottom":
			document.getElementById('sub_form').style.top="500px";
			break;
		default:
			break;
	}

}
*/

/*
function revivecontent(){
contractform("omitnothing")
selectedItem=getselectedItem()
selectedComponents=selectedItem.split("|")
for (i=0; i<selectedComponents.length-1; i++)
document.getElementById(selectedComponents[i]).style.display="block"
}

function revivestatus(){
var inc=0
while (statecollect[inc]){
if (ccollect[inc].style.display=="block")
statecollect[inc].innerHTML=contractsymbol
else
statecollect[inc].innerHTML=expandsymbol
inc++
}
}

function do_onload(){
uniqueidn=window.location.pathname+"firsttimeload"
var alltags=document.all? document.all : document.getElementsByTagName("*")
ccollect=getElementbyClass(alltags, "switchcontent")
statecollect=getElementbyClass(alltags, "showstate")
if (enablepersist=="on" && ccollect.length>0){
document.cookie=(get_cookie(uniqueidn)=="")? uniqueidn+"=1" : uniqueidn+"=0" 
firsttimeload=(get_cookie(uniqueidn)==1)? 1 : 0 //check if this is 1st page load
if (!firsttimeload)
revivecontent()
}
if (ccollect.length>0 && statecollect.length>0)
revivestatus()
}

if (window.addEventListener)
window.addEventListener("load", do_onload, false)
else if (window.attachEvent)
window.attachEvent("onload", do_onload)
else if (document.getElementById)
window.onload=do_onload

if (enablepersist=="on" && document.getElementById)
window.onunload=saveswitchstate
*/

function sendContactForm(form){

	var jForm = $(form);

	// validate data
	if ( jForm.find("input#name").val() == "" ){
		// didn't enter a name
		alert("The name field is required. Please enter your name.");
		return false;
	}

	var data = jForm.serialize();
	var url = baseUrl + "/onlinemessage/sendmessage.php";

	// disable all text boxes
	jForm.find(".contactinput").attr('disabled', 'disabled');
	jForm.find('input#send_button').val('Sending Message...');

	$.ajax({
		type: "post",
		url: url,
		data: data,
		success: function(msg){
			if(msg == 'success'){
				jForm.find('input#send_button').addClass('accentbutton').val('Your Message Has Been Sent');
				setTimeout(function(){
					// hide dialog
					$('#contactdialog').jqmHide();
				},3000);
			}else{
				jForm.find('input#send_button').val('Unable to Send Message').addClass('accentbutton');
			}
		},
		failure : function(msg){
			jForm.find('input#send_button').val('Unable to Send Message').addClass('accentbutton');
		}
	});

	return false;
}
/*
function sendMessage(email){
	// hide form
	//contractform()
	if (document.getElementById("send_button").value == "Sent... Click to Close" || document.getElementById("send_button").value == "Message Failed To Send... Close" || document.getElementById("send_button").value == "Server Script Error... Close"){

		contractform();
		document.getElementById("send_button").value = "Send Message";
		document.getElementById("send_button").className="normalbutton";

	}else{
			//var frm = document.messageform;
		// verify that proper information was entered
		if ( document.getElementById("name").value == "" )
		{
			// didn't enter a name
			alert("The name field is required. Please enter your name.");

		}else{

			// disable all text boxes
			disableFormObjects(true);

			// change text to sending
			document.getElementById("send_button").value="Sending Message...";

			// Start timer to add periods

			// send message
			connect(email, document.getElementById("name").value, document.getElementById("e").value, document.getElementById("p").value, "ONLINE MESSAGE FROM: " + document.getElementById("name").value, document.getElementById("m").value);
		}
	}

}

function disableFormObjects( a ){ // a = true|false

	// enable/disable all text boxes
	document.getElementById("name").disabled=a;
	document.getElementById("e").disabled=a;
	document.getElementById("m").disabled=a;
	document.getElementById("send_button").disabled=a;

}

function clearForm() {
	document.getElementById("name").value="";
	document.getElementById("e").value="";
	document.getElementById("p").value="";
	document.getElementById("m").value="";

}

function connect( t, n, email, p, s, m) { // to, name, e-mail, subject, message, text box for response
  var xmlhttp = false;
  try {
   xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  } catch (e) {
	  
   try {
    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
   } catch (E) {
    xmlhttp = false;
   }
  }
  if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	  try
	  {
		xmlhttp = new XMLHttpRequest();
	  }catch (E){
		  alert("Error creating XMLHttpRequest");
	  }
  }

  var l = new Array();
	try{
	  xmlhttp.onreadystatechange=function() {
	   if (xmlhttp.readyState==4) {
		l = xmlhttp.responseText;
		if ( l == 'success' ){
			document.getElementById("send_button").value = "Sent... Click to Close";
			document.getElementById("send_button").className="accentbutton";
			//tb.innerHTML = "Message Sent Successfully";
			//contractform();
		}else if ( l == 'failure' ){
			document.getElementById("send_button").value = "Message Failed To Send... Close";
			document.getElementById("send_button").className="accentbutton";
			//contractform();
		}else{
			document.getElementById("send_button").value = "Server Script Error... Close";
			document.getElementById("send_button").className="accentbutton";
			//contractform();
		}
		// disable form objects, except for Send/Close button
		disableFormObjects(true);
		document.getElementById("send_button").disabled=false;

		// clear form
		clearForm();

	   }
	  }
  
		var url = "onlinemessage/sendmessage.php?t=" + escape(t) + "&n=" + escape(n) + "&e=" + escape(email) + "&p=" + escape(p) + "&s=" + escape(s) + "&m=" + escape(m)
		
	  xmlhttp.open("GET", url, true); // CHANGE THIS!!!
	  xmlhttp.send(null);
  
  }catch (E){
	  // unable to send via xml
	  connect_safe( t, n, email, p, s, m);
		
  }
}

function connect_safe( t, n, email, p, s, m) {

	site = "onlinemessage/sendmessage_safe.php?t=" + escape(t) + "&n=" + escape(n) + "&e=" + escape(email) + "&p=" + escape(p) + "&s=" + escape(s) + "&m=" + escape(m);
	myRef = window.open(site,'connect_safe', 'left=100,top=100,width=250,height=250,toolbar=1,resizable=0');

	contractform();
	document.getElementById("send_button").value = "Send Message";
	document.getElementById("send_button").className="normalbutton";

}
*/
