function empt(){}

function more(myPage, windowName, myWidth, myHeight, scroll, resize){
	LeftPosition= (screen.width*0.5)-(myWidth*0.5);
	TopPosition= (screen.height*0.4)-(myHeight*0.5);
	window.open(myPage, windowName, 'width='+myWidth+',height='+myHeight+',top='+TopPosition+',left='+LeftPosition+',scrollbars=' + scroll + ',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=' + resize);
}


function ConfirmGeneral(alert_msg){
	a = confirm(alert_msg);
	if (a) return true;
	else return false;
}


function NewWindow(mypage,myname,w,h,isscroll){
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	settings = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+isscroll+',resizable';
	window.open(mypage,myname,''+settings+'');
}


function verifyData() {
	if (document.getElementById('firstName').value == '') {alert('First name cannot be empty!');document.getElementById('firstName').focus();return false;}
	if (document.getElementById('lastName').value == '') {alert('Last name cannot be empty!');document.getElementById('lastName').focus();return false;}
	if (document.getElementById('newComm').value == '') {alert('Commisison cannot be empty!');document.getElementById('newComm').focus();return false;}
	if (isNaN(document.getElementById('newComm').value)) {alert('New Commission must be a number!');document.getElementById('newComm').focus();return false;}
	if (document.getElementById('recurComm').value == '') {alert('Recurring commission cannot be empty!');document.getElementById('recurComm').focus();return false;}
	if (isNaN(document.getElementById('recurComm').value)) {alert('Recurring commission must be a number!');document.getElementById('recurComm').focus();return false;}
	return true;
}



function changeToMoney(nowField){
	tmpValue2=""
	tmpValue = document.getElementById(nowField).value;
	tmpValue = tmpValue.replace(/[^0-9]/ig,"");
	if(tmpValue > 999){
		countNo=0;
		for (i=tmpValue.length; i>=0; i--){
			countNo++;
			tmpValue2 = tmpValue.substr(i,1) + tmpValue2;
			if (countNo>=4){
				countNo=1;
				tmpValue2 = "," + tmpValue2;
				}
			}
		tmpValue = tmpValue2;
		}
	if (tmpValue.substr(0,1)==",") tmpValue=tmpValue.substr(1,tmpValue.length-1);
	if (tmpValue.length>1) if (tmpValue.substr(0,1)=="0") tmpValue=tmpValue.substr(1,tmpValue.length-1);
	document.getElementById(nowField).value=tmpValue;
}

function changeToNumeric(nowField, max_val){
	tmpValue = document.getElementById(nowField).value;
	tmpValue = tmpValue.replace(/[^-^0-9]/ig, "");
	document.getElementById(nowField).value=tmpValue;
	if(max_val!=-1)if(document.getElementById(nowField).value*1>max_val)document.getElementById(nowField).value=max_val;
}

function changeToNumericDec(nowField, max_val){
	tmpValue = document.getElementById(nowField).value;
	tmpValue = tmpValue.replace(/[^-^0-9^"."]/ig, "");
	document.getElementById(nowField).value=tmpValue;
	if(max_val!=-1)if(document.getElementById(nowField).value*1>max_val)document.getElementById(nowField).value=max_val;
}

function error_me(element, message){
	document.getElementById(element).focus();
	alert(message);
	return false;
}

/*function changeToNumeric(nowField){
	tmpValue = document.getElementById(nowField).value;
	tmpValue = tmpValue.replace(/[^0-9]/ig,"");
	document.getElementById(nowField).value=tmpValue;
}*/

function changeToPhone(nowField){
	tmpValue = document.getElementById(nowField).value;
	tmpValue = tmpValue.replace(/[^0-9]/ig,"");
	if ((tmpValue.substr(0,3)=="000")||(tmpValue.substr(0,3)=="555")) tmpValue = "";
	document.getElementById(nowField).value=tmpValue;
}

function limitFieldChars(nowField, max_chars, notifyField){
	tmpCount = nowField.value.length;
	if (notifyField) document.getElementById(notifyField).innerHTML = (max_chars - tmpCount);
	if(tmpCount > max_chars) nowField.value = nowField.value.substring(0, max_chars);
}

function expand(elem){
	if (document.getElementById(elem).className=='hidden') document.getElementById(elem).className='visible';
	else document.getElementById(elem).className='hidden';
}


function expand_layer(show_elem, hide_elem){
	if (document.getElementById(show_elem).className != 'visible') {
		document.getElementById(show_elem).className='visible';
		document.getElementById(hide_elem).className='hidden';
	} else {
		document.getElementById(show_elem).className='hidden';
		document.getElementById(hide_elem).className='visible';
	}
}

