/*
' Copyright (c) 2000 Affno (Pvt) Ltd, . All rights reserved.
'
' This software is the confidential and proprietary information of        
' Affno  ("Confidential Information").  You shall not disclose such 
' Confidential Information and shall use it only in accordance with
' the terms of the license agreement you entered into with Affno.
'
'Module Name	: NTBWEB1
' File Name		: clientSudemsg.js
' Description	: 
' Created By	: Shalini
' Created Date	: 28/04/2008
' Modified By	: 
' Modified Date	: 
' Version		: 1.00.000
*/

// Empty or Null
function isEmpty(inputStr) {
	if ((inputStr == null) || (inputStr=="")) return true
	else return false
}

// Space
function isSpace(str) {
	pattern = /^[\s]+$/
        if (str.match(pattern)) return true
           else return false;
}

//Trim Whitespaces
function trim(value) {
   var temp = value;
   var obj = /^(\s*)([\W\w]*)(\b\s*$)/;
   if (obj.test(temp)) { temp = temp.replace(obj, '$2'); }
   var obj = /  /g;
   while (temp.match(obj)) { temp = temp.replace(obj, " "); }
   return temp;
}

//Clear entry with white spaces at start, end and many in middle (becomes 1)
/*function trim(value) {
   var temp = value;
   var obj = /^(\s*)([\W\w]*)(\b\s*$)/;
   if (temp.match(obj)) { return true; }
   	else return false;
}*/

// Numbers only - (No of children, adults, passengers, rooms)
function isNumber(str) {
	pattern= /^[0-9]+$/
		if (!str.match(pattern)) return false
			else return true;
}

// Currency 
function isCurrency(str) {
	pattern= /^[0-9\.\,]+$/
		if (!str.match(pattern)) return false
			else return true;
}


// Letters with Space
function isLetters(str) {
	pattern = /^[a-zA-Z\s]+$/
		if (!str.match(pattern)) return false
			else return true;
}

// Numbers, Letters and Space - (Search, Identity card number, Passport number)
function isAlphaNu(str) {
	pattern = /^[a-zA-Z0-9\s]+$/
		if (!str.match(pattern)) return false
			else return true;
}

/* 
---- all cractors allowed --------	
	Address(postal, resident, mailing, shipping)
 	Zip code, postal code
 	Organization, Company
 	Message, remarks, comments, qualifications
*/	 

// Name - (first, last, full name)
function isName(str) {
	pattern = /^[a-zA-Z\s\-\.\']+$/
		if (!str.match(pattern)) return false
			else return true;
}

//Author Name
function isAuthorName(str) {
	pattern = /^[a-zA-Z\s\-\.\,\']+$/
		if (!str.match(pattern)) return false
			else return true;
}

// National iIdentity card number
function isNIC(str) {
	pattern = /^[0-9a-zA-Z\s]+$/
		if (!str.match(pattern)) return false
			else return true;
}



// Age
function isAge(str) {
	pattern = /^[0-9\s\.]+$/
		if (!str.match(pattern)) return false
			else return true;
}

// Email
function isEmail(str) {
     pattern = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,})+$/
        if (str.match(pattern)) return true
           else return false;
}
// URL
function isUrl(str) {
     pattern = /^[a-zA-Z\s\:\.\/]+$/
        if (str.match(pattern)) return true
           else return false;
}

// Telephone
function isTelephone(str) {
	pattern =/^[0-9a-zA-Z\s\-\/\,\(\)\+\.\:]+$/
		if (!str.match(pattern)) return false
			else return true;
}

// Fax
function isFax(str) {
	pattern =/^[0-9a-zA-Z\s\-\/\(\)\+\.]+$/
		if (!str.match(pattern)) return false
			else return true;
}

// Mobile Number
function isMobile(str) {
	pattern =/^[0-9\s\-\/\+]+$/
		if (!str.match(pattern)) return false
			else return true;
}

// SMS No
function isSmsNo(str) {
	pattern =/^[0-9\+]+$/
		if (!str.match(pattern)) return false
			else return true;
}

