// JavaScript Document
function makeObject(){
	var x;
	var browser = navigator.appName;
	if(browser == "Microsoft Internet Explorer"){
		x = new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		x = new XMLHttpRequest();
	}
	return x;
}
var request = makeObject();

function intOnly(i,decPlaces) {
	if(i.value.length>0) {
		i.value = i.value.replace(/[^\d]+/g, ''); 
	}
}

function trimString (str) {
  str = this != window? this : str;
  return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
}//end trim string

function convertFormDataToPostContent(form_name) { 
var content_to_submit = ''; 
var form_element; 
var last_element_name = ''; 
for (i = 0; i < form_name.elements.length; i++) { 
	form_element = form_name.elements[i];
 	switch (form_element.type) { 
		// Text fields, hidden form elements 
		case 'text': 
		case 'hidden': 
		case 'password': 
		case 'textarea': 
		case 'select-one': 
			content_to_submit += form_element.name + '=' + escape(form_element.value) + '&' 
			break; 
		// Radio buttons 
		case 'radio': 
			if (form_element.checked) { 
				content_to_submit += form_element.name + '='  + escape(form_element.value) + '&'
 			}		 
			break; 
		// Checkboxes 
		case 'checkbox': 
			if (form_element.checked) { 
				// Continuing multiple, same-name checkboxes 
				if (form_element.name == last_element_name) { // Strip of end ampersand if there is one
 					if (content_to_submit.lastIndexOf('&') ==  content_to_submit.length - 1) { 
						content_to_submit = content_to_submit.substr( 0, content_to_submit.length - 1);
					} // Append value as comma-delimited string
					content_to_submit += ',' + escape(form_element.value); 
				} else { 
					content_to_submit += form_element.name + '='  + escape(form_element.value); 
				} 
				content_to_submit += '&'; 
				last_element_name = form_element.name;
			} 
			break; 
	} 
} 
	// Remove trailing separator 
	content_to_submit = content_to_submit.substr(0, content_to_submit.length - 1); 
	return content_to_submit; 
}

function chkVal(frm){
	var obj = frm.elements;
	var flag = 0;
	for(var i=0;i<(obj.length-1);i++){
			var val = trimString(obj[i].value);
			if(val != "")	flag++;
			//alert(flag);
			//alert(obj[i].name);
	}
	if(flag<6){
		alert("You seem to have missed a question.\n All questions require an answer.");
	}else{//submit form through ajax
		var done = function () {
			try {
				document.getElementById("dv_tbl").innerHTML = request.responseText;
				Fat.fade_element("dv_tbl", 200, 1000, "#5A99BA");
			}
			catch (exc) {
				document.getElementById("dv_msg").innerHTML = "An error occured <br />" +
					"Message: " + exc.message + "<br />" +
					"File: " + exc.fileName + "<br />" +
					"Line: " + exc.lineNumber + "<br />" +
					"Name: " + exc.name;
			}
		};
		var url="objects/advisors/process.php";
		request.open("POST", url, true);
		var content = convertFormDataToPostContent(frm);
		request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		request.setRequestHeader("Content-length", content.length);
		request.setRequestHeader("Connection", "close");
		var bAsync = true;
		if (bAsync) {
			request.onreadystatechange = function () {
				if (request.readyState == 4)
					done();
			}
			document.getElementById("dv_tbl").innerHTML = "<blink>Processing...</blink>";
		}
		request.send(content);		
		if (!bAsync) {
			done();
		}		
	}
}//end chkVal()

/*
\\\\\\\\\\\\\\\\\\\\\\\\\
fade anything technique\\
\\\\\\\\\\\\\\\\\\\\\\\\\
*/

// FADE ANYTHING TECHNIQUE

// @name      The Fade Anything Technique
// @namespace http://www.axentric.com/aside/fat/
// @version   1.0-RC1
// @author    Adam Michela

var Fat = {
	make_hex : function (r,g,b) 
	{
		r = r.toString(16); if (r.length == 1) r = '0' + r;
		g = g.toString(16); if (g.length == 1) g = '0' + g;
		b = b.toString(16); if (b.length == 1) b = '0' + b;
		return "#" + r + g + b;
	},
	fade_all : function ()
	{
		var a = document.getElementsByTagName("*");
		for (var i = 0; i < a.length; i++) 
		{
			var o = a[i];
			var r = /fade-?(\w{3,6})?/.exec(o.className);
			if (r)
			{
				if (!r[1]) r[1] = "";
				if (o.id) Fat.fade_element(o.id,null,null,"#"+r[1]);
			}
		}
	},
	fade_element : function (id, fps, duration, from, to) 
	{
		if (!fps) fps = 30;
		if (!duration) duration = 3000;
		if (!from || from=="#") from = "#FFFF33";
		if (!to) to = this.get_bgcolor(id);
		
		var frames = Math.round(fps * (duration / 1000));
		var interval = duration / frames;
		var delay = interval;
		var frame = 0;
		
		if (from.length < 7) from += from.substr(1,3);
		if (to.length < 7) to += to.substr(1,3);
		
		var rf = parseInt(from.substr(1,2),16);
		var gf = parseInt(from.substr(3,2),16);
		var bf = parseInt(from.substr(5,2),16);
		var rt = parseInt(to.substr(1,2),16);
		var gt = parseInt(to.substr(3,2),16);
		var bt = parseInt(to.substr(5,2),16);
		
		var r,g,b,h;
		while (frame < frames)
		{
			r = Math.floor(rf * ((frames-frame)/frames) + rt * (frame/frames));
			g = Math.floor(gf * ((frames-frame)/frames) + gt * (frame/frames));
			b = Math.floor(bf * ((frames-frame)/frames) + bt * (frame/frames));
			h = this.make_hex(r,g,b);
		
			setTimeout("Fat.set_bgcolor('"+id+"','"+h+"')", delay);

			frame++;
			delay = interval * frame; 
		}
		setTimeout("Fat.set_bgcolor('"+id+"','"+to+"')", delay);
	},
	set_bgcolor : function (id, c)
	{
		var o = document.getElementById(id);
		o.style.backgroundColor = c;
	},
	get_bgcolor : function (id)
	{
		var o = document.getElementById(id);
		while(o)
		{
			var c;
			if (window.getComputedStyle) c = window.getComputedStyle(o,null).getPropertyValue("background-color");
			if (o.currentStyle) c = o.currentStyle.backgroundColor;
			if ((c != "" && c != "transparent") || o.tagName == "BODY") { break; }
			o = o.parentNode;
		}
		if (c == undefined || c == "" || c == "transparent") c = "#FFFFFF";
		var rgb = c.match(/rgb\s*\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)/);
		if (rgb) c = this.make_hex(parseInt(rgb[1]),parseInt(rgb[2]),parseInt(rgb[3]));
		return c;
	}
}	

/*
ksm Feb2006
*/