var phone = "()- 0123456789";
var integer = "-0123456789";
var money = "$.,0123456789";
var percent = "0123456789.";
var dates = "/0123456789";
var numb = "0123456789";
var alpha = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ";
var standard = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.- ";
var username = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789._";
var e_mail = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_@.";

function res(t,v){
	var w = "";
	for (i=0; i < t.value.length; i++) {
		x = t.value.charAt(i);
		if (v.indexOf(x,0) != -1)
		w += x;
	}
	t.value = w;
};

function cleaner(t,v){
	var w = "";
	for (z=0; z<t.length; z++) {
		x = t.charAt(z);
		if (v.indexOf(x,0) != -1) {
			w += x;
		}
	}
	return (w);
};
	
function formatCurrency(num) {
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
	num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10)
	cents = "0" + cents;
		for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
		num = num.substring(0,num.length-(4*i+3))+','+
		num.substring(num.length-(4*i+3));
	return (((sign)?'':'-') + '$' + num + '.' + cents);
};

function isNumeric(sText) {
	var ValidChars = "0123456789.";
	var isNumber = true;
	var Char;

	for (i = 0; i < sText.length && isNumber == true; i++) {
		Char = sText.charAt(i);
		if (ValidChars.indexOf(Char) == -1) { isNumber = false; }
	}
	return isNumber;
}


var CallMeShown = 0;

var IE = document.all?true:false // Detect if the browser is IE or not.

//if (!IE) document.captureEvents(Event.MOUSEMOVE) // If NS -- that is, !IE -- then set up for mouse capture

//document.onmousemove = getMouseXY; // Set-up to use getMouseXY function onMouseMove

// Temporary variables to hold mouse x-y pos.s
//var tempX = 0
//var tempY = 0

// Main function to retrieve mouse x-y pos.s

function getMouseXY(e) {
	if (IE) { // grab the x-y pos.s if browser is IE
		tempX = event.clientX + document.body.scrollLeft;
		tempY = event.clientY + document.body.scrollTop;
	} else {  // grab the x-y pos.s if browser is NS
		tempX = e.pageX;
		tempY = e.pageY;
	}

	// catch possible negative values
	if (tempX < 0){tempX = 0}
	if (tempY < 0){tempY = 0}

	// show the position values in the form named Show
	return true;
}

function iReload() {
	document.location.reload();
}

//document.write("<span id='iHelperConsole' style='left:25%; top:50; position:absolute;'></span>");


function confirmDelete(){
	if (confirm("Are you sure that you want to delete this record?")){
		return true;
	} else {
		return false;
	}
}


	function mOvr(src,clrOver) { if (!src.contains(event.fromElement)) { src.style.cursor = 'hand'; src.bgColor = clrOver; }}
	function mOut(src,clrIn) { if (!src.contains(event.toElement)) { src.style.cursor = 'default'; src.bgColor = clrIn; }}
	function mClk(src) { if(event.srcElement.tagName=='TD'){src.children.tags('A')[0].click();} }
	function updateMessage(sStr){ if (sStr.length>0) { document.all.Messages.innerHTML = sStr; } }
	
	var changed = 0;
	var old_colour;
	
	function cell_hover(cell, colour, linkid) {
		if (changed == 0) { //mouse on
			changed = 1;
			old_colour = cell.style.backgroundColor;
			cell.style.backgroundColor=colour;
		} else { //mouse off
			if (!colour) {
				changed = 0;	
				cell.style.backgroundColor=old_colour;
			} else {
				cell.style.backgroundColor=colour;
			}
		}
	}
	

function set_child_listbox(parentObject,childObject,childArray,spanToHide) {

	//Clear child listbox
	for(var i=childObject.length;i>0;i--) {
		childObject.options[i] = null;
	} 
	
	childObject.options[0] = new Option("Select Value","");
	var sel_index = parentObject.options[parentObject.selectedIndex].value;
	if (sel_index == "") {
		childObject.disabled = true;
	} else {
		childObject.disabled = false;
		var childIndex = 1;
		for (i = 0; i < childArray.length; i++) {
			// alert(childArray[i][1] + " -- " + childArray[i][2] + " -- " + childArray[i][0]);
			if (childArray[i][1] == sel_index) {
				childObject.options[childIndex] = new Option(childArray[i][2], childArray[i][0]); // new Option(childArray[i][2], childArray[i][0]);
				childIndex++;
			}
		}
	}
	//Select first option
	childObject.selectedIndex = 0;

	//Hide dependent grid
//	if (spanToHide != "") {
//		if (DomYes) {
//  			document.getElementById(spanToHide).style.display="none";
//		} else {
//			document.all[spanToHide].style.display="none";
//		}
//	}
}

function disable_child_listbox(spanToHide) {
  
  //Disable second listbox 
  if (document.store_productsSearch.s_category_id.selectedIndex == "") {
     document.store_productsSearch.s_product_id.disabled = true;
  }	

  //Hide dependent grid 
  if (document.store_productsSearch.s_product_id.selectedIndex == "") {
	if (spanToHide != "") {
		if (DomYes) {
			document.getElementById(spanToHide).style.display="none";
		} else {
			document.all[spanToHide].style.display="none";
		}
	}
  }	
}