var timer = new Array();
var delay = 0;
var original_class = 'nav';
var highlight_class = 'nav_hover';
function dropDown(id,action,options,links,orig,cntr) {
	if(action=='clear') {
		var all_fields = document.getElementById('all_fields').value;
		var all_fields = all_fields.split(",");
		for(var i=0;i<all_fields.length;i++) {
			if(all_fields[i]!=id) {
				if(document.getElementById(all_fields[i])) {
					document.getElementById('menu_'+all_fields[i]+'_left').className = 'actblank';
					document.getElementById('menu_'+all_fields[i]+'_bgd').className = 'actblankbgd';
					document.getElementById('menu_'+all_fields[i]+'_right').className = 'actblank';
					document.getElementById('menu_'+all_fields[i]).className = original_class;
					document.getElementById(all_fields[i]).style.display = 'none';
				}
			}
		}
	}
	if(action=='show') {
		document.getElementById('menu_'+id+'_left').className = 'actleft';
		document.getElementById('menu_'+id+'_bgd').className = 'actbgd';
		document.getElementById('menu_'+id+'_right').className = 'actright';
		document.getElementById('menu_'+id).className = highlight_class;
		if(!document.getElementById(id)) {
			var options = options.split("#");
			var links = links.split("#");
            var newdiv = document.createElement('div');
			newdiv.setAttribute('id', id);
			newdiv.style.position = 'absolute';
			newdiv.style.width = '190px';
			newdiv.style.display = 'none';
			newdiv.style.textAlign = 'left';
			var html = '';
			var styleadd = '';
			for(var i = 0;i<options.length;i++) {
                styleadd = '';
				if(i==(options.length - 1)) styleadd = 'style="border-bottom:0px;" ';
				html += '<a '+styleadd+'onMouseOver="dropDown(\''+id+'\',\'clear\',\'\',\'\',\'\',\''+cntr+'\');" onMouseOut="dropDown(\''+id+'\',\'set\',\'\',\'\',\'\',\''+cntr+'\');" class="dropdown" href="'+links[i]+'">'+options[i]+'</a>';
			}
			newdiv.innerHTML = html;
			document.body.appendChild(newdiv);
		}
		var all_fields = document.getElementById('all_fields').value;
		var all_fields = all_fields.split(",");
		for(var i=0;i<all_fields.length;i++) {
			if(all_fields[i]!=id) {
				if(document.getElementById(all_fields[i])) {
					document.getElementById('menu_'+all_fields[i]).className = original_class;
					document.getElementById(all_fields[i]).style.display = 'none';
				}
			}
		}
		var target = document.getElementById(id);
		var top = parseInt(orig.offsetHeight);
		var curleft = curtop = 0;
		if(orig.offsetParent) {
			do {
				curleft += orig.offsetLeft;
				curtop += orig.offsetTop;
			} while (orig = orig.offsetParent);
		}
		var top = top + curtop - 1;
		var top = top+'px';
		var left = curleft - 5;
		var left = left+'px';
		target.style.display = 'block';
        target.style.top = top;
        target.style.left = left;
		window.clearTimeout(timer[cntr]);
	}
	if(action=='clear') {
		window.clearTimeout(timer[cntr]);
	}
	if(action=='set') {
		timer[cntr] = window.setTimeout("dropDown('"+id+"','hide','','','','"+cntr+"');", delay);
	}
	if(action=='hide') {
		var target = document.getElementById(id);
	    target.style.display = 'none';
		document.getElementById('menu_'+id+'_left').className = 'actblank';
		document.getElementById('menu_'+id+'_bgd').className = 'actblankbgd';
		document.getElementById('menu_'+id+'_right').className = 'actblank';
		document.getElementById('menu_'+id).className = original_class;
	}
}

function change_classes(id,dir) {
	if(dir=='Over') {
		document.getElementById('menu_'+id+'_left').className = 'actleft';
		document.getElementById('menu_'+id+'_bgd').className = 'actbgd';
		document.getElementById('menu_'+id+'_right').className = 'actright';
	} else if(dir=='Out') {
		document.getElementById('menu_'+id+'_left').className = 'actblank';
		document.getElementById('menu_'+id+'_bgd').className = 'actblankbgd';
		document.getElementById('menu_'+id+'_right').className = 'actblank';
	}
}

