var pics=0;

function blink(id)
{
	var el=document.getElementById(id);
	
	if(el.style.color=='red')
	{
		el.style.color='black';
	}
	else
	{
		el.style.color='red';
	}
	
	if(el.numBlinks==null)
	{
		el.numBlinks=1;
		window.setTimeout("blink('"+id+"')",400);
	}
	else if(el.numBlinks<7)
	{
		el.numBlinks++;
		window.setTimeout("blink('"+id+"')",400);
	}
	else
	{
		el.numBlinks=null;
	}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
	 //else{alert("Can't Find: "+a[i]);}
}



var xinha_editors=new Array();
var dragee = null;
var div=null;
var allchecked=false;
var isWin=false;
var o=0;
var i=0;
var lmenu=new Array();
var fadeTime=1;
var picObject=null;
var selectOption;
var madeToolbar=0;
var catArray = new Array();
function remove(act,form,message)
{
	if(act=='Delete')
	{
		if(confirm(message))
		{
			form.submit();
		}
	}
}
function mouseOver(el,mID)
{
	el.mOver=1;
	if(el.tagName=="TD")
	{
		if(lastOver!=null)
		{
			lastOver.className="leagueMenu";
		}
		el.className="over";
		lastOver=el;
	}
	var menu;
	if(menu=document.getElementById(mID))
	{
		menu.caller=el;
		showMenu(mID);
	}
}
function mouseOut(el,mID)
{
	el.mOver=0;
	if(el.tagName=="TD")
	{
		el.className="leagueMenu";
	}
	if(mID != null)
	{
		window.setTimeout("hideMenu('"+mID+"')",100);
	}
}
function showMenu(mID)
{
	var menu;
	if(menu = document.getElementById(mID))
	{
		if(menu.show==1)
		{
			return;
		}
		menu.style.visibility="visible";
		if(document.all)
		{
			menu.style.filter='alpha(opacity=0)';
		}
		else
		{
			menu.style.opacity=0.00;
		}
		menu.show=1;
		menu.opacity=0;
		addOpacity(mID);
	}
}
function hideMenu(mID)
{
	var menu;
	if(menu = document.getElementById(mID))
	{
		if((menu.mOver!=1)&&(menu.caller.mOver!=1))
		{
			menu.show=0;
			subOpacity(mID);
		}
	}
}
function addOpacity(mID)
{
	var menu;
	if(menu = document.getElementById(mID))
	{
		if(menu.show==0)
		{
			return;
		}
		if(document.all)
		{
			menu.opacity+=1;
			menu.style.filter='alpha(opacity='+menu.opacity+')';
			if(menu.opacity<100)
			{
				window.setTimeout("addOpacity('"+mID+"')",fadeTime);
			}
		}
		else
		{
			menu.opacity+=0.01;
			menu.style.opacity=menu.opacity;
			if(menu.opacity<1)
			{
				window.setTimeout("addOpacity('"+mID+"')",fadeTime);
			}
		}
	}
}
function subOpacity(mID)
{
	var menu;
	if(menu = document.getElementById(mID))
	{
		if(menu.mOver==1)
		{
			showMenu(mID);
			return;
		}
		if(menu.show==1)
		{
			return;
		}
		if(document.all)
		{
			menu.opacity--;
			menu.style.filter='alpha(opacity='+menu.opacity+')';
		}
		else
		{
			menu.opacity-=0.01;
			menu.style.opacity=menu.opacity;
		}
		if(menu.opacity>0)
		{
			window.setTimeout("subOpacity('"+mID+"')",fadeTime);
		}
		else
		{
			menu.visibility="hidden";
		}
	}
}
function elClick(el)
{
	if(el=el.firstChild)
	{
		window.location=el;
	}
}
function checkAll(el)
{
	if(el.name.length==0)
	{
		var elements = document.getElementsByTagName("input");
		for(var c=0; c<elements.length; c++)
		{
			if(elements[c].className==el.className)
			{
				elements[c].checked=el.checked;
			}
		}
	}
	else
	{
		var check=true;
		var elements = document.getElementsByTagName("input");
		var controllers = new Array(0);
		for(var c=0; c<elements.length; c++)
		{
			if(elements[c].className==el.className)
			{
				if(elements[c].name.length>0)
				{
					if(elements[c].checked==false)
					{
						check=false;
					}
				}
				else
				{
					var old = controllers;
					controllers = new Array(old.length+1);
					var i;
					for(i=0; i<old.length; i++)
					{
						controllers[i]=old[i];
					}
					controllers[i]=elements[c];
				}
			}
		}
		for(var i=0; i<controllers.length; i++)
		{
			controllers[i].checked=check;
		}
	}
}
function performAction(el,form,message)
{//Delete-Edit (confirm for delete)
	if(el.value=="Delete")
	{
		if(confirm(message))
		{
			form.submit();
		}
		else
		{
			el.options[0].selected=true;
		}
	}
	else
	{
		form.submit();
	}
}
function showUpload(picObj)
{
	//alert(picObj.data+" "+picObj.field+" Primary Key = "+picObj.pri);
	picObj.copy=document.getElementById('uploadcopy');
	picObject=picObj;
	var upldWindow=window.open("?f=upload","Upload","width=375,height=200,scrollbars=no,status=yes");
	upldWindow.picObj=picObj;
}
function rePopulate(cat,subcat)
{//repopulate subCatagory menu
	if(subcat)
	{
		var array=subcat.optList[cat.value];
		if(!subcat.orgVal)
		{//set original selected value;
			subcat.orgVal=subcat.options[subcat.selectedIndex].value;
		}
		while(subcat.options.length>0)
		{
			subcat.options[subcat.options.length-1]=null;
			if(!document.all)
			{
				subcat.options.length--;
			}
		}
		if(array!=null)
		{
			for(var c=0; c<array.length; c++)
			{
				subcat.options[c]= new Option(array[c].name,array[c].value);
				if(array[c].value==subcat.orgVal)
				{
					subcat.selectedIndex=c;
				}
			}
		}
		if(subcat.optList[0])
		{
			subcat.options[subcat.length]=new Option('None',subcat.optList[0].value);
			if(subcat.orgVal==0)
			{
				subcat.selectedIndex=subcat.length-1;
			}
		}
	}
}
function makeToolbar()
{
		if((madeToolbar==0)&&(document.all)&&(document.execCommand('Bold')))
		{
			
		}
}
function onPost()
{
	return true;
}
function setDrag(event,el)
{
	if(!el.move)
	{
		if(document.all)
		{
			el.move=new Function('this.style.left = window.event.clientX - this.sx;this.style.top = window.event.clientY - this.sy;');
		}
		else
		{
			el.move=new Function('event','this.style.left = event.clientX - this.sx;this.style.top = event.clientY - this.sy;');
		}
	}
	if(!el.setSXY)
	{
		if(document.all)
		{
			el.setSXY=new Function('this.sx=(window.event.clientX-this.style.pixelLeft);this.sy=(window.event.clientY-this.style.pixelTop);');
		}
		else
		{
			el.setSXY=new Function('event','this.sx=(event.clientX-this.style.left);this.sy=(event.clientY-this.style.top);');
		}
	}
	dragee=el;
	dragee.setSXY(event);
	//event.returnValue = false;
	//event.cancelBubble = true;
}
function drag(event)
{
	if(dragee!=null)
	{
		dragee.move(event);
		//event.returnValue = false;
		//event.cancelBubble = true;
	}
}
function resetDrag()
{
	//document.getElementById('debug').innerHTML=dragee.sx;
	dragee = null;
}
function changeColor(grnd)
{
	var sColor = dlgHelper.ChooseColorDlg();
	sColor = sColor.toString(16);
	if (sColor.length < 6)
	{
		var sTempString = "000000".substring(0,6-sColor.length);
		sColor = sTempString.concat(sColor);
	}
	if(sColor!="Other")
	{
		document.execCommand(grnd, false, sColor);
	}
}
function pNums(num,element1,element2)
{
	if(element1.value.length==num)
	{
		element2.focus();
	}
}
function checkNum(el)
{
	if(event.keyCode!=8&&event.keyCode!=9&&(!(event.keyCode<41&&event.keyCode>36))&&(event.keyCode<46||event.keyCode>58))
	{
		//alert(event.keyCode);
		//event.returnValue=false;
	}
	//document.getElementsByName(mdiv.id).item(1).value=mdiv.innerHTML;
}
function uHTML(mdiv)
{
	/*if(event.keyCode==13)
	{
		//event.returnValue=false;
		var sRange  = document.selection.createRange();
		sRange.pasteHTML('<BR>&nbsp;');
		sRange.text="";
		event.keyCode=8;
	}*/
}
function showBar(el)
{
	document.getElementById('toolBar').style.visibility='visible';
	if(el!=div)
	{
		document.getElementById('toolBar').style.top=el.offsetTop-25;
		document.getElementById('toolBar').style.left=el.offsetLeft;
		div=el;
		//window.status="X: "+el.offsetTop+" Y: "+el.offsetLeft;
	}
}
function lookup()
{
	var uWindow=window.open("./?f=aPropertyEdit&m=lookup","Upload","width=600,height=400,scrollbars=yes,status=yes");

}
function chooseUser( user )
{
	var sel = window.opener.document.getElementById("userSelect");
	for(var c=0; c < sel.options.length; c++)
	{
		if(sel.options[c])
		{
			if(sel.options[c].value==user)
			{
				sel.selectedIndex=c;
				window.close();
			}
		}
	}
}
function clearForm()
{
	if(confirm("Do you really want to clear the form?"))
	{
		for(var c=0; c<document.f1.elements.length; c++)
		{
			var el = document.f1.elements[c];
			if(el.type=="text")
			{
				el.value="";
			}
		}
	}
}
function slideShow(location)
{
	var slideWindow=window.open(location,"SlideShow","width=600,height=400,scrollbars=no,status=no");
}
function prcntCalc(off)
{
	var org = document.getElementById('Original').value;
	org = parseFloat(org);
	var dsc = document.getElementById('Discount').value;
	dsc = parseFloat(dsc);
	off = parseFloat(off);
	off=off/100;
	document.getElementById('Discount').value=org-(off*org);
}
function showPrcnt()
{
	var org = document.getElementById('Original').value;
	org = parseFloat(org);
	var dsc = document.getElementById('Discount').value;
	dsc = parseFloat(dsc);
	var off = org - dsc;
	window.status=off;
	document.getElementById('off').value = (off/org)*100;
}
function showVideo(wpath)
{
	var vWindow=window.open("","Video","width=350,height=315,scrollbars=no,status=no");
	vWindow.document.write('<html><head><title>Video</title></head><body><EMBED SRC="http://video.ranchandresorttv.com'+wpath+'" AUTOSTART="true" VOLUME="100"></EMBED></body></html>');
}

