
function init(id)
{
	strid=new String(id);
	if (id != 'list_linkSearch')
		changeImage(id,'a');
	pictlinesrc='pict'+strid.substring(strid.length-1)+'_line.gif'
	document.images("pictline").src='../images/'+pictlinesrc
}

function changeImage(id,letter)
{
	document.images(id).src='../images/'+id+letter+'.gif'
}

function changeCheckbox(field,number,value)
{
	ischecked=document.f1.elements(field+number).checked
	
	for(i=1; ;i++)
		if(document.f1.elements(field+i))
		{
			if (i != number)
				document.f1.elements(field+i).checked=false
		}
		else
			break
	//document.f1.elements(field).value=value
}

function setStyle(obj,clname)
{
	obj.className=clname;
}

String.prototype.trim = function()
{
    // Use a regular expression to replace leading and trailing 
    // spaces with the empty string
    return this.replace(/(^\s*)|(\s*$)/g, "");
}

	function OpenWin(sFileName,wwidth,wheight,window_name,bScroll,bResizable)
	{
	if(window_name=='') { window_name='justawindow'; }
	if(wwidth=='') { wwidth=600; }
	if(wheight=='') { wheight=700; }
	if(bScroll=='' ) { bScroll='yes'; }
	if(bResizable=='') { bResizable='no'; }
	ww=screen.width;
	hh=screen.height;
	if(wwidth>ww) { xx=0;} else {xx=Math.round((ww-wwidth)/2)-5; }
	if(wheight>hh) { yy=0;} else { yy=Math.round((hh-wheight)/2); }
	options='location=no, toolbar=no, status=no, left='+xx+', top='+yy+', menubar=no, height='+wheight+', width='+wwidth+', scrollbars ='+bScroll+', resizable='+bResizable+'';
	file=sFileName;
	window.open(file,window_name,options);
	}	

function GetNumbersAndLetters(){
	var ch=event.keyCode;
	event.returnValue =((ch >= 48 && ch <= 57) || (ch >= 65 && ch <= 90) || (ch >= 97 && ch <= 122) || (ch >= 1488 && ch <= 1513) );
}


function getNumbers(){
	var ch=event.keyCode;
	event.returnValue =((ch >= 48 && ch <= 57) || ch ==46);
}

function getDateSymbols(){
	var ch=event.keyCode;
	event.returnValue =((ch >= 48 && ch <= 57) || ch ==45 || ch ==46 || ch ==47 );
}
function checkEmail(checkThisEmail){

//  return (strEmail.indexOf(".") > 2) && (strEmail.indexOf("@") > 0);
   //return /^\w+@([\w\-]+\.)+\w{2,3}$/.test(strEmail);
var myEMailIsValid = true;
var myAtSymbolAt = checkThisEmail.indexOf('@');
var myLastDotAt = checkThisEmail.lastIndexOf('.');
var mySpaceAt = checkThisEmail.indexOf(' ');
var myLength = checkThisEmail.length;


// at least one @ must be present and not before position 2
// @yellow.com : NOT valid
// x@yellow.com : VALID

if (myAtSymbolAt < 1 ) 
 {myEMailIsValid = false}


// at least one . (dot) afer the @ is required
// x@yellow : NOT valid
// x.y@yellow : NOT valid
// x@yellow.org : VALID

if (myLastDotAt < myAtSymbolAt) 
 {myEMailIsValid = false}

// at least two characters [com, uk, fr, ...] must occur after the last . (dot)
// x.y@yellow. : NOT valid
// x.y@yellow.a : NOT valid
// x.y@yellow.ca : VALID

if (myLength - myLastDotAt <= 2) 
 {myEMailIsValid = false}


// no empty space " " is permitted (one may trim the email)
// x.y@yell ow.com : NOT valid

if (mySpaceAt != -1) 
 {myEMailIsValid = false}


return myEMailIsValid

}

/*CHECK PHONE NUMBER*/

// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- /";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 9;

// Minimum no of digits in an international mobile phone no.
var minDigitsInIMobileNumber = 10;

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++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function checkPhone(strPhone){
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}

function checkMobile(strPhone){
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIMobileNumber);
}
/*END ofPHONE CHECHING*/


// ----------- calendar's functions -----------

function isAnyDate(dateStr) {

var datePat = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/;
var matchArray = dateStr.match(datePat); // is the format ok?

if (matchArray == null) {
alert("Please enter date as either dd/mm/yyyy or dd-mm-yyyy.");
return false;
}

month = matchArray[3]; // p@rse date into variables
day = matchArray[1];
year = matchArray[5];

if (month < 1 || month > 12) { // check month range
alert("Month must be between 1 and 12.");
return false;
}

if (day < 1 || day > 31) {
alert("Day must be between 1 and 31.");
return false;
}

if ((month==4 || month==6 || month==9 || month==11) && day==31) {
alert("Month "+month+" doesn`t have 31 days!")
return false;
}

if (month == 2) { // check for february 29th
var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
if (day > 29 || (day==29 && !isleap)) {
alert("February " + year + " doesn`t have " + day + " days!");
return false;
}
}
return true; // date is valid
}

var cal_w = null;
function popupcal(obField)
{
	f_name = "../include/popup_calend.asp?obName=" + obField.name + "&obValue='" + obField.value + "'"
	cal_w = window.open(f_name,"cal_w","left=250,top=150,height=180,width=180,status=no,toolbar=no,scroll=no,menubar=no,location=no")
	cal_w.focus();
	return false;
}
function win_close()
{
	if (cal_w)
	{cal_w.close();}
	
}
// ----------- end calendar's functions -----------
