var newWin = null;

function popUp(strURL, strType, strHeight, strWidth) 
{  
	if (newWin != null && !newWin.closed)    
		newWin.close();  
	
	var strOptions="";  
	
	if (strType=="console")    
		strOptions = "resizable,height=" + strHeight + ",width=" + strWidth;  
		
	if (strType=="fixed")    
		strOptions = "status,height=" + strHeight + ",width=" + strWidth;  
		
	if (strType=="elastic")    
		strOptions = "toolbar,menubar,scrollbars," + "resizable,location,height=" + strHeight + ",width=" + strWidth;  
		
	if (strType=="consoleWScroll")
		strOptions = "resizable,height=" + strHeight + ",width=" + strWidth + ",scrollbars";
	
	if (strType=="consoleNoScrollNoStatus") {
		strOptions = "resizable,height=" + strHeight + ",width=" + strWidth + ",noscrollbars";
		window.status = '';
	}
	newWin = window.open(strURL, 'newWin', strOptions);  
	newWin.focus();
}

function isNumber(inputVal) {
	oneDecimal = false;
	inputStr = inputVal.toString();
	for (var i = 0; i < inputStr.length; i++) {
		var oneChar = inputStr.charAt(i);
		if (i == 0 && oneChar == "-") {
			continue;
		}
		if (oneChar == "." && !oneDecimal) {
			oneDecimal = true;
			continue;
		}
		if (oneChar < "0" || oneChar > "9") {
			return false;
		}
	}
	return true;
}

function isPosInteger(inputVal)
{
	inputStr = inputVal.toString()
	for (var i = 0; i < inputStr.length; i++) {
		var oneChar = inputStr.charAt(i)
		if(oneChar < "0" || oneChar > "9") {
			return false
		} 
	}
	return true
}

//**************************************
// Name: Best Trim function
// Description:Sturdy javascript trim function. A must for good form validation! Good javascript trim functions are hard to come by.
// By: David Knipper
//
//
// Inputs:Trim(your_value);
//
// Returns:String
//
//Assumes:None
//
//Side Effects:None
//This code is copyrighted and has limited warranties.
//Please see http://www.1JavaStreet.com/xq/ASP/txtCodeId.3621/lngWId.2/qx/vb/scripts/ShowCode.htm
//for details.
//**************************************



    function Trim(TRIM_VALUE){


        	if(TRIM_VALUE.length < 1){
        		return"";
        	}
        	TRIM_VALUE = RTrim(TRIM_VALUE);
        	TRIM_VALUE = LTrim(TRIM_VALUE);


            	if(TRIM_VALUE==""){
            		return "";
            	}


                	else{
                		return TRIM_VALUE;
                	}
            }


                function RTrim(VALUE){
                	var w_space = String.fromCharCode(32);
                	var v_length = VALUE.length;
                	var strTemp = "";


                    	if(v_length < 0){
                    		return"";
                    	}
                    	var iTemp = v_length -1;


                        	while(iTemp > -1){
                        		if(VALUE.charAt(iTemp) == w_space){}


                            		else{
                            			strTemp = VALUE.substring(0,iTemp +1);
                            			break;
                            		}
                            		iTemp = iTemp-1;
                            	}
                            	return strTemp;
                        }


                            function LTrim(VALUE){
                            	var w_space = String.fromCharCode(32);


                                	if(v_length < 1){
                                		return"";
                                	}
                                	var v_length = VALUE.length;
                                	var strTemp = "";
                                	var iTemp = 0;


                                    	while(iTemp < v_length){
                                    		if(VALUE.charAt(iTemp) == w_space){}


                                        		else{
                                        			strTemp = VALUE.substring(iTemp,v_length);
                                        			break;
                                        		}
                                        		iTemp = iTemp + 1;
                                        	}
                                        	return strTemp;
                                    }
		

