﻿
	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 findObj(objId)
	{   
		return MM_findObj(objId);
	}

	function toggleDropDown(checkBox,dropDownList,submitButton)
	{   
		var mySubmitButton = $(submitButton);
		var myDropDownList = $(dropDownList);
	    
		if(checkBox.checked)
		{
			myDropDownList.value = 1;
			mySubmitButton.style.display = "inline";
		}
		else
		{
			myDropDownList.value = 0;
			mySubmitButton.style.display = "none";
		}
	}

	function toggleCheckBox(dropDownList,checkBox,submitButton)
	{   
		var mySubmitButton = $(submitButton);
		var myCheckBox = $(checkBox);
		if(dropDownList.value < 1)
		{   
			myCheckBox.checked = false;
			mySubmitButton.style.display = "none";
		}
		else
		{
			myCheckBox.checked = true;
			mySubmitButton.style.display = "inline";
		}
	}  

	//to disable the submit button
	var firstClick; 
	firstClick = true; 
	function savedisable(btnObj, requestApplicationPath) 
	{ 
		Page_ClientValidate(); //validate now
	    
		if(Page_IsValid)
		{
			if (firstClick) 
			{ 
				//btnObj.value = "Searching...";
	            
				//add the spinner
				var spinner = new Image();
				spinner.src = requestApplicationPath+"/images/wait/spinner_red_yellow.gif";
				$('spinnerHolder').appendChild(spinner);
	            
				firstClick = false; //it's not the first click any more!
			} 
			else
			{
				alert('Your request has been submited, please wait.'); 
				btnObj.disabled=true;                 
			}
		}
	} 

	function expand() {
		//for(x = 0; x < 50; x+5) {
		//    window.moveTo(screen.availWidth * -(x - 50) / 100, screen.availHeight * -(x - 50) / 100);
		//    window.resizeTo(screen.availWidth * x / 50, screen.availHeight * x / 50);
		//}
		//window.moveTo(0,0);
		//window.resizeTo(screen.availWidth, screen.availHeight);
	}   

	function addEvent(elm, evType, fn, useCapture) {
		if (elm.addEventListener) {
			elm.addEventListener(evType, fn, useCapture);
			return true;
		}
		else if (elm.attachEvent) {
			var r = elm.attachEvent('on' + evType, fn);
			return r;
		}
		else {
			elm['on' + evType] = fn;
		}
	}

	function addLoadEvent(func) {
	  var oldonload = window.onload;
	  if (typeof window.onload != 'function') {
		window.onload = func;
	  } else {
		window.onload = function() {
		  if (oldonload) {
			oldonload();
		  }
		  func();
		}
	  }
	}

	function getElementsByClass(searchClass,node,tag) {
		var classElements = new Array();
		if ( node == null )
			node = document;
		if ( tag == null )
			tag = '*';
		var els = node.getElementsByTagName(tag);
		var elsLen = els.length;
		var pattern = new RegExp('(^|\\s)'+searchClass+'(\\s|$)');
		for (i = 0, j = 0; i < elsLen; i++) {
			if ( pattern.test(els[i].className) ) {
				classElements[j] = els[i];
				j++;
			}
		}
		return classElements;
	}

	function toggle(obj) {
		var el = document.getElementById(obj);
		if ( el.style.display != 'none' ) {
			el.style.display = 'none';
		}
		else {
			el.style.display = '';
		}
	}

	function insertAfter(parent, node, referenceNode) {
		parent.insertBefore(node, referenceNode.nextSibling);
	}

	Array.prototype.inArray = function (value) {
		var i;
		for (i=0; i < this.length; i++) {
			if (this[i] === value) {
				return true;
			}
		}
		return false;
	};

	function $() {
		var elements = new Array();
		for (var i = 0; i < arguments.length; i++) {
			var element = arguments[i];
			if (typeof element == 'string')
				element = document.getElementById(element);
			if (arguments.length == 1)
				return element;
			elements.push(element);
		}
		return elements;
	}

	function flvFPW1(){
		var v1=arguments,v2=v1[2].split(","),v3=(v1.length>3)?v1[3]:false,v4=(v1.length>4)?parseInt(v1[4]):0,v5=(v1.length>5)?parseInt(v1[5]):0,v6,v7=0,v8,v9,v10,v11,v12,v13,v14,v15,v16;v11=new Array("width,left,"+v4,"height,top,"+v5);for (i=0;i<v11.length;i++){v12=v11[i].split(",");l_iTarget=parseInt(v12[2]);if (l_iTarget>1||v1[2].indexOf("%")>-1){v13=eval("screen."+v12[0]);for (v6=0;v6<v2.length;v6++){v10=v2[v6].split("=");if (v10[0]==v12[0]){v14=parseInt(v10[1]);if (v10[1].indexOf("%")>-1){v14=(v14/100)*v13;v2[v6]=v12[0]+"="+v14;}}if (v10[0]==v12[1]){v16=parseInt(v10[1]);v15=v6;}}if (l_iTarget==2){v7=(v13-v14)/2;v15=v2.length;}else if (l_iTarget==3){v7=v13-v14-v16;}v2[v15]=v12[1]+"="+v7;}}v8=v2.join(",");v9=window.open(v1[0],v1[1],v8);if (v3){v9.focus();}document.MM_returnValue=false;return v9;
	}

	function hideElementByClass(className)
	{
		var objArray = new Array();
		objArray = getElementsByClass(className, null, null);
		objArray[0].style.display = "none";
	}

	function showElementByClass(className)
	{
		var objArray = new Array();
		objArray = getElementsByClass(className, null, null);
		objArray[0].style.display = "block";
	}

	function getElementByClass(className)
	{
		var objArray = new Array();
		objArray = getElementsByClass(className, null, null);
		return objArray[0];
	}

	//alert("shared" + location.href);

	/*-------------------------Bubble ToolTips----------------------------------*/
	function showToolTip(e,text){
	    
		//alert('showToolTip');

		if(document.all)e = event;
		
		var obj = document.getElementById('bubble_tooltip');
		var obj2 = document.getElementById('bubble_tooltip_content');
		obj2.innerHTML = text;
		obj.style.display = 'block';
		var st = Math.max(document.body.scrollTop,document.documentElement.scrollTop);
		if(navigator.userAgent.toLowerCase().indexOf('safari')>=0)st=0; 
		var leftPos = e.clientX - 100;
		if(leftPos<0)leftPos = 0;
		obj.style.left = leftPos + 'px';
		obj.style.top = e.clientY - obj.offsetHeight -1 + st + 'px';
	}	

	function hideToolTip()
	{
		document.getElementById('bubble_tooltip').style.display = 'none';
	}
	/*-------------------------End Bubble ToolTips-----------------------------*/

	function showImageEditButtons(clientId)
	{
		findObj(clientId).style.display = "block";
	}

	function hideImageEditButtons(clientId)
	{
		findObj(clientId).style.display = "none";
	}

	function showClientObj(clientId)
	{
	    //alert(clientId);
		if(findObj(clientId).style.display == "none" || findObj(clientId).style.display == "")
		{
			findObj(clientId).style.display = "inline";
		}
		else
		{
			findObj(clientId).style.display = "none";
		}
		return false;
	}

	function hideClientObj(clientId)
	{
		findObj(clientId).style.display = "none";
		return false;
	}

	function toggleStyle(objClass, styleName, styleValue)
	{
		obj = getElementByClass(objClass);
		eval("obj.style." + styleName + "='" + styleValue + "'");
	}

	function setDropDownValueByClass(cssClass, aValue)
	{
		var objDropDown = getElementByClass(cssClass);
		for (i = 0; i < objDropDown.length; i++) {
			if (objDropDown[i].value == aValue) {
				objDropDown[i].selected = true;
			} 
		}
	}

	function highlight(field)
	{
	    field.focus();
	    field.select();
	}
	
	function demoMatchClick(str, pattern) {
  var re = new RegExp(pattern);
  if (str.match(re)) {
    alert("Successful match");
  } else {
    alert("No match");
  }
}