function validateEmail(vEmail, vEmailValue) {
var err = 0;
if (vEmailValue=='') return true;
var invalidChars = '\/\'\\ ";:?!()[]\{\}^|';
for (i=0; i<invalidChars.length; i++) {
   if (vEmailValue.indexOf(invalidChars.charAt(i),0) > -1) err = 1;
}
for (i=0; i<vEmailValue.length; i++) {
   if (vEmailValue.charCodeAt(i)>127) err = 1;
}

var atPos = vEmailValue.indexOf('@',0);
if (atPos == -1) err = 1;
if (atPos == 0)  err = 1;
if (vEmailValue.indexOf('@', atPos + 1) > - 1)  err = 1;
if (vEmailValue.indexOf('.', atPos) == -1)  err = 1;
if (vEmailValue.indexOf('@.',0) != -1)  err = 1;
if (vEmailValue.indexOf('.@',0) != -1)  err = 1;
if (vEmailValue.indexOf('..',0) != -1)  err = 1;
var suffix = vEmailValue.substring(vEmailValue.lastIndexOf('.')+1);
if (suffix.length != 2 && suffix != 'com' && suffix != 'net' && suffix != 'org' && suffix != 'edu' && suffix != 'int' && suffix != 'mil' && suffix != 'gov' & suffix != 'arpa' && suffix != 'biz' && suffix != 'aero' && suffix != 'name' && suffix != 'coop' && suffix != 'info' && suffix != 'pro' && suffix != 'museum')  err = 1;
if(err)
	{
	alert("Email address in invalid");
	globalvar = vEmail;
	setTimeout("globalvar.focus()",250);
	setTimeout("globalvar.select()",250);
	return false;
	}
return true;
}

function submitenter(myform,a,e) {
	if(e.keyCode==13) {
	   myform.action2.value=a;
	   myform.submit();
	   return false;
	} else return true;
}
function checkReqdFields(formName) {
	theForm = document.getElementById(formName);
	ms = false;
	rdName = '';
	var failed = '';
	var radioviewed = new Array();
	var failed = new Array();
	for (i=0; i < theForm.elements.length; i++) {
		ele = theForm.elements[i];
		if(ele.className=="radio_rqd"&&!checkArray(radioviewed,ele.name)) {
			if(getRadioValue(ele.name)=='') { ms = true; failed[failed.length] = ele.name; }
            radioviewed[radioviewed.length] = ele.name;
		}
		if(ele.className=="checkbox_rqd"&&ele.checked==false) { ms = true; failed[failed.length] = ele.name; }
		if(ele.className=="text_rqd"&&ele.value=='') { ms = true; failed[failed.length] = ele.name; }
		if(ele.className=="select_rqd"&&ele.value=='') { ms = true; failed[failed.length] = ele.name; }
	}
	if(ms) {
		alert('You have not completed all the required fields');
//		alert(failed)
		return false;
	} else return true;
}
function checkArray(arrayvalue,newname) {
	var foundit = false;
	for(var t=0;t<arrayvalue.length;t++) {
		if(arrayvalue[t]==newname) foundit = true;
	}
	return foundit;
}
function conditionPrice(price) {
	price = price.toString();
	if(price.indexOf(".")!='-1') {
		var new_price = Math.round(price*100)/100;
		new_price = new_price.toString();
		var location = new_price.indexOf(".");
		if(location=='-1') new_price = new_price+'.00';
		else if(new_price.length==(location+2)) new_price = new_price+'0';
	} else var new_price = price+'.00';
	return new_price;
}
function selectPlan(id) {
	var australian_countryID = document.getElementById('australian_countryID').value;
	var countryID = document.getElementById('countryID').value;
	var cost_target = document.getElementById('cost_display');
	var cost_row = document.getElementById('cost_row');
	var gst_target = document.getElementById('gst_display');
	var gst_row = document.getElementById('gst_row');
	var gst_rate = document.getElementById('gst_rate').value;
	if(id=='') {
		var j = document.signup_form.planID.length;
		for(var i=0;i<j;i++) {
			if(document.getElementById('planID'+i).checked==true) id = i;
		}
	}
	if(id>=0) {
		var rate = document.getElementById('planID'+id+'_cost');
		if(countryID==australian_countryID) {
			if(rate.value>0.00) gst_target.value = conditionPrice(rate.value/gst_rate)+' AUD';
			else gst_target.value = 'N/A';
			if(rate.value>0.00) cost_target.value = conditionPrice(rate.value*((gst_rate/100)+1))+' AUD';
			else cost_target.value = 'FREE';
			gst_row.style.display = '';
			cost_row.style.display = '';
		} else {
			if(rate.value>0.00) cost_target.value = conditionPrice(rate.value)+' AUD';
			else cost_target.value = 'FREE';
			gst_row.style.display = 'none';
			cost_row.style.display = '';
		}
	}
}