// Country
function isCountry(str) {
	pattern =/^[a-zA-Z\s\-\.\']+$/
		if (!str.match(pattern)) return false
			else return true;
}

// Postal Code
function isPostalCode(str) {
	pattern =/^[0-9a-zA-Z\s\-\/\(\)\+\.]+$/
		if (!str.match(pattern)) return false
			else return true;
}



// City, State, Province, Region
function isCity(str) {
	pattern = /^[0-9a-zA-Z\s\-\.\']+$/
		if (!str.match(pattern)) return false
			else return true;
}

// Designation, Position, occupation, post of applied for
function isDesignation(str) {
	pattern = /^[0-9a-zA-Z\s\-\/\.\,\"\(\)\']+$/
		if (!str.match(pattern)) return false
			else return true;
}

// Post applied for
function isPostApp(str) {
	pattern = /^[0-9a-zA-Z\s\-\/\.\:\?\!\;\,\"\(\)\']+$/
		if (!str.match(pattern)) return false
			else return true;
}

// Date (birth, arrival, departure, delivery)
function isSortDate(str) {
	pattern = /^[0-9\/\s]+$/
		if (!str.match(pattern)) return false
			else return true;
}

function isUName(str) {
	pattern = /^[a-zA-Z0-9\_]+$/
		if (!str.match(pattern)) return false
			else return true;
}


function isValidPwd(str) {
	if (str.lastIndexOf(" ") == -1) {
				return false;
	} else {
				return true;
	}
}

//Decimal number
function isDecNumber(str, len) {
	//pattern=/^[0-9]+[\.]{0,1}[0-9]{0,2}$/
	pattern=/^[0-9]+[\.]{0,1}[0-9]{0,9}$/
	if (((str.indexOf("."))!=-1) && (str.indexOf(".") > 10)){
			return false
		}
	else if (((str.indexOf("."))==-1) && (str.length > 10)) {
	return false;
	}
	else return(str.match(pattern));
}


//Key word
function isKeyWord(str) {
	pattern = /^[a-zA-Z0-9\s\-\']+$/
		if (!str.match(pattern)) return false
			else return true;
}


// Reference No
function isReferenceNo(str) {
     pattern = /^[a-zA-Z0-9\s\/\_]+$/
        if (str.match(pattern)) return true
           else return false;
}

// Account No
function isAccountNo(str) {
     pattern = /^[0-9\s\-]+$/
        if (str.match(pattern)) return true
           else return false;
}

//Disable password filed
function CheckFunction(){
if (document.miniadmin.changepass.checked ) {
	document.miniadmin.password.disabled = false;
	document.miniadmin.password.style.backgroundColor="#ffffff";
	document.miniadmin.password2.disabled = false;
	document.miniadmin.password2.style.backgroundColor="#ffffff";
} else {
	document.miniadmin.password.disabled = true;
	document.miniadmin.password.style.backgroundColor="#cccccc";
	document.miniadmin.password2.disabled = true;
	document.miniadmin.password2.style.backgroundColor="#cccccc";

	}
}

//========================Delete before confirm window=============//

function allowDeleteUser() {
return window.confirm("Are you sure you wish to delete this User?")
} 

function allowRejectCustomer() {
return window.confirm("Are you sure you wish to reject this Customer?")
} 

function allowDeleteLocation() {
return window.confirm("Are you sure you wish to delete this Location?")
}

function allowDeleteProduct() {
return window.confirm("Are you sure you wish to delete this Record?")
}


/*
==================================================================
isDate(string) : check whether date is in proper format
==================================================================
*/

var dtCh= "/";
	var minYear=1900;
	var maxYear=2100;

	function isInteger(s){
		var i;
	    for (i = 0; i < s.length; i++){   
    	    // Check that current character is number.
        	var c = s.charAt(i);
	        if (((c < "0") || (c > "9"))) return false;
    	}
	    // All characters are numbers.
	    return true;
	}

	function stripCharsInBag(s, bag){
		var i;
	    var returnString = "";
    	// Search through string's characters one by one.
	    // If character is not in bag, append to returnString.
    	for (i = 0; i < s.length; i++){   
        	var c = s.charAt(i);
	        if (bag.indexOf(c) == -1) returnString += c;
    	}
	    return returnString;
	}

	function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
	}
	function DaysArray(n) {
		for (var i = 1; i <= n; i++) {
			this[i] = 31
			if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
			if (i==2) {this[i] = 29}
   	} 
   	return this
	}

	function isDate(dtStr){
		var daysInMonth = DaysArray(12)
		var pos1=dtStr.indexOf(dtCh)
		var pos2=dtStr.indexOf(dtCh,pos1+1)
		var strDay=dtStr.substring(0,pos1)
		var strMonth=dtStr.substring(pos1+1,pos2)
		var strYear=dtStr.substring(pos2+1)
		strYr=strYear
		if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
		if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
		for (var i = 1; i <= 3; i++) {
			if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
		}
		month=parseInt(strMonth)
		day=parseInt(strDay)
		year=parseInt(strYr)
		
		if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
			alert("Please enter a valid day")
			return false
		}
		if (strMonth.length<1 || month<1 || month>12){
			alert("Please enter a valid Month")
			return false
		}
		if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
			alert("Please enter a valid 4 digit Year between "+minYear+" and "+maxYear)
			return false
		}
		if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
			alert("Please enter the Date \n E.g. dd/mm/yyyy")
			return false
		}
	return true
}


/*
==================================================================
LTrim(string) : Returns a copy of a string without leading spaces.
==================================================================
*/
function LTrim(str)
/*
   PURPOSE: Remove leading blanks from our string.
   IN: str - the string we want to LTrim
*/
{
   var whitespace = new String(" \t\n\r");

   var s = new String(str);

   if (whitespace.indexOf(s.charAt(0)) != -1) {
      // We have a string with leading blank(s)...

      var j=0, i = s.length;

      // Iterate from the far left of string until we
      // don't have any more whitespace...
      while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
         j++;

      // Get the substring from the first non-whitespace
      // character to the end of the string...
      s = s.substring(j, i);
   }
   return s;
}


function checkStyle(str)
{
	var chr = ""
	var nAlpha = 0
	var digits = 0
	
	/*for (position = 0; position < str.length; position++){
	   chr = str.charAt(position)
	   if ((chr >= "a" && chr <= "z") || (chr >= "A" && chr <= "Z")) nAlpha++
		if ((chr >= "0" && chr <= "9")) digits++
	}*/
	for (position = 0; position < 3; position++){
	   chr = str.charAt(position)
	   if ((chr >= "a" && chr <= "z") || (chr >= "A" && chr <= "Z")) nAlpha++
		
	}
	for (position = 3; position < 7; position++){
	   chr = str.charAt(position)
	   if ((chr >= "0" && chr <= "9")) digits++
	}
	
	
	if(str.length > 7)
	{
	return false
	}
	else if(nAlpha >3)
	{
	return false
	}
	else if(digits != 4)
	{
	return false
	}
	else if( (str.length == 7) && (nAlpha == 3)&& (digits == 4))
	{ 
	return true;
	}
	//else return true;
}

//To check file type for Images

function checkFile(str,fileid)
{
	fileLength = str.substring(str.lastIndexOf("\\")+1, str.length)
	hidfileextname = str.substring(str.lastIndexOf(".")+1, str.length);
	fname = str.substring(0,str.lastIndexOf("."))
	//alert(hidfileextname);
		if  ((fileLength!="") && (fileLength.length > 1500)) {
			alert(msgError_fileLenthFile_img);
			//document.AddVacancy.vac_Logo.focus();
			//document.getElementById(fileid).focus();
			return false;
		}
   		else if ((hidfileextname!="") && ((hidfileextname.toUpperCase() !="JPEG") &&(hidfileextname.toUpperCase() !="JPG") && (hidfileextname.toUpperCase() !="GIF"))){
			alert(msgError_validFile_img);
			return false;
		}
		else if ((fname!="") && (str.lastIndexOf(".") == -1)) {
			alert(msgError_validFile_img);
			return false;
		}
		else
		{
		
		return true;
		}
}

//To check file type for PDF

function checkFile_Pdf(str,fileid)
{
	fileLength = str.substring(str.lastIndexOf("\\")+1, str.length)
	hidfileextname = str.substring(str.lastIndexOf(".")+1, str.length);
	fname = str.substring(0,str.lastIndexOf("."))
	//alert(hidfileextname);
		if  ((fileLength!="") && (fileLength.length > 1500)) {
			alert(msgError_fileLenthFile_img);
			//document.AddVacancy.vac_Logo.focus();
			//document.getElementById(fileid).focus();
			return false;
		}
   		else if ((hidfileextname!="") && (hidfileextname.toUpperCase() !="PDF")){
			alert(msgError_validFile_pdf);
			return false;
		}
		else if ((fname!="") && (str.lastIndexOf(".") == -1)) {
			alert(msgError_validFile_pdf);
			return false;
		}
		else
		{
		
		return true;
		}
}


//To check file type for Htm

function checkFile_Htm(str,fileid)
{
	fileLength = str.substring(str.lastIndexOf("\\")+1, str.length)
	hidfileextname = str.substring(str.lastIndexOf(".")+1, str.length);
	fname = str.substring(0,str.lastIndexOf("."))
	//alert(hidfileextname);
		if  ((fileLength!="") && (fileLength.length > 1500)) {
			alert(msgError_fileLenthFile_img);
			//document.AddVacancy.vac_Logo.focus();
			//document.getElementById(fileid).focus();
			return false;
		}
   		else if ((hidfileextname!="") && ((hidfileextname.toUpperCase() !="HTM") && (hidfileextname.toUpperCase() !="HTML"))){
			alert(msgError_validFile_Htm);
			return false;
		}
		else if ((fname!="") && (str.lastIndexOf(".") == -1)) {
			alert(msgError_validFile_Htm);
			return false;
		}
		else
		{
		
		return true;
		}
}

//To check file type for Audio

function checkFile_Audio(str,fileid)
{
	fileLength = str.substring(str.lastIndexOf("\\")+1, str.length)
	hidfileextname = str.substring(str.lastIndexOf(".")+1, str.length);
	fname = str.substring(0,str.lastIndexOf("."))
	//alert(hidfileextname);
		/*if  ((fileLength!="") && (fileLength.length > 1500)) {
			alert(msgError_fileLenthFile_img);
			//document.AddVacancy.vac_Logo.focus();
			//document.getElementById(fileid).focus();
			return false;
		}
   		else */if ((hidfileextname!="")  && ((hidfileextname.toUpperCase() !="MP3"))&& ((hidfileextname.toUpperCase() !="WAV"))&& ((hidfileextname.toUpperCase() !="FLV")) && ((hidfileextname.toUpperCase() !="WMA"))){
			alert(msgError_validFile_img);
			return false;
		}
		else if ((fname!="") && (str.lastIndexOf(".") == -1)) {
			alert(msgError_validFile_img);
			return false;
		}
		else
		{
		
		return true;
		}
}


function filepath(filename,str)
{
alert(msgError_filePath)
document.forms[filename].elements[str].value ="";
document.forms[filename].elements[str].focus();
return false
}

function isTextLimit(maxchars,descLength) {
 if(descLength > maxchars) {
   alert('Allowed only 500 characters! Please remove '+
    (document.post.message.value.length - maxchars)+ ' characters');
   return false; }
 else
   return true; }
   
 function isTextLimit_Contact(maxchars,descLength) {
 if(descLength > maxchars) {
   alert('Allowed only '+ maxchars +' characters! Please remove '+
    (document.FrmContact.Comment.value.length - maxchars)+ ' characters');
   return false; }
 else
   return true; }
   
   
function login_link()
{
var login_opt=document.getElementById('login_opt').value;
	//alert(login_opt);
	if(login_opt == "personal"){ window.open ('https://www.online.nationstrust.com/');}
	else if(login_opt == "corporate"){ window.open('https://www.online.nationstrust.com/ntbcorporate/');}
	else if(login_opt == "credit"){ window.open('https://www.onlineamex.lk/Amex/customer/my_ac_login.jsp');}
	/*
	if(login_opt == "personal"){ window.location = 'https://www.online.nationstrust.com/';}
	else if(login_opt == "corporate"){ window.location = 'https://www.online.nationstrust.com/ntbcorporate/';}
	else if(login_opt == "credit"){ window.location = 'https://www.onlineamex.lk/Amex/customer/my_ac_login.jsp';}
	*/
	return true;
}

function index_link(in_link)
{
var card_name=document.getElementById(in_link).name;
var card=document.getElementById(in_link).value;
	//alert(card_name);
	if(card_name == 'card'){
		if(card == "1"){window.open ('http://www2.americanexpress.lk/personal/cards/restaurants/default.html');
			}
		else if(card == "2"){ window.open ('http://www2.americanexpress.lk/personal/cards/offers/travel_insurance.html');}
		else if(card == "3"){ window.open ('http://www2.americanexpress.lk/personal/cards/offers/abs.html');}
		else if(card == "4"){ window.open ('http://www2.americanexpress.lk/personal/cards/rewards/mr_plus.html');}
		else if(card == "5"){ window.open ('http://www2.americanexpress.lk/personal/cards/offers/esp.html');}
		return true;
	}
	
	if(card_name == 'sme'){
		if(card == "1"){ window.location = 'inpages/sme_banking/factoring.shtml';}
		else if(card == "2"){ window.location = 'inpages/sme_banking/leasing.shtml';}
		else if(card == "3"){ window.location = 'inpages/sme_banking/leasing_products.shtml';}
		else if(card == "4"){ window.location = 'inpages/sme_banking/leasing_products.shtml';}
		else if(card == "5"){ window.location = 'inpages/sme_banking/business_first.shtml';}
		return true;
	}
	
	if(card_name == 'personal'){
		if(card == "1"){ window.location = 'inpages/personal_banking/inner_circle.shtml';}
		else if(card == "2"){ window.location = 'inpages/personal_banking/personal_loans.shtml';}
		else if(card == "3"){ window.location = 'inpages/personal_banking/home_loans.shtml';}
		else if(card == "4"){ window.location = 'inpages/personal_banking/savings&investments.shtml';}
		else if(card == "5"){ window.location = 'inpages/personal_banking/private_banking.shtml';}
		return true;
	}
	if(card_name == 'corporate'){
		if(card == "1"){ window.location = 'inpages/corporate_banking/trade_finance.shtml';}
		else if(card == "2"){ window.location = 'inpages/corporate_banking/transactional_banking.shtml';}
		else if(card == "3"){ window.location = 'inpages/corporate_banking/transactional_banking.shtml';}
		else if(card == "4"){ window.location = 'inpages/personal_banking/savings&investments.shtml';}
		else if(card == "5"){ window.location = 'inpages/corporate_banking/working_capital_finance.shtml';}
		return true;
	}
}
