// JavaScript Document


// Set Netscape up to run the "captureMousePosition" function whenever
// the mouse is moved. For Internet Explorer and Netscape 6, you can capture
// the movement a little easier.
if (document.layers) { // Netscape
    document.captureEvents(Event.MOUSEMOVE);
    document.onmousemove = captureMousePosition;
} else if (document.all) { // Internet Explorer
    document.onmousemove = captureMousePosition;
} else if (document.getElementById) { // Netcsape 6
    document.onmousemove = captureMousePosition;
}
// Global variables
xMousePos = 0; // Horizontal position of the mouse on the screen
yMousePos = 0; // Vertical position of the mouse on the screen
xMousePosMax = 0; // Width of the page
yMousePosMax = 0; // Height of the page

function captureMousePosition(e) {
    if (document.layers) {
        // When the page scrolls in Netscape, the event's mouse position
        // reflects the absolute position on the screen. innerHight/Width
        // is the position from the top/left of the screen that the user is
        // looking at. pageX/YOffset is the amount that the user has
        // scrolled into the page. So the values will be in relation to
        // each other as the total offsets into the page, no matter if
        // the user has scrolled or not.
        xMousePos = e.pageX;
        yMousePos = e.pageY;
        xMousePosMax = window.innerWidth+window.pageXOffset;
        yMousePosMax = window.innerHeight+window.pageYOffset;
    } else if (document.all) {
        // When the page scrolls in IE, the event's mouse position
        // reflects the position from the top/left of the screen the
        // user is looking at. scrollLeft/Top is the amount the user
        // has scrolled into the page. clientWidth/Height is the height/
        // width of the current page the user is looking at. So, to be
        // consistent with Netscape (above), add the scroll offsets to
        // both so we end up with an absolute value on the page, no
        // matter if the user has scrolled or not.
        xMousePos = window.event.x + document.documentElement.scrollLeft;
        yMousePos = window.event.y + document.documentElement.scrollTop;
        xMousePosMax = document.body.clientWidth+document.documentElement.scrollLeft;
        yMousePosMax = document.body.clientHeight+document.documentElement.scrollTop;
    } else if (document.getElementById) {
        // Netscape 6 behaves the same as Netscape 4 in this regard
        xMousePos = e.pageX;
        yMousePos = e.pageY;
        xMousePosMax = window.innerWidth+window.pageXOffset;
        yMousePosMax = window.innerHeight+window.pageYOffset;
    }
}

function fncCenteredChildWindow(URL,vHeight,vWidth,vScroll,vStatus) {
	if (screen.width) {
		var winl=(screen.width-vWidth)/2;
		var wint=(screen.height-vHeight)/2;
	} else { 
		winl=0;wint=0;
	}
	if(winl<0)winl=0;
	if(wint<0)wint=0;
	window.open(URL,'myWin','height='+vHeight+',width='+vWidth+',scrollbars='+vScroll+',status='+vStatus+',top='+wint+',left='+winl+',resizable=no')
}
function setFormValue(field,n_value){
	document.getElementById(field).value = n_value;
}

function disableListManagerButtons(xform){

	if(xform.save_button)
		xform.save_button.disabled=true; //DISABLE THE SUBMIT BUTTON
	
	if(xform.save_close_button)
		xform.save_close_button.disabled=true; //DISABLE THE SUBMIT BUTTON
}

function saveListingForm(next_value){

	var bErrors = false;
	var bErrorStr = '';
	
	var xform = document.listManagerForm;

	//error checking

	//this value tells the form where to redirect after saving
	xform.nextMode.value = next_value;
	
	//TODO: do some error checking
	
	//submit xform POST
	if(bErrors){
		alert(bErrorStr);
	}else{
		//disable all the news story form buttons
		disableListManagerButtons(xform);
	
		//alert('submit');
		xform.submit();
	}

}

function showHelp(help_text){
	//alert('show '+help_id);
	toggleMoveLayer( 'editHelp', xMousePos, yMousePos, help_text );
}

function hideHelp(help_text){
	//alert('hide '+help_id);
	toggleMoveLayer( 'editHelp', xMousePos, yMousePos, help_text );
}

function toggleMoveLayer( whichLayer, new_x, new_y, help_text )
{
  var elem, vis;
  if( document.getElementById ){ // this is the way the standards work
    elem = document.getElementById( whichLayer );
  }else if( document.all ){ // this is the way old msie versions work
      elem = document.all[whichLayer];
	  new_x = new_x + document.body.clientWidth;
	  new_y = new_y + document.body.clientHeight;
  }else if( document.layers ){ // this is the way nn4 works
    elem = document.layers[whichLayer];
  }
  vis = elem.style;
  // if the style.display value is blank we try to figure it out here
  if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
    vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
  vis.display = (vis.display==''||vis.display=='block')?'none':'block';

elem.innerHTML = help_text;

	vis.left = new_x+20 + 'px';	
	vis.top = new_y-50 + 'px';
}