function expand_layer_dyn(show_elem, hide_elem, iden, total_elems){
	tmp_elem = "";
	if (eval[show_elem]) {
		if (eval[show_elem] != "") {
			document.getElementById(eval[show_elem]).className='hidden';
			document.getElementById(eval[hide_elem]).className='visible';
			tmp_elem = eval[show_elem];
			if (total_elems) {
				for (i=2; i <= total_elems; i++){
					document.getElementById(eval[show_elem] + '_' + i).className='hidden';
					document.getElementById(eval[hide_elem] + '_' + i).className='visible';
				}
			}
		}
	}
	if (tmp_elem != (show_elem + iden)) {
		document.getElementById(show_elem + iden).className='visible';
		document.getElementById(hide_elem + iden).className='hidden';
		eval[show_elem] = show_elem + iden;
		eval[hide_elem] = hide_elem + iden;
		if (total_elems) {
			//alert(document.getElementById(show_elem + iden + '_' + 2).className);
			for (i=2; i <= total_elems; i++){
				document.getElementById(show_elem + iden + '_' + i).className='visible';
				document.getElementById(hide_elem + iden + '_' + i).className='hidden';
			}
		}
	} else {
		eval[show_elem] = "";
		eval[hide_elem] = "";
	}
}

/*function mousePosX(event) {
	pos = event.offsetX?(event.offsetX):event.pageX-0;
	return pos + 'px';
}

function mousePosY(event) {
	pos = event.offsetY?(event.offsetY):event.pageY-0;
	return pos + 'px';
}*/

/*function mousePosX(e) {
	if (document.all?true:false) pos = event.clientX + document.body.scrollLeft;
	else pos = e.pageX;
	if (pos < 0){pos = 0;}
	return pos + 'px';
}

function mousePosY(e) {
	if (document.all?true:false) pos = event.clientY + document.body.scrollTop;
	else pos = e.pageY;
	if (pos < 0){pos = 0;}
	return pos + 'px';
}*/

/*var IE = document.all?true:false;
document.onmousemove = getMouseXY;
function getMouseXY(e) {
	if (IE) {
		tempX = event.clientX + document.body.scrollLeft;
		tempY = event.clientY + document.body.scrollTop;
	} else {
		tempX = e.pageX;
		tempY = e.pageY;
	}  
	if (tempX < 0){tempX = 0;}
	if (tempY < 0){tempY = 0;}  
	document.Show.MouseX.value = tempX;
	document.Show.MouseY.value = tempY;
	return true;
}*/

function findPos(obj, coordsOf) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
			} while (obj = obj.offsetParent);
	}
	if (coordsOf) {
		if (coordsOf == "x") return curleft;
		else if (coordsOf == "y") return curtop;
	} else return [curleft,curtop];
}

function loading(elem){
	if (document.getElementById('floating_div_loading').className == 'floating_div visible') document.getElementById('floating_div_loading').className = 'floating_div hidden';
	else {
		if (elem) document.getElementById('floating_div_loading').style.top = ((findPos(elem, "y") - 250) + 'px');
		document.getElementById('floating_div_loading').className = 'floating_div visible';
		}
}

function left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0, n);
}

function right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}


//=====================================================AJAX
function getHTTPObject() {
	var xhr = false;
	if(window.XMLHttpRequest) {
		var xhr = new XMLHttpRequest();
	} else if(window.ActiveXObject) {
		try {
			var xhr = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e) {
			try {
				var xhr = new ActiveXObject("Microsoft.XMLHTTP");
			} catch(e) {
				xhr = false;
			}
		}
	}
	return xhr;
}

var ajaxWorking = false;
function doAjax(httpPath, vals, method, sync) {
	var http = getHTTPObject();

	//vals => all values i'm entering. all value must transferred as string; devided by  |~|. 
	//ex: 'state=AR|~|phone=212-111-1111|~|active=1'
	
	if (http && !ajaxWorking) {
		vals_break = "";
		if (vals != "") {
			vals = vals.split("|~|");
			for (i = 0; i < vals.length; i++) {
				variable = vals[i].substr(0, vals[i].indexOf("="));
				value = "";
				value = vals[i].substr(vals[i].indexOf("=") + 1, vals[i].length);
				if (value != "") {
					if (vals_break != "") vals_break += "&";
					vals_break += variable + "=" + escape(value);
				}
			}
		}
		if (vals_break=="") vals_break = null;
		
		http.open(method, httpPath, sync);
		http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajaxWorking = true;
		http.send(vals_break);
		http.onreadystatechange = function(){
			if (http.readyState == 4) {
				ajaxWorking = false;
				//alert('VALUES:\n' + vals_break + '\n\nHTML:\n' + http.responseText);
				if (http.status == 200) ajaxSuccess(http.responseXML);
				else ajaxFail();
			}
		}
	}
}