var NS4 = (document.layers)?true:false;
var IE4 = (document.all)?true:false;

function getNumber(nValue) {
	var strValue	= "";
	if(nValue < 10) {
		strValue	= "0" + nValue;
	} else {
		strValue	= nValue;
	}	
	return(strValue);
}

function validateEmail(strEmail) {
    var regExpInValid 	= /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/;
    var regExpValid 	= /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
    if(!regExpInValid.test(strEmail) && regExpValid.test(strEmail)) {
		if(strEmail.indexOf(' ') <= 0) {
			return true;
		} else {
			return false;
		}
    } else {
		return false;
	}
    return false;
}

function moveAll(objFrom, objTo) {
	
	var nCount	= objFrom.options.length;
	for(i = 0; i < nCount; i++) {		
		objOption = new Option();
		objOption.value	= objFrom.options[0].value;
		objOption.text	= objFrom.options[0].text;
		if(NS4) {									
			objTo.options[i]	= objOption;				
		}else if(IE4){				
			objTo.options.add(objOption,i);		
		}
		objFrom.remove(0);						
		delete(objOption);
	}
}

function moveSelected(objFrom, objTo) {
	var nSelIndex	= objFrom.selectedIndex;
	var nCount		= objTo.options.length;
	if(nSelIndex >= 0) {
		objOption = new Option();
		objOption.value	= objFrom.options[nSelIndex].value;
		objOption.text	= objFrom.options[nSelIndex].text;
		if(NS4) {									
			objTo.options[nCount]	= objOption;				
		} else if(IE4) {				
			objTo.options.add(objOption,nCount);
		}				
		objFrom.remove(nSelIndex);		
		delete(objOption);
	}
}

function validateElement(objElement, strMessage, userSide) {
	
	if(objElement.value == "") {
		if(!userSide) {
			alert("Please enter " + strMessage + "!");	
		} else {
			alert(strMessage + "!");	
		}
		objElement.focus();
		return false;
	} else {
		return true;
	}
	return false;		
}

function validateSelection(objSelect, strMessage, userSide) {

	if(objSelect.selectedIndex < 0 || objSelect.options[objSelect.selectedIndex].value == 0) {
		if(!userSide) {
			alert(strMessage + " should be entered.");
		} else {
			alert(strMessage);	
		}
		objSelect.focus();
		return false;
	} else {
		return true;
	}
	
	return false;		
}

var nSelectedCount	= 0;

function selectCheckbox(objCheckbox) {
	if(objCheckbox.checked) {
		nSelectedCount++;
	} else {
		nSelectedCount--;
	}
}

function selectAllCheckbox(objCheckBox, formName, checkBoxId) {
	var frm 			= document.getElementById(formName);
	var	nCount			= 0;	
	var checkBoxList	= eval("frm." + checkBoxId);
	if(checkBoxList != null) {
		nCount	= checkBoxList.length;
	}
	if(nCount > 1) {
		for(i = 0; i < nCount; i++) {
			checkBoxList[i].checked	= objCheckBox.checked;
		}
		if(objCheckBox.checked) {
			nSelectedCount	= nCount;
		} else {
			nSelectedCount	= 0;
		}
	} else {
		if(checkBoxList != null) {
			checkBoxList.checked	= objCheckBox.checked;
			
			if(objCheckBox.checked) {
				nSelectedCount	= 1;
			} else {
				nSelectedCount	= 0;
			}
		}
	}
}

function openImageWindow(strImage, nWidth, nHeight) {
	var nLeft	= 0;
	var nTop	= 0;
	nLeft		= (window.screen.width - nWidth)/2;
	nTop		= (window.screen.height - nHeight)/2;
	var imagePopup = window.open(strImage,"","left=" + nLeft + ",top=" + nTop + ",height=" + nHeight + ",width=" + nWidth);
	imagePopup.document.write("<html><body topmargin='0' leftmargin='0'><img src='"+strImage+"'></body></html>");
}

function goPreviousPage() {
	window.history.go(-1);
}

function backToMainMenu() {

	window.location.href	= "aswAdminHome.php";
}

function goToPage(strPage) {
	window.location.href	= strPage;
}

function moveToPreviousPage(objForm, strPage) {

	objForm.action	= strPage;
	objForm.submit();
}

function showTooltip(status, objectId, objEvent) {
	
	var objTooltip	= document.getElementById(objectId);
	if(status) {
		objTooltip.className	= "showTooltip";
		objTooltip.style.left	= objEvent.x + 10;
		objTooltip.style.top 	= objEvent.y;
	} else {
		objTooltip.className	= "hideTooltip";
	}
}

/*function navigatePage(pageNo, className, formName) {

	/*var frm = eval("document." + formName);

	eval("frm." + className + "_pageIndex").value = pageIndex;
	frm.submit();*-/
	
	var frm = document.getElementById(formName);
	if(refreshList() == true) {
		frm.clsaswSearchServices_currentPage.value = pageNo;
		frm.submit();
		return true;
	}
}*/

function MM_openBrWindow(theURL, winName, nWidth, nHeight, features) {

	var nLeft	= 0;
	var nTop	= 0;
	nLeft		= (window.screen.width - nWidth)/2;
	nTop		= (window.screen.height - nHeight)/2;
	window.open(theURL,winName,"left=" + nLeft + ",top=" + nTop + ",height=" + nHeight + ",width=" + nWidth + "," + features);
}

function refreshPage(frm) {

	frm.submit();
}

function onPrintPage() {

	var objTop		= document.getElementById("topPane");
	var objLeft		= document.getElementById("leftPane");
	var objBottom	= document.getElementById("bottomPane");
	var btnPrint	= document.getElementById("btnPrint");
	if (objTop != null) {
		objTop.style.display	= (window.event.type == "beforeprint") ? "none" : "inline";
	}
	if (objLeft != null) {
		objLeft.style.display	= (window.event.type == "beforeprint") ? "none" : "inline";
	}
	if (objBottom != null) {
		objBottom.style.display	= (window.event.type == "beforeprint") ? "none" : "inline";
	}
	if (btnPrint != null) {
		btnPrint.style.display	= (window.event.type == "beforeprint") ? "none" : "inline";
	}
}

function trimval(str)
{
	return str.replace(/^\s+|\s+$/g, "");
}

function isAlphaNumeric(val, field)
{	 
	var myRegxp = 	/^[a-zA-Z0-9\s_-]+$/;

	if (myRegxp.test(val))
	{ 
		return true;
	}
	else
	{
		alert(field + " should be an alphanumeric srting;\n\rAllowed character set is {Alphabets, Numbers, Hiphen and Minus}");
		return false;
	} 
}

function validateNumber(objNumberField) {

	if(isNaN(objNumberField.value) || objNumberField.value == ""){
		alert("Please Specify a Number");
		objNumberField.focus();
		return false;
	} else {
		return true;
	}
}