function hideAllEditPhotoDisplay(){

	hideXDiv('EditPhotoThumbnail');
	hideXDiv('EditPhotoSmall');
	hideXDiv('EditPhotoMedium');
	hideXDiv('EditPhotoSource');

}

function hideXDiv(div_name){
	eSmall = document.getElementById(div_name);
	if(eSmall){
		eSmall.style.visibility = 'hidden'; 
		eSmall.style.display = 'none';
	}
}

function showXDiv(div_name){
	eSmall = document.getElementById(div_name);
	if(eSmall){
		eSmall.style.visibility = 'visible'; 
		eSmall.style.display = 'block';
	}
}

function toggleEditThumbnail(){
	//alert('thumb');
	hideAllEditPhotoDisplay();
	showXDiv('EditPhotoThumbnail');
}

function toggleEditSmall(){
	//alert('small');
	hideAllEditPhotoDisplay();
	showXDiv('EditPhotoSmall');
}

function toggleEditMedium(){
	//alert('small');
	hideAllEditPhotoDisplay();
	showXDiv('EditPhotoMedium');
}

function toggleEditSource(){
	//alert('small');
	hideAllEditPhotoDisplay();
	showXDiv('EditPhotoSource');
}

function confirmAction(url,message){
	var box = confirm(message);
	if(box){
		window.location = url;
	}
}

function refreshOptions(url,element){
	if(element){
		loadFragmentInToElement(url, element);
	}
}
function refreshIndustrySubs(obj){
	refreshOptions('/includes/ajax.php?m=account&sm=itype&itype='+obj.value,'is_id_div');
}
function refreshIndustrySubs2(obj,num,f_name){
	refreshOptions('/includes/ajax.php?m=account&sm=itype_ld&dn='+f_name+'&itype='+obj.value,'is_id_div'+num);
}
function refreshPropSubTypes(obj,ltype){
	refreshOptions('/includes/ajax.php?m=account&sm=pstype&ltype='+ltype+'&ptype='+obj.value,'pstype_id_div');
}
function refreshPropSubTypes2(obj,ltype,num,f_name){
	refreshOptions('/includes/ajax.php?m=account&sm=pstype_ld&ltype='+ltype+'&dn='+f_name+'&ptype='+obj.value,'pstype_id_div'+num);
}
function refreshPropTypes(obj){
	refreshOptions('/includes/ajax.php?m=admin&sm=ltype&ltype='+obj.value,'ptype_id_div');
}
function refreshCountyOptions(obj){
	refreshOptions('/includes/ajax.php?m=account&sm=county&state='+obj.value,'county_id_div');
}

/*	Alerts Page	*/
function toggleAlertActive(alert_id){
	window.location='/account/index.php?m=alerts&alm=activate&aid='+alert_id;
}

function showAlertDetailSection(section_id){
	var divs = new Array(4);
	divs = ['alertSection_0','alertSection_1','alertSection_2','alertSection_3'];
	
	//hide all divs
	for(x=0;x<=divs.length;x++){
		if(document.getElementById(divs[x])){
			hideXDiv(divs[x]);
		}
	}
	
	//show selected div
	if(document.getElementById(section_id)){
		showXDiv(section_id);
	}
}

function showMatchDetailSection(){
  var dropdown = document.matchPro.matchType;
	var divs = new Array(4);
	divs = ['matchSection_0','matchSection_1','matchSection_2','matchSection_3',
          'matchSection_4','matchSection_5','matchSection_6','matchSection_7',
          'matchSection_8','matchSection_9','matchSection_10','matchSection_11',
          'matchSection_12','matchSection_13','matchSection_14','matchSection_15',
          'matchSection_16','matchSection_17'];
	
	//hide all divs
	for(x=0;x<=divs.length;x++){
		if(document.getElementById(divs[x])){
			hideXDiv(divs[x]);
		}
	}

	var myindex = dropdown.selectedIndex;
	var div_id = 'matchSection_'+dropdown.options[myindex].value;
	
	//show selected div
	if(document.getElementById(div_id)){
		showXDiv(div_id);
	}
}

function showProUserSection(section_id){
	div = 'proSection';
	
	//hide all divs
	if(document.getElementById(div)){
		hideXDiv(section_id);
	}
	
	//show selected div
	if(document.getElementById(section_id)){
		showXDiv(section_id);
	}
}

function changeProDirAmount() {
    var amount = document.getElementById('amount');
    
}
