var $j = $;//jQuery.noConflict();//This is here so that in the future we can easyly add libraries that confict--%>
var version4 = false;//<%--TODO: Remove references (navigator.appVersion.charAt(0) == "4");--%>

function displayPopup(position, url, name, height, width, evnt) {
	$j('[name="'+name+'"]').popupWindow({
	//$j('window').popupWindow({
		centerScreen:1,
		windowURL:url,
		toolbar:false,
		height:height,
		width:width
	});
	return false;
}

function displayPopupDc(position, url, name, height, width, evnt) {
	$j('[name="'+name+'"]').popupWindowDc({
	//$j('window').popupWindow({
		centerScreen:1,
		windowURL:url,
		toolbar:false,
		height:height,
		width:width
	});
	return false;
}


function hideItem(divName) {
	$j("#"+divName).hide();
}

$j(document).bind('mousemover', getMouseXY);

var tempX = 0
var tempY = 0


function getMouseXY(e) {
	tempX = e.pageX;
	tempY = e.PageY;

	if (tempX < 0) {
		tempX = 0
	}
	if (tempY < 0) {
		tempY = 0
	}

	return true
}


function showItem(divName) {
	$j("#"+divName).css('left', tempX).css('top', tempY);
	$j("#"+divName).show();
}



function checkNumeric(box, value) {

	var entry = $j("#"+box).val();//document.getElementById(box).value;
	var validChar = '0123456789';

	var check = 'valid'

	var strlen = entry.length;


	for (i = 0; i < strlen; i++) {
		if (validChar.indexOf(entry.charAt(i)) < 0) {

			check = 'invalid';
			break;
		}
	}

	if (check == 'invalid') {
		$("#"+box).val(value);//document.getElementById(box).value = value;
		alert('Please enter numeric value only');
	}

}

function checkNumericOrEmpty(box, value) {

	var entry = $j("#"+box).val();//document.getElementById(box).value;
	var validChar = '0123456789';


	var check = 'valid'

	var strlen = entry.length;


	for (i = 0; i < strlen; i++) {
		if (validChar.indexOf(entry.charAt(i)) < 0) {

			check = 'invalid';
			break;
		}
	}

	if (check == 'invalid') {
		if (entry != '') {
			$j("#"+box).val(value);//document.getElementById(box).value = value;
			alert('Please enter numeric value only');
		}
	}

}

function checkAlphanumeric(box, value) {
	var anumaric = $j("#"+box).val();//document.getElementById(box).value;
	var check = 'valid'

	for (var j = 0; j < anumaric.length; j++) {
		var alphaa = anumaric.charAt(j);
		var hh = alphaa.charCodeAt(0);
		if ((hh > 47 && hh < 58) || (hh > 64 && hh < 91) || (hh > 96 && hh < 123)) {
		}
		else {
			check = 'invalid';
			break;
		}
	}

	if (check == 'invalid') {
		if (anumaric != '') {
			$j("#"+box).val(value);//document.getElementById(box).value = value;
			alert('Please enter alpha numeric values only');
		}
	}

}

//set and get cookies
function setCookie(c_name, c_value) {
	document.cookie = c_name + '=' + escape(c_value);
}


function getCookie(c_name) {
	if (document.cookie.length > 0) {
		c_start = document.cookie.indexOf(c_name + "=");
		if (c_start != -1) {
			c_start = c_start + c_name.length + 1;
			c_end = document.cookie.indexOf(";", c_start);
			if (c_end == -1) c_end = document.cookie.length;
			return unescape(document.cookie.substring(c_start, c_end));
		}
	}
	return "";
}

function validURL(str) {
  var pattern = new RegExp('^(https?:\/\/)?'+ // protocol
    '((([a-z\d]([a-z\d-]*[a-z\d])*)\.)+[a-z]{2,}|'+ // domain name
    '((\d{1,3}\.){3}\d{1,3}))'+ // OR ip (v4) address
    '(\:\d+)?(\/[-a-z\d%_.~+]*)*'+ // port and path
    '(\?[;&a-z\d%_.~+=-]*)?'+ // query string
    '(\#[-a-z\d_]*)?$','i'); // fragment locater
  if(!pattern.test(str)) {
    return false;
  } else {
    return true;
  }
}


