function validateEmail(textBox, errorMessage){
	result = 0;
	var textBoxObject = document.getElementById(textBox);
	var textBoxValue = textBoxObject.value;
	var regEx = /^[\w][\w\d._]+[@][\w\d]{2,25}[.][.\w]{2,10}$/
	if ( textBoxValue.search(regEx) == -1 ) {
		textBoxObject.focus(); 
		alert(errorMessage);
		return false;
	}
	return true;
}

function checkNumber(textBox, errorMessage){
	var textBoxObject = document.getElementById(textBox);
	var textBoxValue = textBoxObject.value;
	if( textBoxValue == '' || isNaN(textBoxValue) != 0 ){
		textBoxObject.focus();
		alert(errorMessage);
		return false;
	}
	return true;
}

function checkNumberNM(textBox, errorMessage){
	var textBoxObject = document.getElementById(textBox);
	var textBoxValue = textBoxObject.value;
	if( textBoxValue != '' && isNaN(textBoxValue) != 0 ){
		textBoxObject.focus();
		alert(errorMessage);
		return false;
	}
	return true;
}

function checkPlainURLString(textBox, errorMessage){
	var txtBoxObj = document.getElementById(textBox);
	var textBoxValue = txtBoxObj.value;
	var regEx = /[\w\d\&]/
	var regEx2 = /^[\s]*[\w\d\s\&]+$/
	if ( textBoxValue.search(regEx) == -1 || textBoxValue.search(regEx2) == -1) {
		alert(errorMessage);
		txtBoxObj.focus();
		return false;
	}
	return true;
}

function checkPlainString(textBox, errorMessage){
	var txtBoxObj = document.getElementById(textBox);
	var textBoxValue = txtBoxObj.value;
	var regEx = /[\w\d\.\&\,\_\-\/]/
	var regEx2 = /^[\s]*[\w\d\s\.\&\,\_\-\/]+$/
	if ( textBoxValue.search(regEx) == -1 || textBoxValue.search(regEx2) == -1) {
		alert(errorMessage);
		txtBoxObj.focus();
		return false;
	}
	return true;
}

function checkPlainString2(textBox, errorMessage){
	var txtBoxObj = document.getElementById(textBox);
	var textBoxValue = txtBoxObj.value;
	var regEx = /[\w\d\W\D\s]/
	var regEx2 = /^[\s'"]*$/
	if ( textBoxValue.search(regEx) == -1 || textBoxValue.search(regEx2) == 0) {
		alert(errorMessage);
		txtBoxObj.focus();
		return false;
	}
	return true;
}

function checkForEmpty(textBox, errorMessage){
	var txtBoxObj = document.getElementById(textBox);
	var textBoxValue = txtBoxObj.value;
	if ( textBoxValue == "") {
		alert(errorMessage);
		txtBoxObj.focus();
		return false;
	}
	return true;
}

function checkUsername(textBox, errorMessage){
	var txtBoxObj = document.getElementById(textBox);
	var textBoxValue = txtBoxObj.value;
	var regEx = /[\w\d_]/
	var regEx2 = /^[\s]*[\w\d_]+$/
	if ( textBoxValue.search(regEx) == -1 || textBoxValue.search(regEx2) == -1 || textBoxValue.length < 6) {
		alert(errorMessage);
		txtBoxObj.focus();
		return false;
	}
	return true;
}

function compareValues(textBox1, textBox2, errorMessage){
	var txtBoxObj1 = document.getElementById(textBox1);
	var txtBoxObj2 = document.getElementById(textBox2);
	if ( txtBoxObj1.value != txtBoxObj2.value)
	{
		alert(errorMessage);
		return false;
	} 
	return true;
}

function checkForPassword(textBox, errorMessage, minLen){
	var txtBoxObj = document.getElementById(textBox);
	var textBoxValue = txtBoxObj.value;
	if ( textBoxValue.length < minLen ) {
		alert(errorMessage);
		txtBoxObj.focus();
		return false;
	}
	return true;
}

function checkPlainStringWLen(textBox, errorMessage, minLen, maxLen){
	var ret = checkPlainString(textBox, errorMessage);
	if ( ret == false) return false;
	var txtBoxObj = document.getElementById(textBox);
	var textBoxValue = txtBoxObj.value;
	if ( textBoxValue.length < minLen ) {
		alert(errorMessage);
		return false;
	}
	
	if ( textBoxValue.length > maxLen ) {
		alert(errorMessage);
		return false;
	}
	return true;
}

function checkIndex(textBox, errorMessage){
	var listBox = document.getElementById(textBox);
	if ( listBox.length == 0 || listBox.selectedIndex == 0 ) {
		alert(errorMessage);
		listBox.focus();
		return false;
	}
	return true;
}

function validateDate(textBox, errorMessage){
	var expiryDate = document.getElementById(textBox);
	if (expiryDate.value != "") {
		var datesarr = (new String(expiryDate.value)).split("-");
		var datesx = new Date(parseInt(datesarr[0]), parseInt(datesarr[1])-1, parseInt(datesarr[2]));
		var fullday = new Date();
		var today = new Date(parseInt(fullday.getFullYear()), parseInt(fullday.getMonth()), parseInt(fullday.getDate()));
		if ( datesx < today ) {
			alert("Selected date cannot be less than Today");
			return false;
		}
	} else {
		alert(errorMessage);
		return false;
	}
}

function getClearText( strSrc ) {
	 var regex = /<[^<|>]+?>/gi
	 return  strSrc.replace(regex, "");
}
function ShowSTFBox(xtype, xid) {
	
	var divObject = document.getElementById("divstfbox");	
	if (divObject == undefined) {
		alert("Error!");
		return false;
	}
	divObject.style.display = "block";
	document.getElementById('fade').style.display='block';		
	var iFrameObj = null;
	iFrameObj = document.getElementById("stfIframe");
	if ( iFrameObj == undefined ) {
		iFrameObj = document.createElement('iframe');
		iFrameObj.setAttribute("id","stfIframe");	
		iFrameObj.setAttribute("frameborder","0");
		iFrameObj.setAttribute("framespace","0");
		iFrameObj.setAttribute("hspace","0");
		iFrameObj.setAttribute("vspace","0");	
		iFrameObj.setAttribute("scrolling","auto");
		iFrameObj.setAttribute("marginheight","0");
		iFrameObj.setAttribute("marginwidth","0");	
		iFrameObj.style.display = "block";
		iFrameObj.style.float = "center";	
	}
	iFrameObj.src = "/sendtofriends.php?type="+xtype+"&id="+xid;
	divObject.appendChild(iFrameObj);
}

function resizeIframe(newHeight, newWidth) {
	//alert(newHeight+"-"+newWidth)
	var stfobj = document.getElementById('stfIframe');
	stfobj.style.height = parseInt(newHeight) + 10 + 'px';	
	stfobj.style.width = parseInt(newWidth) + 10 + 'px';
}