function selectSMS(id) {
	var australian_countryID = document.getElementById('australian_countryID').value;
	var countryID = document.getElementById('countryID').value;
	var cost_target = document.getElementById('cost_display');
	var cost_row = document.getElementById('cost_row');
	var gst_target = document.getElementById('gst_display');
	var gst_row = document.getElementById('gst_row');
	if(id=='') {
		var j = document.signup_form.planID.length;
		for(var i=1;i<=j;i++) {
			if(document.getElementById('planID'+i).checked==true) id = i;
		}
	}
	if(id!='') {
		var rate = document.getElementById('planID'+id+'_cost').value;
		if(countryID==australian_countryID) {
			if(rate>0.00) gst_target.innerHTML = '$'+conditionPrice(rate/10);
			else gst_target.innerHTML = 'N/A';
			if(rate>0.00) cost_target.innerHTML = '$'+conditionPrice(rate*1.1);
			else cost_target.innerHTML = 'FREE';
			gst_row.style.display = '';
			cost_row.style.display = '';
		} else {
			if(rate>0.00) cost_target.innerHTML = '$'+conditionPrice(rate);
			else cost_target.innerHTML = 'FREE';
			gst_row.style.display = 'none';
			cost_row.style.display = '';
		}
	}
}

var ie5 = (document.all && document.getElementById) ? true : false;
function numbersOnly(e,field_name) {
	if(ie5) var e = event;
	var target = document.getElementById(field_name);
	var strCheck = '8,9,13,17,18,19,20,27,33,34,35,36,37,38,39,40,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,91,92,93,95,96,97,98,99,100,101,102,103,104,105,112,113,114,115,116,117,118,119,120,121,122,123,144,145';
	if(strCheck.indexOf(e.keyCode)=='-1') {
		current = target.value;
		current = current.substr(0,(current.length - 1));
		target.value = current;
	}
}

function setRadioValue(name,crrntvalue) {
	var foundit = true;
	var t = 0;
	while(foundit) {
		if(document.getElementById(name+t)) {
        	if(crrntvalue==document.getElementById(name+t).value) document.getElementById(name+t).checked = true;
		} else foundit = false;
		t++;
	}
}

function getRadioValue(name) {
	var foundit = true;
	var returnvalue = '';
	var t = 0;
	while(foundit) {
		if(document.getElementById(name+t)) {
        	if(document.getElementById(name+t).checked==true) var returnvalue = document.getElementById(name+t).value;
		} else foundit = false;
		t++;
	}
	return returnvalue;
}

function getLeft(objectId) {
	s = objectId;
	sLeft = s.offsetLeft;
	while(s.offsetParent!=null) {
		sParent = s.offsetParent;
		sLeft += sParent.offsetLeft;
		s = sParent;
	}
	return sLeft;
}

function getTop(objectId) {
	s = objectId;
	sTop = s.offsetTop;
	while(s.offsetParent!=null) {
		sParent = s.offsetParent;
		sTop += sParent.offsetTop;
		s = sParent;
	}
	return sTop;
}

function displayBox(obj,val,cntr,hour) {
	if(!document.getElementById('displayBox')) {
		var div = document.createElement("div");
		div.id = 'displayBox';
		div.style.width = '150px';
		div.style.height = '19px';
		div.style.paddingTop = '5px';
		div.style.textAlign = 'left';
		div.style.paddingLeft = '6px';
		div.style.backgroundColor = '#FFFFFF';
		div.style.border = '1px solid #5F5F5F';
		div.style.display = 'none';
		div.style.position = 'absolute';
		div.style.fontSize = '11px';
		document.body.appendChild(div);
	}
	var target = document.getElementById('displayBox');
	var sLeft = getLeft(obj);
	var sTop = getTop(obj);
	if(cntr==1) target.style.border = '2px solid #6F93D4';
	if(cntr==2) target.style.border = '2px solid #8DC068';
	if(cntr==3) target.style.border = '2px solid #E09E48';
	target.style.top = (sTop - 30)+'px';
	if(hour>17) target.style.left = (sLeft - 161)+'px';
	else target.style.left = (sLeft + 8)+'px';
	target.innerHTML = val;
	target.style.display = 'block';
}
function updateCheckedLetter(cntr,resID,obj) {
	var pageno = document.getElementById('page').value;
	var stringvals = document.getElementById('carry_over').value;
	var setYes = false;
	if(obj.checked==true) setYes = true;
	else setYes = false;
	stringvals = stringvals.split("@");
	pagevals = stringvals[(pageno - 1)];
	pagevals = pagevals.split("#");
	if(setYes) pagevals[cntr] = 'Y';
	else pagevals[cntr] = '';
	stringvals[(pageno - 1)] = pagevals.join("#");
	document.getElementById('carry_over').value = stringvals.join("@");
}
function updateCheckedPage(dir) {
	if(dir) dir = 'Y';
	else dir = '';
	var pageno = document.getElementById('page').value;
	var checkvals = document.getElementById('matching_ids').value;
	checkvals = checkvals.split("@");
	pgvals = checkvals[(pageno - 1)];
	pgvals = pgvals.split("#");
	for(var t=0;t<pgvals.length;t++) {
		var resID = pgvals[t];
		if(dir=='Y') document.getElementById('check['+resID+']').checked = true;
		else document.getElementById('check['+resID+']').checked = false;
		updateCheckedLetter(t,resID,document.getElementById('check['+resID+']'));
	}
}

