
function isValidFilename(string) {

	var invalids = '?&/\*:;|<>"\'=';

    for (var i=0; i< string.length; i++) {
       if (invalids.indexOf(string.charAt(i)) != -1)
          return false;
    }
    return true;
}

function outputMoney(number, dec) {
	var neg = '';
	dec = (!dec ? 2 : dec);
	if(isNaN(number))
		number = 0;
	if (number < 0) {
		neg = '-';
		number *= -1;
	}
	return neg + outputDollars(Math.floor(number-0) + '') + outputCents(number - 0, dec);
}

function outputDollars(number) {
    var i;
	if (number.length <= 3)
        return (number == '' ? '0' : number);
    else {
        var mod = number.length%3;
        var output = (mod == 0 ? '' : (number.substring(0,mod)));
        for (i=0 ; i < Math.floor(number.length/3) ; i++) {
            if ((mod ==0) && (i ==0))
                output+= number.substring(mod+3*i,mod+3*i+3);
            else
                output+= ',' + number.substring(mod+3*i,mod+3*i+3);
        }
        return (output);
    }
}

function stripChars (s, bag) {   
	var i;
    var returnString = "";

    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) 
			returnString += c;
    }
    return returnString;
}

function outputCents(amount, nDec) {
/*	num = '' + amount + '';
	amount = Math.round( ( (amount) - Math.floor(amount) ) * 100);
    return (amount < 10 ? '.0' + amount : '.' + amount);*/

	num = '' + amount + '';
	offset = num.indexOf('.');
	if (offset == -1) {
		num = '.';
		for (i = 1; i <= nDec; i++)
			num +=  '0';
		return num;
	}
	num1 = '.';
	dcount = 1;
	for (i = offset + 1; i < num.length && dcount <= nDec; i++) {
		num1 += num.charAt(i);
		dcount++;
	}
	if (dcount <= nDec) {
		for(i = dcount; i <= nDec; i++) {
			num1 += '0';
		}
	}
	return num1;
}

function round(number,X) {
// rounds number to X decimal places, defaults to 2
    X = (!X ? 2 : X);
    return Math.round(number*Math.pow(10,X))/Math.pow(10,X);
}

function Val(nVal) {
	nVal = (isEmpty(nVal)) ?  '0' :  nVal;
	nVal = parseFloat(stripChars(nVal, ','));
	return nVal;
}

function onFocusVal(value){
	return replaceString(trim(value),',','');
}

function onBlurVal(value){
	if (validAmount(value)){ 
		var amount = trim(value.split(',').join('')); 
		return outputMoney(amount);
	} else {
		return 0;
		//eval("document." + form + "." + field + ".focus()");
	}
}

function validAmount(value){

	if(trim(value) == '' || isNaN(value)){
		alert("Please enter an proper value");
		return false;
	}
	else if (parseFloat(trim(value), 10) <= 0){
		alert('Please enter an value greater than zero');
		return false;
	}

	return true;
}


function replaceString(string,text,by) {
// Replaces text with by in string
    var strLength = string.length, txtLength = text.length;
    if ((strLength == 0) || (txtLength == 0)) return string;

    var i = string.indexOf(text);
    if ((!i) && (text != string.substring(0,txtLength))) return string;
    if (i == -1) return string;

    var newstr = string.substring(0,i) + by;

    if (i+txtLength < strLength)
        newstr += replaceCarriageReturn(string.substring(i+txtLength,strLength),text,by);

    return newstr;
}


function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}




function toggle_box(form, box)
{

	str = "if (document."+form+"."+box+".checked == true) document."+form+"."+box+".checked = false; else document."+form+"."+box+".checked = true"
	eval(str);

}



//3-state Highlight menu effect script: By Dynamicdrive.com
//For full source, Terms of service, and 100s DTHML scripts
//Visit http://www.dynamicdrive.com

function over_effect(e,state){
if (document.all)
source4=event.srcElement
else if (document.getElementById)
source4=e.target
if (source4.className=="menulines")
source4.style.borderStyle=state
else{
while(source4.tagName!="TABLE"){
source4=document.getElementById? source4.parentNode : source4.parentElement
if (source4.className=="menulines")
source4.style.borderStyle=state
}
}
}