function getSubstring(str, pattern, matchIndex) {

  str = str.toLowerCase();

  var re = new RegExp(pattern);
  
  var m = re.exec(str);
  
  if (m == null) {
    return 0;
  } else {
    var s = "Match at position " + m.index + ":\n";
    for (i = 0; i < m.length; i++) {
      s = s + m[i] + "\n";
    }
    return m[matchIndex];
  }
}

function revealModal(divID)
{
    window.onscroll = function () { document.getElementById(divID).style.top = document.body.scrollTop; };
    document.getElementById(divID).style.display = "block";
    document.getElementById(divID).style.top = document.body.scrollTop;
}

function hideModal(divID)
{
    document.getElementById(divID).style.display = "none";
}

function getTrackingPage()
{
    
}

function trackEvent(category, eventName, eventDescription)
{   
    if(window.location.host == "localhost")
    {
        var str = "Category: " + category;
        str += "EventName: " + eventName;
        str += "EventDescription: " + eventDescription + " - " + window.location.pathname;
        //alert(str);
    }
    else //check if site has Analytics include
    {
        if (typeof pageTracker != 'undefined')
        {
            pageTracker._trackEvent(category, eventName, eventDescription + " - " + window.location.pathname);
        }
    }
}

function rgbToHex(rgbString) // converts RGB to hex
{
	//var rgbString = "rgb(0, 70, 255)"; // get this in whatever way.
	var parts = rgbString
			.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/)
	;
	// parts now should be ["rgb(0, 70, 255", "0", "70", "255"]

	delete (parts[0]);
	for (var i = 1; i <= 3; ++i) {
		parts[i] = parseInt(parts[i]).toString(16);
		if (parts[i].length == 1) parts[i] = '0' + parts[i];
	}
	var hexString = parts.join(''); // "0070ff"
	return hexString;
}
