// JavaScript Document

//function that determines if the field is a numeric, pass a numeric only field to verify a number
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;
}

//function that determines if the field is text, pass a text only field to verify text
function IsText(sText) {
	var InvalidChars = "0123456789<>";
	var IsOnlyText = true;
	var Char;
	
	for (x = 0; x < sText.length; x++) { 
		Char = sText.charAt(x); 
		if (InvalidChars.indexOf(Char) != -1) {
			IsOnlyText = false;
		}
	}
	
	return IsOnlyText;
}

//function that determines if the field is does not have a special character, pass a text only field to verify text
function IsNotSpecialChars(sText) {
	var InvalidChars = /^[A-z0-9-'.'-','-'-'-' ']*$/;
	var IsNotSpec = true;
	
	if (!InvalidChars.test(sText)) {
		IsNotSpec = false;
	}
	return IsNotSpec;
}

//function that checks for spaces
function noSpaces(sText) {
	var InvalidChar = " ";
	var NoSpaces = true;
	
	if (!InvalidChar.test(sText)) {
		NoSpaces = false;
	}
	return NoSpaces;
}

// foramts a float to currency format ($0.00)
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);
}

// Full screenshot popup
function fullScreenPopup(pic_id) {
	day = new Date();
	id = day.getTime();
	URL = "../works/fullimage.php?art_id=" + pic_id;
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,left = 0,top = 0');");
}

function searchPopUp() {
	alert("This is not available yet. Coming Soon!");
}

function randomNumber(num) {
	var randomnumber = Math.floor(Math.random()* (num+1));
	return randomnumber;
}
