/* Javscript Functions for the internet banking login form */
// Start scripts
function fcs()
 {
     document.frm.id.focus();
 }
 
 function validate(id)
 {
     idno=document.frm.id.value; 
    pwd=document.frm.password1.value; 
    if(idno == "")
     {
         alert("Please Enter The ID."); 
        document.frm.id.focus();
        return false;
     }
    if(idno.length<=5 || idno.length>6) 
    {
         alert("ID Is Supposed To Be 6 Digits In Length") 
        document.frm.id.value="" 
        document.frm.id.focus();
        return false;
     } 
    if(pwd == "")     
    {
         alert("Please Enter The PIN.");
         document.frm.password1.focus(); 
         return false;
     }
     idno=document.frm.id.value;
     for(var i = 0; i < idno.length; i++)
     {
         var onechar=idno.charAt(i) 
    if(onechar <"0" || onechar >"9") 
    {
     alert("Enter only numbers");
     document.frm.id.value="" 
    document.frm.password1.value="" 
    document.frm.id.focus();
     return false;
     }
 }
  return true;
 
 } 
// End scripts


function openWindow(pageid, pageType) {
	sWidth = screen.availWidth;
	sHeight = screen.availHeight;

	sTop = (sHeight - 400) / 2;
	sLeft = (sWidth - 650) / 2;
	
	pageUrl = "";
	
	pageUrl = "view_news.php?news_id=" + pageid;
	window.open(pageUrl, "dhanwindow", "width=650,height=400,top=" + sTop + ",left=" + sLeft + ",toolbar=0,menubar=0,status=0,scrollbars=1,resizable=0");
	return;
}

function openLoan(){
	sWidth = screen.availWidth;
	sHeight = screen.availHeight;

	sTop = (sHeight - 400) / 2;
	sLeft = (sWidth - 650) / 2;
	pageUrl = "0100loan.asp"
	window.open(pageUrl, "dhanwindow", "width=650,height=400,top=" + sTop + ",left=" + sLeft + ",toolbar=0,menubar=0,status=0,scrollbars=1,resizable=0");
	return;

}

function doSearch(pageName, pagelink) {
	searchKey = trimSpaces(document.searchForm.searchKey.value);
	if(searchKey.length <= 0) {
		alert("Please enter a keyword to search with");
		document.searchForm.searchKey.focus();
		return;
	}
	else {
		searchKey = escape(searchKey)
		if(pageName == "sub") {
			parent.window.location.href = "../asp/0100page.asp?searchKey=" + searchKey + "&pagetype=Search&pagename=" + pagelink;
		}
		else {
			parent.window.location.href = "asp/0100page.asp?searchKey=" + searchKey + "&pagetype=Search&pagename=" + pagelink;
		}
	}
}

/////////////////////////////////////////////////////////////////////////////////////////
// Removes the leading and trailing spaces in a strings and returns the trimmed string
/////////////////////////////////////////////////////////////////////////////////////////
function trimSpaces(stringValue) {
	// Checks the first occurance of spaces and removes them
	for(i = 0; i < stringValue.length; i++) {
		if(stringValue.charAt(i) != " ") {
			break;
		}
	}
	if(i > 0) {
		stringValue = stringValue.substring(i);
	}
	
	// Checks the last occurance of spaces and removes them
	strLength = stringValue.length - 1;
	for(i = strLength; i >= 0; i--) {
		if(stringValue.charAt(i) != " ") {
			break;
		}
	}
	if(i < strLength) {
		stringValue = stringValue.substring(0, i + 1);
	}
	
	// Returns the string after removing leading and trailing spaces.
	return stringValue;
}