function addOption(sel,activeVal)
{
	if(sel.options[sel.selectedIndex].text==activeVal)
	{
		var selIndex=sel.selectedIndex;
		var optName=null;
		optName = prompt('Please enter new option name:');
		if(optName!=null)
		{
			var option = new Option(optName,optName);
			var last = sel.options[selIndex];
			sel.options[selIndex]=option;
			sel.options[sel.length]=last;
			sel.selectedIndex=selIndex;
		}
		else
		{
			sel.selectedIndex=0;
		}
	}
}
function changeClass( elID, className)
{
	var el = document.getElementById(elID);
	el.className=className;
}
function pOver(el,noteid)
{
	el.bgColor="white";
	var note;
	if(note=document.getElementById(noteid))
	{
		note.className='hNote';
	}
	//document.getElementById(noteid)
}
function pOut(el,noteid)
{
	el.bgColor="transparent";
	var note;
	if(note=document.getElementById(noteid))
	{
		note.className='nNote';
	}
	//document.getElementById(noteid).className='nNote';
}
function mbuttonover()
{
	this.mouseIsOver=1;
	this.smenu.className='smenu';
	if(this.toID!=0)
	{
		for(var i=0; i<window.toObjects.length; i++)
		{
			if(window.toObjects[i]==this)
			{
				window.toObjects.splice(i,1);
			}
		}
		window.clearTimeout(this.toID);
	}
}
function mbuttonout()
{
	this.mouseIsOver=0;
	
	window.toObjects.push(this);
	this.toID=window.setTimeout(mbuttontimeout,200);
}
function mbuttontimeout()
{
	var el = window.toObjects.shift();
	if(el.mouseIsOver==0)
	{
		el.smenu.className='hsmenu';
	}
}
function mbuttonsetup()
{
	var els=document.getElementsByClass("mbutton");
	window.toObjects = new Array();
	
	for(var i=0; i<els.length; i++)
	{
		els[i].toID=0;//TimeOut ID
		els[i].mouseIsOver=0;
		els[i].smenu=els[i].getElementByClass('hsmenu');
		els[i].onmouseover=mbuttonover;
		els[i].onmouseout=mbuttonout;
		var pos=els[i].findPos();
		els[i].smenu.style.left=pos[0]+'px';
		els[i].smenu.style.top=(pos[1]+15)+'px';
		//alert(els[i].offsetHeight);
		//els[i].timeout=mbuttontimeout;
	}
}