/*
* Popup Window with 'win' as name
*/
function popWin(url, w, h, scroll){
    URL = url + '';
    popWindow = window.open(url,'win','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=' + scroll + ',resizeable=0,copyhistory=0,height=' + h + ',width=' + w);
    // return(false);
}//popWin

/*
* Popup Window with 'win' as name
*/
function popWin2(url, w, h, scroll){
    URL = url + '';
    popWindow = window.open(url,'win2','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=' + scroll + ',resizeable=0,copyhistory=0,height=' + h + ',width=' + w);
    // return(false);
}//popWin

/*
* Closes current Window
*/
function closeWin() {
  window.close();
}


/*
* Popup Window for subscription form
*/
function subscribepop(f){
	if( !isValidEmail(f.email.value)){
		alert("Please enter a valid email address");
		f.email.focus();
		return false;
	}
	window.open("","subscribepop","toolbar=0,menubar=0,resizable=0,status=0,scrollbars=0,height=260,width=350"); 
	return true;
}//subscribepop


/*
* Checks whether the string str is empty
* Returns true if the string is empty
*/
function isEmptyString(str){
	
	//trim the leading whitespaces:
	regEx = /^\s*/gi;
	newStr = str.replace(regEx,"");
	if(newStr.length == 0){
		return true;
	}
	
	return false;
}//isEmptyString

/*
* Checks whether the string is valid decimal number (not in exponential form)
* Note: this is not 100% robust matching
* Returns true if the string is a valid number
*/
function isValidNumber(str){
	regEx = /^[+-]?\d+\.?\d*$/;
	res = str.search(regEx);
	if(res==-1){
		return false;
	}
	return true;
}//isValidNumber

/*
* Checks whether the string is longer than a maximalLength
*/
function isLongerThan(str, maxLen){
	if(str.length>maxLen){
		return true;
	}
	return false;
}//isLongerThan

/*
* Checks whether the string is valid date in 'YYYY-MM' format
* Returns true if the string is valid
*/
function isYYYYMM(str){
	regEx = /^\d{4}\-{1}01|02|03|04|05|06|07|08|09|10|11|12$/;
	res = str.search(regEx);
	if(res==-1){
		return false;
	}
	return true;
}//isYYYYMM

/*
* Returns the selected value of select box
*/
function getSelectedValue(selectBox){
	selInd = selectBox.selectedIndex;
	selOpt = selectBox.options[selInd];
	return selOpt.value;
}//getSelectedValue

/*
* Asks for confirmation berore executins link delAction
*/
function confirmDel(delAction){
	if (confirm("Are you sure you want to delete it?")){
		location.href = delAction;
	}
}//confirmDel

/*
* Checks whether the string is valid phone number
* Starting and eding with 3 digits, and an arbitrary number of 
* digits and dashes between
* Returns true if the string is a valid phone number
*/
function isValidPhone(str){
	regEx = /^(\d{3})[\d|\-]+(\d{3})$/;
	res = str.search(regEx);
	if(res==-1){
		return false;
	}
	return true;
}//isValidPhoneNumber

/*
* Checks whether the string is valid money str
* Optional '$' char, then digit(s) or , or .
* digits and dashes between
* Returns true if the string is a valid money number
*/
function isValidMoney(str){
	regEx = /^(\$?)[\d+|\,|\.]/;
	res = str.search(regEx);
	if(res==-1){
		return false;
	}
	return true;
}//isValidMoney



function isValidMoney2(str){
	regEx = /^\d+\s*[KMB]$/i;
	res = str.search(regEx);
	if(res!=-1){
		return true;
	}
	
	regEx = /^\d+\s*(Thousand|Million|Billion)$/i;
	res = str.search(regEx);
	if(res!=-1){
		return true;
	}
	
	regEx = /^\d+$/i;
	res = str.search(regEx);
	if(res!=-1){
		return true;
	}
	return false;
}//isValidMoney2


/*
* Checks whether the string is valid CC Number
*/
function isValidCC(str){
	regEx = /^(\d{4})\-(\d{4})\-(\d{4})\-(\d{4})$/;
	res = str.search(regEx);
	if(res==-1){
		return false;
	}
	return true;
}//isValidCC

/*
* Checks whether the string is valid email Address
*/
function isValidEmail(str){

 	if(str.indexOf("@") + "" == "-1" || str.indexOf(".") + "" == "-1"){
		return false;
    }
	return true;
}//isValidEmail




/*
* 	Show and hide popup autohelp windows
*/
function pv(e, num) {
	var span = document.getElementById("pv" +num);
	span.style.pixelLeft = e.clientX+document.body.scrollLeft;
	span.style.pixelTop = e.clientY+document.body.scrollTop+30;
	span.style.display="block";
}

function unpv(num) {
	var span = document.getElementById("pv" +num);
	span.style.display = "none";
}