function stripVowelAccent(str)
{
var s=str;

var rExps=[ /[\xC0-\xC2]/g, /[\xE0-\xE2]/g,
/[\xC8-\xCA]/g, /[\xE8-\xEB]/g,
/[\xCC-\xCE]/g, /[\xEC-\xEE]/g,
/[\xD2-\xD4]/g, /[\xF2-\xF4]/g,
/[\xD9-\xDB]/g, /[\xF9-\xFB]/g ];

var repChar=['A','a','E','e','I','i','O','o','U','u'];

for(var i=0; i<rExps.length; i++)
s=s.replace(rExps[i],repChar[i]);

return  s;
}

function removeSpaces(string) {
	var tstring = "";
	string = '' + string;
	splitstring = string.split(" ");
	for(i = 0; i < splitstring.length; i++)
	tstring += splitstring[i];
	return tstring;
}


function removeCurrency( strValue ) {
/************************************************
DESCRIPTION: Removes currency formatting from
  source string.

PARAMETERS:
  strValue - Source string from which currency formatting
     will be removed;

RETURNS: Source string with commas removed.
*************************************************/
  var objRegExp = /\(/;
  var strMinus = '';

  //check if negative using ()
  if(objRegExp.test(strValue)){
	strMinus = '-';
  }

  objRegExp = /\)|\(|[,]/g;
  strValue = strValue.replace(objRegExp,'');

  if(strValue.indexOf('$') >= 0){
    strValue = strValue.substring(1, strValue.length);
  }
  return strMinus + strValue;
}

function formatCurrency(num) {
	if (num > 0) {
		num = num.toString().replace(/\$|\,/g,'');
	} else {
		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 getDeliveryDateObj(businessDaysLeftForDelivery) {
  var now = new Date();
  var dayOfTheWeek = now.getDay();
  var calendarDays = businessDaysLeftForDelivery;
  var deliveryDay = dayOfTheWeek + businessDaysLeftForDelivery;
  if (deliveryDay >= 6) {
    //deduct this-week days
    businessDaysLeftForDelivery -= 6 - dayOfTheWeek;
    //count this coming weekend
    calendarDays += 2;
    //how many whole weeks?
    deliveryWeeks = Math.floor(businessDaysLeftForDelivery / 5);
    //two days per weekend per week
    calendarDays += deliveryWeeks * 2;
  }
  now.setTime(now.getTime() + calendarDays * 24 * 60 * 60 * 1000);
  return now;
}

function emailCheck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false;
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    return false;
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return false;
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    return false;
		 }
		
		 if (str.indexOf(" ")!=-1){
		    return false;
		 }

 		 return true;					
}


// ******************************************************************
// This function accepts a string variable and verifies if it is a
// proper date or not. It validates format matching either
// mm-dd-yyyy or mm/dd/yyyy. Then it checks to make sure the month
// has the proper number of days, based on which month it is.

// The function returns true if a valid date, false if not.
// ******************************************************************

function isDate(dateStr) {

if (dateStr != "m/d/yyy") {

var datePat = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/;
var matchArray = dateStr.match(datePat); // is the format ok?

if (matchArray == null) {
//alert("Please enter date as either mm/dd/yyyy or mm-dd-yyyy.");
return false;
}

month = matchArray[1]; // p@rse date into variables
day = matchArray[3];
year = matchArray[5];

if (month < 1 || month > 12) { // check month range
//alert("Month must be between 1 and 12.");
return false;
}

if (day < 1 || day > 31) {
//alert("Day must be between 1 and 31.");
return false;
}

if ((month==4 || month==6 || month==9 || month==11) && day==31) {
//alert("Month "+month+" doesn`t have 31 days!")
return false;
}

if (month == 2) { // check for february 29th
var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
if (day > 29 || (day==29 && !isleap)) {
//alert("February " + year + " doesn`t have " + day + " days!");
return false;
}
}
return true; // date is valid
} else {
	return true;
}
}