function isEmail(string) {
    if (string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
        return true;
    else
        return false;
}



function confirm_logout(page) {
  if (confirm("Are you sure you want to logout?"))
	document.location.href=page;
}



function getExtension(value) {
  return value.substring(value.lastIndexOf('.') + 1,value.length);
}


function datePosition(m1,d1,y1,m2,d2,y2,flag)
{
  if (m1 < 10)
    m1 = "0" + m1;

  if (m2 < 10)
    m2 = "0" + m2;

  if (d1 < 10)
    d1 = "0" + d1;

  if (d2 < 10)
    d2 = "0" + d2;

  /*
     type 5 : 05/29/1997

     'flag' determines if we are comparing date1 with todays date or not
     Returns -1 if the date1 is behind date2
     Returns 0 if the date1 is equal to date2
     Returns 1 if the date1 is ahead of date2

     Added Y2K checking.  (Works for any century cross over)
  */

    //date format needs to be "mm/dd/yyyy"
    dateString1 = m1 + "/" + d1 + "/" + y1;

    var now = new Date();

    if (flag==1)  //compare with given (second) date
      {
        var dateString2 = m2 + "/" + d2 + "/" + y2;
        var date2 = new Date(dateString2.substring(6,10),
                            dateString2.substring(0,2)-1,
                            dateString2.substring(3,5));
      }


    else //compare with today's date
      var date2 = new Date(now.getFullYear(),now.getMonth(),now.getDate());


      var date1 = new Date(dateString1.substring(6,10),
                            dateString1.substring(0,2)-1,
                            dateString1.substring(3,5));

    if (date1 < date2)
       return -1;

    else if (date1 > date2)
       return 1;

    else
      return 0;

}

function y2k(number)
{
  return (number < 1000) ? number + 1900 : number;
}


function isValidDate (day,month,year)
{
  // checks if date passed is valid
 
    var today = new Date();
    year = ((!year) ? y2k(today.getFullYear()):year);
	month = ((!month) ? today.getMonth():month-1);
  

    if (!day) return false


    var test = new Date(year,month,day);
    if ( (y2k(test.getFullYear()) == year) &&
         (month == test.getMonth()) &&
         (day == test.getDate()) )
        return true;
    else
        return false

}




function replaceCarriageReturn(string,text,by) {
// Replaces text with by in string
    var strLength = string.length, txtLength = text.length;
    if ((strLength == 0) || (txtLength == 0)) return string;

    var i = string.indexOf(text);
    if ((!i) && (text != string.substring(0,txtLength))) return string;
    if (i == -1) return string;

    var newstr = string.substring(0,i) + by;

    if (i+txtLength < strLength)
        newstr += replaceCarriageReturn(string.substring(i+txtLength,strLength),text,by);

    return newstr;
}


function trim(strText) { 

    strText = replaceCarriageReturn(replaceCarriageReturn(strText,'\r',''),'\n','');

	// this will get rid of leading spaces 
    while ((strText.substring(0,1) == ' ')||(strText.substring(0,2) == '\r')) 
        strText = strText.substring(1, strText.length);

    // this will get rid of trailing spaces 
    while ((strText.substring(strText.length-1,strText.length) == ' ')||(strText.substring(strText.length-2,strText.length) == '\r'))
        strText = strText.substring(0, strText.length-1);

   return strText;
} 

function openProducts(fileName) 
{
	_win = window.open("products_popup.php?"+fileName, "Products", 'toolbar=no, menubar=no, resizable=no,scrollbars=yes, width=467,height=300,top=50,left=200');
	_win.focus();
	return;
}


function openWindow(fileName, leftValue, rightValue, widthVal, heightVal) {
	x = leftValue //+ window.event.clientX; 
	y = rightValue //+ window.event.clientY;
	winProp = "toolbar=no, titlebar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no";
	_win = window.open(fileName, "test", winProp + ', width=' + widthVal + ',height=' + heightVal + ',top='+y+',left='+x);
	_win.focus();
	return;
}

function is_empty(form, field)
{
  form.field.value = trim(form.field.value);
  if ( (temp_str == null) || (temp_str == " ") || (temp_str == '\t') || (temp_str == "") )
	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 changeto(highlightcolor){
source=event.srcElement
if (source.tagName=="TABLE")
return
while(source.tagName!="TR")
source=source.parentElement
if (source.style.backgroundColor!=highlightcolor&&source.id!="ignore")
source.style.backgroundColor=highlightcolor
}
 
function changeback(originalcolor){
if (event.fromElement.contains(event.toElement)||source.contains(event.toElement)||source.id=="ignore")
return
if (event.toElement!=source)
source.style.backgroundColor=originalcolor
}


function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}


function show_image(image)
{
	window.open('photo_gallery/show_image.php?image='+image,'GALLERY','toolbar=no,location=no,statusbar=no,resizable=yes,menubar=no,width=650,height=400,scrollbars=yes');
	
	return;
}
