 /**********************************************************************************/
  function AddDateToList(List, vDate)
   {	if (vDate!=''  && vDate!='{nothing}')	
		{	if (List.indexOf(Date)==-1) 
				{ if (List!=''  && List!='{nothing}' ) {return (List+ ','+ vDate+',');} else {return (','+ vDate+',');}
				
				}
			else {return List;}
		}else {return List;}
   }

/**************************Browser' s type***************************/
  
  var ie4up;  if (navigator.userAgent.indexOf("MSIE")>=0){ ie4up= true;} else { ie4up=false;}
  

/**********************************************************************************/
	  function help(Service)
	  {
		window.open("help.aspx?Service="+Service, null,"toolbar=no,location=no,directories=no, status=no,menubar=no,resizable=yes,scrollbars=yes, copyhistory=no,width=860,height=400" );
	  }

/**********************************************************************************/
	function ReplaceAll(expression, find, replacewith)
	{	if (expression!=null)
		{	var re = new RegExp(find, "gi");
			return ( expression.replace(re, replacewith) );
		}
		else
		{
			return ( '');
		}
	}
	   
   
   function AddToList(List, User)
   {	if (User!=''  && User!='{nothing}')	
		{	if (List.indexOf(User)==-1) 
				{ if (List!=''  && List!='{nothing}' ) {return (List+ '-'+ User+'-');} else {return ('-'+ User+'-');}
				
				}
			else {return List;}
		}else {return List;}
   }
   
   function IsInList(List, User)
   {if (List.indexOf('-'+User+'-')>=0) {return true; }  else {return false; }
   }
   
   function RemoveFromList(List, User)
   {
			if 		(List.indexOf('--'+ User +'--')!=-1) {return (ReplaceAll(List, '--'+ User +'--', '--'))}
			else if	(List.indexOf('-'+ User+'-' )!=-1) {return (ReplaceAll(List, '-'+ User+'-' , ''))}
			else return (List);
   }
   
   function SexeCase(UserGenderValue)
   {
		switch (UserGenderValue)
		{
		 case "5":
			imagesPath="images/phom.gif";sexeX='sexeM';txtaskX='txtaskM';break;				//Male seeking Male
		 case "7":
			imagesPath="images/hom.gif";sexeX='sexeM';txtaskX='txtaskM';break;				//Male seeking Female
		 case "11":
			imagesPath="images/araig.gif";sexeX='sexeM';txtaskX='txtaskM';break;			//Male seeking Couple(Male/Female)
		 case "10":
			imagesPath="images/fem.gif";sexeX='sexeF';txtaskX='txtaskF';break;				//Female seeking Male
		 case "14":
			imagesPath="images/pfem.gif";sexeX='sexeF';txtaskX='txtaskF';break;				//Female seeking Female
		 case "22":
			imagesPath="images/s15.gif";sexeX='sexeF';txtaskX='txtaskF';break;				//Female seeking Couple(Male/Female)
		 case "15":
			imagesPath="images/yingbluewhite.gif";sexeX='sexeC';txtaskX='txtaskC';break;	//Couple(M/F) seeking Male
		 case "21":
			imagesPath="images/yingrosewhite.gif";sexeX='sexeC';txtaskX='txtaskC';break;	//Couple(M/F) seeking Female
		 case "33":
			imagesPath="images/yingblackwhite.gif";sexeX='sexeC';txtaskX='txtaskC';break;	//Couple(M/F) seeking Couple(M/F)
		 default:
			imagesPath="images/tasse.gif";sexeX='sexeC';txtaskX='txtaskC';break;			// !
		}  
	}


/**********************************************************************************/

function stripWhiteSpace(txtField)
{
	var  strName;
	var  data;
	if(txtField.value)
	{
		if(txtField.value.length > 0)
		{
			txtField.value = Replace(txtField.value, " ", "");
			
			data = txtField.value;
			strName = data.substr(0,1).toUpperCase();
			strName += data.substr(1).toLowerCase();
			txtField.value = strName;
		
		}
	 }
}

/**********************************************************************************/
function  changeCase(objText)
    {	 var  k=0;
         var  strName;
         var  data = objText.value;
         
		 	
			if(data) 
    		{  if(data.length > 0) 
				{ 
					data = Replace(data, " ", "");
					data = Replace(data, ";", ",");
					strName = data.substring(0,1).toUpperCase();
					while  (  (-1<data.indexOf(",",k)) && (data.indexOf(",",k)<data.length) )
					{	q = data.indexOf(",",k);
						strName += data.substring(k+1,q+1).toLowerCase(); 
						strName += " "+ data.substring(q+1,q+2).toUpperCase(); 
						k=q+1;
					}
					if (data.indexOf(",",k)==-1)
					{	strName += data.substring(k+1).toLowerCase();  
					}
					objText.value = strName;
			   }
			}
			
    }
    
/**********************************************************************************/
function  GetTextByValues(obj,obj_type,ovalues)
	{		
	 var i;
	 var j;
	 var AA;
	
	if ((ovalues!=null)	&& (ovalues!='') && (obj) )
	{ 		
		if (obj_type == "text" || obj_type == "password" || obj_type == "textarea" || obj_type == "file")
		{
		


		} else if (obj_type == "select")
		{

			if (ie4up)	{	BeginTag	='value='+ovalues+'>';} else {BeginTag	='value="'+ovalues+'">';}
			EndTag		='<';

			if (obj.innerHTML.indexOf(BeginTag,0)>=0 )
			{ if (obj.innerHTML.indexOf(EndTag,obj.innerHTML.indexOf(BeginTag,0)+BeginTag.length)>=0) 
			     {return obj.innerHTML.substring( obj.innerHTML.indexOf(BeginTag,0)+BeginTag.length, obj.innerHTML.indexOf(EndTag,obj.innerHTML.indexOf(BeginTag,0)+BeginTag.length) );}
			  else return "";
			}
			else
			{
				if (ie4up)	{	BeginTag	='value='+ovalues+' selected>';} else {BeginTag	='value="'+ovalues+'" selected>';}
				EndTag		='<';
				if (obj.innerHTML.indexOf(BeginTag,0)>=0 )
				{ if (obj.innerHTML.indexOf(EndTag,obj.innerHTML.indexOf(BeginTag,0)+BeginTag.length)>=0) 
					 {return obj.innerHTML.substring( obj.innerHTML.indexOf(BeginTag,0)+BeginTag.length, obj.innerHTML.indexOf(EndTag,obj.innerHTML.indexOf(BeginTag,0)+BeginTag.length) );}
				  else return "";
				}
				else return "";
			}
							
		} else if (obj_type == "radio" || obj_type == "checkbox")
		{    //dont forget to design obj between <a></a> tag
			if (!obj[0] && obj) {
				i=0;TextByValues="";m=0;
				do{	if (ovalues.indexOf("}",i)>-1) {AA=ovalues.substring(i+1,ovalues.indexOf("}",i)); }
						if (ie4up)	{	BeginTag	='value='+AA+' ';} else {BeginTag	='value="'+AA+'"';}
						EndTag		='<';
						if (m==0){	if (obj.innerHTML.indexOf(BeginTag,0)>=0 )
									{ BeginTaglength	=1 + obj.innerHTML.indexOf('>', obj.innerHTML.indexOf(BeginTag,0)) - obj.innerHTML.indexOf(BeginTag,0)  
									  if (obj.innerHTML.indexOf(EndTag,obj.innerHTML.indexOf(BeginTag,0)+BeginTaglength)>=0) 
										 {TextByValues= obj.innerHTML.substring( obj.innerHTML.indexOf(BeginTag,0)+BeginTaglength, obj.innerHTML.indexOf(EndTag,obj.innerHTML.indexOf(BeginTag,0)+BeginTaglength) );}
									  else TextByValues= "";
									}
									else TextByValues= "";
						} else	{	if (obj.innerHTML.indexOf(BeginTag,0)>=0 )
									{ BeginTaglength	=1 + obj.innerHTML.indexOf('>', obj.innerHTML.indexOf(BeginTag,0)) - obj.innerHTML.indexOf(BeginTag,0)  
									  if (obj.innerHTML.indexOf(EndTag,obj.innerHTML.indexOf(BeginTag,0)+BeginTaglength)>=0) 
										 {TextByValues= TextByValues +', '+ obj.innerHTML.substring( obj.innerHTML.indexOf(BeginTag,0)+BeginTaglength, obj.innerHTML.indexOf(EndTag,obj.innerHTML.indexOf(BeginTag,0)+BeginTaglength) );}
									  else TextByValues= TextByValues ;
									}
									else TextByValues= TextByValues ;
						}
						m=1;
						
		 			i=ovalues.indexOf("}",i)+2;
		 		  }
				while (0< i && i<ovalues.length);
				return TextByValues;
			
			} else
			{
				i=0;TextByValues="";m=0;
				do{	if (ovalues.indexOf("}",i)>-1) {AA=ovalues.substring(i+1,ovalues.indexOf("}",i)); }
		 			for (j=0,k=0;(j<=obj.length-1) &&( k==0); j++)
		 			{
						if (ie4up)	{	BeginTag	='value='+AA+' ';} else {BeginTag	='value="'+AA+'"';}
						EndTag		='<';
						if (m==0){	if (obj[j].innerHTML.indexOf(BeginTag,0)>=0 )
									{ BeginTaglength	=1 + obj[j].innerHTML.indexOf('>', obj[j].innerHTML.indexOf(BeginTag,0)) - obj[j].innerHTML.indexOf(BeginTag,0)  
									  if (obj[j].innerHTML.indexOf(EndTag,obj[j].innerHTML.indexOf(BeginTag,0)+BeginTaglength)>=0) 
										 {TextByValues= obj[j].innerHTML.substring( obj[j].innerHTML.indexOf(BeginTag,0)+BeginTaglength, obj[j].innerHTML.indexOf(EndTag,obj[j].innerHTML.indexOf(BeginTag,0)+BeginTaglength) );}
									  else TextByValues= "";
									}
									else TextByValues= "";
						} else	{	if (obj[j].innerHTML.indexOf(BeginTag,0)>=0 )
									{ BeginTaglength	=1 + obj[j].innerHTML.indexOf('>', obj[j].innerHTML.indexOf(BeginTag,0)) - obj[j].innerHTML.indexOf(BeginTag,0)  
									  if (obj[j].innerHTML.indexOf(EndTag,obj[j].innerHTML.indexOf(BeginTag,0)+BeginTaglength)>=0) 
										 {TextByValues= TextByValues +', '+ obj[j].innerHTML.substring( obj[j].innerHTML.indexOf(BeginTag,0)+BeginTaglength, obj[j].innerHTML.indexOf(EndTag,obj[j].innerHTML.indexOf(BeginTag,0)+BeginTaglength) );}
									  else TextByValues= TextByValues ;
									}
									else TextByValues= TextByValues ;
						}
		 				k=1;m=1;
		 			}
		 			i=ovalues.indexOf("}",i)+2;
		 		 }
				while (0< i && i<ovalues.length);
				return TextByValues;
			}
			
		} else {
			return "";
		}
	  }else
	  {
			return "";
	  }
	}
	
/**********************************************************************************/
function SearchResultBillingTest()
{  //to manage the xml document 
   var  objDOMi ;// = new ActiveXObject("Microsoft.XMLDOM");
   //to establish a http connection between the server 
   //and the client, thereby sending and receiving 
   //message to and from the server 
   //without submitting the page   
   if (ie4up)				       // for internet explorer
   { var  xmlhi = new ActiveXObject("Microsoft.XMLHTTP");
   } else					                                       // for firefox 
   {var  xmlhi 	= new XMLHttpRequest();
   }
   xmlhi.open("POST","login.aspx?billingtest=true", false );
   if  (ie4up) {xmlhi.send("");} else {xmlhi.send(null);}
   // objDOMi.async= false;	
   answeri = xmlhi.responseText;
   objDOMi = loadXML(answeri.substring(answeri.indexOf("<Bill>"),answeri.indexOf("</Bill>")+7));
   Bill= utf8Decode(NodesItem(getNodes(objDOMi, "Bill"), 0)); 
   
   if (Bill =='true') 
   {	return Bill;
   }
   else
   {
        //return 'true';
        ModalBox(false,"You must enter your Email and your Password.");
		//see in SearchResult.aspx  for Session("NextLocation")="....."
	 	window.location.href='index.aspx' ; window.focus();
		return 'false';
   }
}

/**********************************************************************************/
function ViewProfile( strUserName,Viewer) 
{
	   
    var strName;
	var strUrl;
	strName = 'viewprofile' + strUserName;
	strUrl = "launchviewprofile.aspx?UserName=" + utf8EncodeX(strUserName) +"&Viewer="+ utf8EncodeX(Viewer);
	launchWindow(strUrl, strName, 625, 450, 'status=yes, scrollbars=yes,resizable=yes,menubar=no,location=yes,directories=yes,toolbar=no');
	
}

/**********************************************************************************/
function createWindow(strURL, strName, intWidth, intHeight, strProperties)
{
	var mywin;
	var intVersion;
	
	if (strProperties == "") {
		strProperties = "status=yes, scrollbars=yes,resizable=yes,menubar=no,location=yes,directories=yes,toolbar=no";
	}
	
	strProperties = "height=" + intHeight + ",width=" + intWidth + "," + strProperties;
	
	mywin = window.open(strURL, strName, strProperties);
	mywin.name = strName
	if (mywin.opener == null) mywin.opener = self;
	
	// return handle to caller
	return mywin;
}

/**********************************************************************************/
function launchWindow(strURL, strName, intWidth, intHeight, strProperties) 
{
	// just create a window with the given properties and don't return the handle
	// to the window. (for inline javascript: calls in hrefs)
	createWindow(strURL, strName, intWidth, intHeight, strProperties);
}


/**********************************************************************************/
function LoadStates()
{		
	if (document.getElementById("CountryRegionID").value == 68) 
	{
		var ListOfStates	=	"<select  id=State name=State	  >"+
								"<option selected value=0></option>"+
								"<option value=1>Alabama</option>"+
								"<option value=2>Alaska</option>"+
								"<option value=3>Arizona</option>"+
								"<option value=4>Arkansas</option>"+
								"<option value=5>California</option>"+
								"<option value=6>Colorado</option>"+
								"<option value=7>Connecticut</option>"+
								"<option value=8>Delaware</option>"+
								"<option value=9>District of Columbia</option>"+
								"<option value=10>Florida</option>"+
								"<option value=11>Georgia</option>"+
								"<option value=12>Hawaii</option>"+
								"<option value=13>Idaho</option>"+
								"<option value=14>Illinois</option>"+
								"<option value=15>Indiana</option>"+
								"<option value=16>Iowa</option>"+
								"<option value=17>Kansas</option>"+
								"<option value=18>Kentucky</option>"+
								"<option value=19>Louisiana</option>"+
								"<option value=20>Maine</option>"+
								"<option value=21>Maryland</option>"+
								"<option value=22>Massachusetts</option>"+
								"<option value=23>Michigan</option>"+
								"<option value=24>Minnesota</option>"+
								"<option value=25>Mississippi</option>"+
								"<option value=26>Missouri</option>"+
								"<option value=27>Montana</option>"+
								"<option value=28>Nebraska</option>"+
								"<option value=29>Nevada</option>"+
								"<option value=30>New Hampshire</option>"+
								"<option value=31>New Jersey</option>"+
								"<option value=32>New Mexico</option>"+
								"<option value=33>New York</option>"+
								"<option value=34>North Carolina</option>"+
								"<option value=35>North Dakota</option>"+
								"<option value=36>Ohio</option>"+
								"<option value=37>Oklahoma</option>"+
								"<option value=38>Oregon</option>"+
								"<option value=39>Pennsylvania</option>"+
								"<option value=40>Rhode Island</option>"+
								"<option value=41>South Carolina</option>"+
								"<option value=42>South Dakota</option>"+
								"<option value=43>Tennessee</option>"+
								"<option value=44>Texas</option>"+
								"<option value=45>Utah</option>"+
								"<option value=46>Vermont</option>"+
								"<option value=47>Virginia</option>"+
								"<option value=48>Washington</option>"+
								"<option value=49>West Virginia</option>"+
								"<option value=50>Wisconsin</option>"+
								"<option value=51>Wyoming</option>"+
								"</select>";
		document.getElementById("IdState").innerHTML=	ListOfStates;

	}
	else if (document.getElementById("CountryRegionID").value == 40) 
	{
		var ListOfStates	=	"<select  id=State name=State	  >"+
								"<option selected value=0></option>"+
								"<option value=1>Alberta</option>"+
								"<option value=2>British Columbia</option>"+
								"<option value=3>Manitoba</option>"+
								"<option value=4>New Brunswick</option>"+
								"<option value=5>Newfoundland</option>"+
								"<option value=6>Northwest Territories</option>"+
								"<option value=7>Nova Scotia</option>"+
								"<option value=8>Nunavut</option>"+
								"<option value=9>Ontario</option>"+
								"<option value=10>Prince Edward Island</option>"+
								"<option value=11>Quebec</option>"+
								"<option value=12>Saskatchewan</option>"+
								"<option value=13>Yukon Territory</option>"+
								"</select>";
		document.getElementById("IdState").innerHTML=	ListOfStates;
		
	}	
	else
	{
		document.getElementById("IdState").innerHTML="<input  id=State  name=State size=37  style=' WIDTH: 221px'>";
	
	}
	
}

function GetState(CountryRegionID,State)
{		
	if (CountryRegionID == 68) 
	{
		switch (State)
		{	case '1' :
		       return "Alabama"
			case '2' :
				return "Alaska"
			case '3' :
				return "Arizona"
			case '4' :
				return "Arkansas"
			case '5' :
				return "California"
			case '6' :
				return "Colorado"
			case '7' :
				return "Connecticut"
			case '8' :
				return "Delaware"
			case '9' :
				return "District of Columbia"
			case '10' :
				return "Florida"
			case '11' :
				return "Georgia"
			case '12' :
				return "Hawaii"
			case '13' :
				return "Idaho"
			case '14' :
				return "Illinois"
			case '15' :
				return "Indiana"
			case '16' :
				return "Iowa"
			case '17' :
				return "Kansas"
			case '18' :
				return "Kentucky"
			case '19' :
				return "Louisiana"
			case '20' :
				return "Maine"
			case '21' :
				return "Maryland"
			case '22' :
				return "Massachusetts"
			case '23' :
				return "Michigan"
			case '24' :
				return "Minnesota"
			case '25' :
				return "Mississippi"
			case '26' :
				return "Missouri"
			case '27' :
				return "Montana"
			case '28' :
				return "Nebraska"
			case '29' :
				return "Nevada"
			case '30' :
				return "New Hampshire"
			case '31' :
				return "New Jersey"
			case '32' :
				return "New Mexico"
			case '33' :
				return "New York"
			case '34' :
				return "North Carolina"
			case '35' :
				return "North Dakota"
			case '36' : 
				return "Ohio"
			case '37' : 
				return "Oklahoma"
			case '38' :
				return "Oregon"
			case '39' :
				return "Pennsylvania"
			case '40' : 
				return "Rhode Island"
			case '41' :
				return "South Carolina"
			case '42' :
				return "South Dakota"
			case '43' :
				return "Tennessee"
			case '44' :
				return "Texas"
			case '45' :
				return "Utah"
			case '46' :
				return "Vermont"
			case '47' :
				return "Virginia"
			case '48' :
				return "Washington"
			case '49' :
				return "West Virginia"
			case '50' :
				return "Wisconsin"
			case '51' : 
				return "Wyoming"
		 }

	}
	else if (CountryRegionID == 40) 
	{
		switch (State)
		{	case '1' :
				 return "Alberta"
			case '2' : 
				return "British Columbia"
			case '3' : 
				return "Manitoba"
			case '4' : 
				return "New Brunswick"
			case '5' : 
				return "Newfoundland"
			case '6' : 
				return "Northwest Territories"
			case '7' : 
				return "Nova Scotia"
			case '8' : 
				return "Nunavut"
			case '9' : 
				return "Ontario"
			case '10': 
				return "Prince Edward Island"
			case '11' : 
				return "Quebec"
			case '12' : 
				return "Saskatchewan"
			case '13' :
				return "Yukon Territory"
		 }
		
	}	
	else
	{
		return State
	
	}
	
}

/**********************************************************************************/
function Replace(str, substring, newstring) {
	if (str.length <= 0)
		return "";

	temp = "" + str; 

	while (temp.indexOf(substring)>-1) {
	pos = temp.indexOf(substring);
	temp = "" + (temp.substring(0, pos) + newstring + temp.substring((pos + substring.length), temp.length));
	}
	return temp;
}
/**********************************************************************************/

function IsEmpty(obj, obj_type)
{
	if (obj_type == "text" || obj_type == "password" || obj_type == "textarea" || obj_type == "file")	    {
		var objValue;
		
		objValue = obj.value.replace(/\s+$/,"");
		
		if (objValue.length == 0) {
			if (obj.enabled) obj.focus();
			return true;
		} else {
			return false;
		}
	} else if (obj_type == "select") {
		for (i=0; i < obj.length; i++) {
			if (obj.options[i].selected) {
				if(obj.options[i].value == "") {
					if (obj.enabled) obj.focus();
					return true;
				} else {
					return false;
				}
			}
			
		}
		return true;	
	} else if (obj_type == "radio" || obj_type == "checkbox") {
		if (!obj[0] && obj) {
			if (obj.checked) {
				return false;
			} else {
				if (obj.enabled) obj.focus();
				return true;	
			}
		} else {
			for (i=0; i < obj.length; i++) {
				if (obj[i].checked) {
					return false;
				}
			}
			if (obj[0].enabled) obj[0].focus();
			return true;
		}
	} else {
		return false;
	}
}

function InLengthRange(object_value, min_value, max_value)
{
	
	if (object_value == null) {
		return true;
	}

	if (min_value == null) {
		min_value = 0;
	}
	
	if (max_value == null) {
		if (object_value.length >= min_value) {
			return true;
		} else {
			return false;
		}
	}
	
	if (object_value.length >= min_value && object_value.length <= max_value) {
		return true;
	} else {
		return false;
	}

}

function InValueRange(object_value, min_value, max_value)
{
	
	if (object_value == null) {
		return true;
	}
	else {
		if (object_value == '')
			return true;
	}

	if (min_value == null) {
		min_value = 0;
	}
	
	

	if (max_value == null) {
		if (object_value >= min_value) {
			return true;
		} else {
			return false;
		}
	}
	
	if (object_value >= min_value && object_value <= max_value) {
		return true;
	} else {
		return false;
	}

}


function TestNumberRange(object_value, min_value, max_value)
{
	// check minimum
	if (min_value != null) {
		if (object_value < min_value) {
			return false;
		}
	}
		
	// check maximum
	if (max_value != null) {
		if (object_value > max_value) {
			return false;
		}
	}
	//All tests passed, so...
	return true;
}

function IsValidDate(month, day, year) {
	var blnRet;

	if (month ==  "" || day == "" || year == "") {
		return true;
	}

	day = parseInt(day)
	month = parseInt(month)
	year = parseInt(year)
	

	if( (day >= 1 && day <= 31) && 
		(month >=1 && month <= 12) && 
		(year > 0) ) {
		blnRet = true;
		switch(month) {
			case 2:
				
				if(day > 28) {
					// check for leap years
					if( ((year % 4 == 0) && (year % 100 != 0)) ||
						(year % 400 == 0) ) {
						if(day > 29) {
							blnRet =  false;
						}
					} else {
						blnRet = false;
					}
				}
				break;
			case 4:
			case 6:
			case 9:
			case 11:
				if(day > 30) {
					blnRet = false;
				}
				break;
			default:
				break;
		}
	} else {
		blnRet = false;
	}
		
	return blnRet;
}

function IsInteger(object_value)
{
    if (object_value.length == 0){
		return true;
	}

	var decimal_format = ".";
	var check_char;

    //The first character can be + -  blank or a digit.
	check_char = object_value.indexOf(decimal_format)

    //Was it a decimal?
	if (check_char < 1) {
		return IsNumeric(object_value);
	} else {
		return false;
	}
}


function IsNumeric(object_value)
{
	//Returns true if value is a number or is NULL
	//otherwise returns false	
	
	if (object_value.length == 0) {
		return true;
	}
	
	//	Returns true if value is a number defined as
	//	having an optional leading + or -.
	// 	having at most 1 decimal point.
	//	otherwise containing only the characters 0-9.
	var start_format = " .+-0123456789";
	var number_format = " .0123456789";
	var check_char;
	var decimal = false;
	var trailing_blank = false;
	var digits = false;
	
	//The first character can be + - .  blank or a digit.
	check_char = start_format.indexOf(object_value.charAt(0))
	//Was it a decimal?
	if (check_char == 1) {
		decimal = true;
	} else if (check_char < 1) {
		return false;
	}
	        
	//Remaining characters can be only . or a digit, but only one decimal.
	for (var i = 1; i < object_value.length; i++)
	{
		check_char = number_format.indexOf(object_value.charAt(i))
		if (check_char < 0) {
			return false;
		} else if (check_char == 1) {
			if (decimal) {		// Second decimal.
				return false;
			} else {
				decimal = true;
			}
		} else if (check_char == 0)	{
			if (decimal || digits) {
				trailing_blank = true;
			}
			// ignore leading blanks
		} else if (trailing_blank) {
			return false;
		} else {
			digits = true;
		}
	}	
	//All tests passed, so...
	return true
}

function IsNumberChar(ch)
{
	return (ch >= '0' && ch <= '9');
}

function IsAlphaChar(ch)
{
	return (ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z');
}

function IsAlphaNumeric(object_value)
{
	var i;
	var intLength, ch;
	intLength = object_value.length;
	
	for(i = 0; i < intLength; i++) 
	{
		ch = object_value.charAt(i);
		if(!(IsAlphaChar(ch) || IsNumberChar(ch))) {
			return false;
		}
	}
	return true;
}

function IsAlpha(object_value)
{
	var i;
	var intLength, ch;
	intLength = object_value.length;
	
	for(i = 0; i < intLength; i++) 
	{
		ch = object_value.charAt(i);
		if(!IsAlphaChar(ch)) {
			return false;
		}
	}
	return true;
}


function IsEmail(object_value, min_value)
{
	var i, ch, intAtCount, intDotPos, intLastDotPos;
	
	var strEmailChars = "_-@.~!#$%&*+\"'\r\n"

	var len = object_value.length;

	if (len < min_value) {
		return false;
	}
	
	intAtCount = 0;
	intDotPos = 0;
	for(i = 0; i < len; i++) {
		ch = object_value.charAt(i);
		
		if(!(	IsAlphaChar(ch) || 
				IsNumberChar(ch) ||
				strEmailChars.indexOf(ch) != -1) 
			) { 
				return false;
		} else {
			if(ch == '@') {
				intAtCount++;
				if(intAtCount > 1) {
					return false;
				}
			} else if (ch == '.') {
				// don't allow consecutive .'s
				if (i - 1 == intLastDotPos) {
					return false;
				}
				intDotPos = i;
				intLastDotPos = i;
			}
		}
	}
		
	return (intDotPos > 0 && intAtCount > 0 && intDotPos < (len - 1));

}

/**********************************************************************************/
function  IsEmailsList(objText, min_value)
    {	 var  k=0;
         var  strEmail;
         var  data = objText.value;
         var re;
		 	
			if(data) 
    		{  if(data.length > 0) 
			   { 
					data = Replace(data, " ", "");
					data = Replace(data, ";", ",");
					data = Replace(data, ",,", "");
					re = /"/gi; 						data = data.replace(re, "") ;
					re = new RegExp("\\r\\n", "gi");	data = data.replace(re, "") ;  
					re = new RegExp(",\\w*<", "gi");	data = data.replace(re, ",") ;  
					re = new RegExp(">\\w*", "gi");		data = data.replace(re, "") ; 
					re = new RegExp("<", "gi");			data = data.replace(re, "") ; 
					
					objText.value = data;

					while  (  (-1<data.indexOf(",",k)) && (data.indexOf(",",k)<data.length) )
					{	q = data.indexOf(",",k);
						strEmail = data.substring(k,q);  
						if ( (IsEmail(strEmail, min_value) == false)&&(strEmail!="") ) return false;
						k=q+1;
					}
					if (data.indexOf(",",k)==-1)
					{	strEmail = data.substring(k); 
						if ( (IsEmail(strEmail, min_value) == false)&&(strEmail!="") ) return false;
					}
			   }
			}
			if ((objText.value== ",") || (objText.value== "")) { return false;}
			return true;

	}

function  InvalidEmailInList(objText, min_value)
    {	 var  k=0;
         var  strEmail;
         var  data = objText.value;
         
		 	
			if(data) 
    		{  if(data.length > 0) 
			   { 
					data = Replace(data, " ", "");
					data = Replace(data, ";", ",");
					data = Replace(data, ",,", "");
					re = /"/gi; 						data = data.replace(re, "") ;
					re = new RegExp("\\r\\n", "gi");	data = data.replace(re, "") ;  
					re = new RegExp(",\\w*<", "gi");	data = data.replace(re, ",") ;  
					re = new RegExp(">\\w*", "gi");		data = data.replace(re, "") ; 
					re = new RegExp("<", "gi");			data = data.replace(re, "") ; 
					
					objText.value = data;

					while  (  (-1<data.indexOf(",",k)) && (data.indexOf(",",k)<data.length) )
					{	q = data.indexOf(",",k);
						strEmail = data.substring(k,q);  
						if ( (IsEmail(strEmail, min_value) == false)&&(strEmail!="") ) return strEmail;
						k=q+1;
					}
					if (data.indexOf(",",k)==-1)
					{	strEmail = data.substring(k); 
						if ( (IsEmail(strEmail, min_value) == false)&&(strEmail!="") ) return strEmail;
					}
			   }
			}
			return objText.value;

	}

function InLengthRangeEmails(objText, min_value, max_value)
    {	 var  k=0;
         var  strEmail;
         var  data = objText.value;
         
		 	
			if(data) 
    		{  if(data.length > 0) 
			   { 
					data = Replace(data, " ", "");
					data = Replace(data, ";", ",");
					data = Replace(data, ",,", "");
					re = /"/gi; 						data = data.replace(re, "") ;
					re = new RegExp("\\r\\n", "gi");	data = data.replace(re, "") ;  
					re = new RegExp(",\\w*<", "gi");	data = data.replace(re, ",") ;  
					re = new RegExp(">\\w*", "gi");		data = data.replace(re, "") ; 
					re = new RegExp("<", "gi");			data = data.replace(re, "") ; 
					
					objText.value = data;

					while  (  (-1<data.indexOf(",",k)) && (data.indexOf(",",k)<data.length) )
					{	q = data.indexOf(",",k);
						strEmail = data.substring(k,q); 
						if ( InLengthRange(strEmail, min_value, max_value) == false) return false;
						k=q+1;
					}
					if (data.indexOf(",",k)==-1)
					{	strEmail = data.substring(k);
						if ( InLengthRange(strEmail, min_value, max_value) == false) return false;
					}
			   }
			}
			return true;
			
    }
	
function ListContainsOnly(objText, object_value)
    {	 var  k=0; 
         var  strName;
         var  data = objText.value;
         
		 var  object_value =	Replace(object_value, " ", "");
		 
			if(data) 
    		{  if(data.length > 0) 
			   { 
					data = Replace(data, " ", "");
					data = Replace(data, ";", ",");
					data = Replace(data, ",,", "");
					re = /"/gi; 						data = data.replace(re, "") ;
					re = new RegExp("\\r\\n", "gi");	data = data.replace(re, "") ;  
					re = new RegExp(",\\w*<", "gi");	data = data.replace(re, ",") ;  
					re = new RegExp(">\\w*", "gi");		data = data.replace(re, "") ; 
					re = new RegExp("<", "gi");			data = data.replace(re, "") ; 
					
					while  (  (-1<data.indexOf(",",k)) && (data.indexOf(",",k)<data.length) )
					{	q = data.indexOf(",",k);
						strName = data.substring(k,q); 
						if ( (strName.toUpperCase()) != (object_value.toUpperCase())) return false;
						k=q+1;   
					}
					if (data.indexOf(",",k)==-1)
					{	strName = data.substring(k);
						if ( (strName.toUpperCase()) != (object_value.toUpperCase())) return false;
					}
					objText.value = data;
			   }
			}
			return true;
			
    }
	

function numberofEmails(objText, number_value)
    {	 var  k=0;
         var  isRepeatedEmail =false;
         var  data = objText.value;
         
		 	
			if(data) 
    		{  if(data.length > 0) 
			   { 
					data = Replace(data, " ", "");
					data = Replace(data, ";", ",");
					data = Replace(data, ",,", "");
					re = /"/gi; 						data = data.replace(re, "") ;
					re = new RegExp("\\r\\n", "gi");	data = data.replace(re, "") ;  
					re = new RegExp(",\\w*<", "gi");	data = data.replace(re, ",") ;  
					re = new RegExp(">\\w*", "gi");		data = data.replace(re, "") ; 
					re = new RegExp("<", "gi");			data = data.replace(re, "") ; 
					
					objText.value = data;

					var arraydata = objText.value.split(',');
	
					for (j=0; j< arraydata.length; j++){
						for (i=0; i< k; i++){
							if ( arraydata[k].toUpperCase() == arraydata[i].toUpperCase() ) 
							{ isRepeatedEmail=true;
							  break;
							}
							else
							{ isRepeatedEmail=false;
							}
						}
						if(  (arraydata[k] !="") && (!isRepeatedEmail)  )  k++;
					}
					if (k < number_value) return false; else return true;
				}
			}
			return false;
			
    }
	
/**********************************************************************************/

function IsURL(object_value)
{
	var i, ch, intDotCount;
	
	var strURLChars = "~!@#$%*_+-:/.?&="
	
	var len = object_value.length;
	
	if (object_value.length == 0) {
		return true;
	}
	
	if (object_value.length < 10) {
		return false;
	}
	
	if	((object_value.indexOf("http://") == -1) &&
			(object_value.indexOf("https://") == -1) &&
			(object_value.indexOf("ftp://") == -1)) {
		return false;
	}
	
	intDotCount = 0;
	for(i = 0; i < len; i++) {
		ch = object_value.charAt(i);
		
		if(!(	IsAlphaChar(ch) || 
				IsNumberChar(ch) ||
				strURLChars.indexOf(ch) != -1) 
			) {
				return false;
		} else if(ch == '.') {
			intDotCount++;
		} 
	}
	
	return (intDotCount > 0);
	
}

function IsValidExtension(object_value, extensions)
{
	// ---------------Examples----------------
	// extensions -->   "jpeg, gif, zip"
	// object_value --> "chat.zip"
	// ---------------------------------------

	var i, ch, intDotCount;
	var test_extension = "";
	var obj_extension = "";
	var len = object_value.length;

	if ((object_value == "") || (extensions == ""))
		return true;
		 
	// --------------------------------------------------
	// First get the extension of the object value
	// --------------------------------------------------
	for (i = len; i > 0; i--) {
		ch = object_value.charAt(i);
		if (ch == '.') {
			intDotCount = i;
			break;
		}
	}	
	
	for (i = (intDotCount + 1); i < len; i++) {
		obj_extension = obj_extension + object_value.charAt(i);
	}

	if (obj_extension.length == 0)
		return false;

	// --------------------------------------------------
	// Then, we compare that string to every extension we passed in
	// --------------------------------------------------

	extensions = extensions.toLowerCase();
	obj_extension = obj_extension.toLowerCase();

	len = extensions.length;
	test_extension = "";

	for (i = 0; i <= len; i++) {

		ch = extensions.charAt(i);

		if ((ch == ',') || (ch == ' ') || (i == len)) {
			if (test_extension.length == 0)
				continue;			
			if (test_extension == obj_extension)
				return true;
			test_extension = "";
		}
		else {
			test_extension = test_extension + ch;
		}
	}
	return false;
}

function LimitInput(field, countfield, maxlimit) 
{
	if (field.value.length > maxlimit) // if too long...trim it!
	{
		field.value = field.value.substring(0, maxlimit);
	}
	// otherwise, update 'characters left' counter
	else
	{
		if (countfield != null) 
			countfield.value = maxlimit - field.value.length;
	}
}
	
function IsCreditCard(object_value) {
  // Encoding only works on cards with less than 19 digits
  if (object_value.length > 19)
    return (false);

  sum = 0; mul = 1; l = object_value.length;
  for (i = 0; i < l; i++) {
    digit = object_value.substring(l - i - 1, l - i);
    tproduct = parseInt(digit ,10) * mul;
    if (tproduct >= 10)
      sum += (tproduct % 10) + 1;
    else
      sum += tproduct;
    if (mul == 1)
      mul++;
    else
      mul--;
  }

  if ((sum % 10) == 0)
    return (true);
  else
    return (false);

} // END FUNCTION isCreditCard()


function ModalBox(blnInterNational, strText)
{
 
		if (ie4up){	alert(unescape(strText));} 		else {		alert(unescape(strText));} 

}

function utf8Encode(str)
{	 
 	 str=new String(str);
	 if  (ie4up)
     {if (str.valueOf()=='null') {return "%20";}  else { return escape(str);	} 
	 }
	 else
     {if (str.valueOf()=='null') {return "%20";}  else { return escape(str);	} 
	 }
	 
}

function utf8Decode(str)
{
	if  (ie4up)
     {return unescape(str);
	 }
	 else
     {return unescape(str);
	 }
	 
}

/*
function Utf8DecodeTextarea(str)
{
	 
}
*/

function utf8DecodePicture(str)
{
   
     return escape(str);		  // i say escape and not unescape
	 
}

function utf8EncodeXML(str)
{	 
 	 str=new String(str);
	 if  (ie4up)
     {if (str.valueOf()=='null') {return escape("%20");}  else { return escape(escape(str));	} 
	 }
	 else
     {if (str.valueOf()=='null') {return escape("%20");}  else { return escape(escape(str));	} 
	 }
	 
}

function utf8EncodeX(str)
{	 
 	 str=new String(str);
	 if  (ie4up)
     {if (str.valueOf()=='null') {return escape("%20");}  else { return escape(escape(str));	} 
	 }
     {if (str.valueOf()=='null') {return escape("%20");}  else { return escape(escape(str));	} 
	 }
	 
}


function AsciivEncode(str)
{	   var i,vstr ;

	   vstr="";
	   if (str!="" ) 
	   {	for (i=0; i<str.length;i++)
			{	if ( str.charCodeAt(i)<0 ) 	{	vstr=vstr + "vd" + (65536+str.charCodeAt(i)) + "r";	}
				else						{	vstr=vstr + "vd" + str.charCodeAt(i) + "r";			}
			}
			return (vstr);
		}
		else
		{	return ("");
		}
}

function AsciiwEncode(str)
{	   var i,vstr ;

	   vstr="";
	   if (str!="" ) 
	   {	for (i=0; i<str.length;i++)
			{   if ( str.charCodeAt(i)<0 ) 	{	vstr=vstr + "&#" + (65536+str.charCodeAt(i)) + ";";	}
				else						{	vstr=vstr + "&#" + str.charCodeAt(i) + ";";			}
			}
			return (vstr);
		}
		else
		{	return ("");
		}
}

function AsciixEncode(str)
{	   var i,vstr ;

	   vstr="";
	   if (str!="" ) 
	   {	for (i=0; i<str.length;i++)
			{	if ( str.charCodeAt(i)<0 ) 	{	vstr=vstr +  (65536+str.charCodeAt(i)) + ";";	}
				else						{	vstr=vstr +  str.charCodeAt(i) + ";";			}
			}
			return (vstr);
		}
		else
		{	return ("");
		}
}

/*function AsciixDecode(str)
{  
	var vstr;
	var i=0;
	var j=0;
	var k=0;
	var s=new String("abc");
	var BeginTag	='';
	var EndTag		=';';
	var vstrs="";

	if (str!="")
	{
		do 
		{	vstr= str.substring( str.indexOf(BeginTag,j)+BeginTag.length, str.indexOf(EndTag,j) );
			if (vstr!='' && vstr!=null && str.indexOf(BeginTag,j)>=0 && str.indexOf(EndTag,j)>=0) 
			{if (vstr>=0 && vstr<=65536) vstrs=	vstrs+ s.fromCharCode(vstr);
			 i+=1;alert(vstr);
			}
			k= j;
			j=str.indexOf(EndTag,j)+ EndTag.length;
		}
		while (str.indexOf(EndTag,k)>=0);
		if (vstrs==""){ return str; } else { return vstrs;}
	}
	else return (""); 

}*/


/*****************************************************************************************************************/
/*****xml Dom parser for browser different than internet explorer: netscape, ...; also for internet explorer******/
/*****CopyRight: Klebair *****************************************************************************************/

function loadXML(doc )
{    return doc ;
}

function getNodes(XMLDoc, tag ) 
{   
	var i=0;
	var j=0;
	var k=0;
	var BeginTag	='<'+tag+'>';
	var EndTag		='</'+tag+'>';
	var Node;
	var Nodes= new Array();
	do 
	{
		Node= XMLDoc.substring( XMLDoc.indexOf(BeginTag,j)+BeginTag.length, XMLDoc.indexOf(EndTag,j) );
		if (Node!='' && Node!=null && XMLDoc.indexOf(BeginTag,j)>=0 && XMLDoc.indexOf(EndTag,j)>=0) 
		{Nodes[i]=Node;
		 i+=1;
		}
		k= j;
		j=XMLDoc.indexOf(EndTag,j)+ EndTag.length;
	}
	while (XMLDoc.indexOf(EndTag,k)>=0);
	return Nodes;
}

function NodesLength(Nodes)
{   return (Nodes.length);
}

function NodesItem(Nodes,x) 
{ 
  if ((x>=0) && (x<Nodes.length)){ return Nodes[x];} else  return null;
}

function ChildsItem(Childs,y) 
{ 
	var i=0;
	var j=0;
	var k=0;
	var ChildNode;
	do
	{
		tag			= Childs.substring( Childs.indexOf('<',j)+1,Childs.indexOf('>',j));
		BeginTag	='<'+tag+'>';
		EndTag		='</'+tag+'>';
		
		ChildNode= Childs.substring( Childs.indexOf(BeginTag,j)+BeginTag.length, Childs.indexOf(EndTag,j) );
		if (XMLDoc.indexOf(BeginTag,j)>=0 && XMLDoc.indexOf(EndTag,j)>=0)
		{if (i==y){ return ChildNode;};
		 i+=1;
		}
		k =j;
		j=Childs.indexOf(EndTag,j)+ EndTag.length;
	}
	while (Childs.indexOf(EndTag,k)>=0);
	return null;
}

function NodesChildItem(Nodes,x,y) 
{ 
	var i=0;
	var j=0;
	var k=0;
	var Node
	if ((x>=0) && (x<Nodes.length)){ Node=Nodes[x];}	else return null;
	var ChildNode;
	do
	{
		tag			= Node.substring( Node.indexOf('<',j)+1,Node.indexOf('>',j));
		BeginTag	='<'+tag+'>';
		EndTag		='</'+tag+'>';

		ChildNode= Node.substring( Node.indexOf(BeginTag,j)+BeginTag.length, Node.indexOf(EndTag,j) );
		if (Node.indexOf(BeginTag,j)>=0 && Node.indexOf(EndTag,j)>=0)
		{if (i==y){ return ChildNode;};
		 i+=1;
		}
		k =j;
		j=Node.indexOf(EndTag,j)+ EndTag.length;
	}
	while (Node.indexOf(EndTag,k)>=0);
	return null;
}


function synchronizeCHATREQUERY(XMLDoc, tag, chrono)
{		
		var n		= 	getNodes(XMLDoc,tag);
        var w		=	XMLDoc.substring(XMLDoc.indexOf('<'+tag+'>'),XMLDoc.indexOf('</'+tag+'>')+tag.length+3);
		var d 		= 	new Date();
  		var	t 		= 	d.getMilliseconds() ;

		if (n.length>0)
		{	if ((t-getLASTt(tag)) >= chrono)
			{ 	setLASTv(tag, t, w) ;
				return true;
			}
			else
			{	if ( getLASTw(tag) != w  )
				{ 	setLASTv(tag, t, w) ;
					return true;
				}
				else 
				{ 	setLASTv(tag, t, w) ;
					return false;
				}
			}
		}
		else
		{ 	setLASTv(tag, t, w);
			return false;
		}
		
}

function getLASTt(tag)
{
    if (tag=='nameasenter') 	{return LASTentringusersT;}
	else if (tag=='msg') 		{return LASTMsgT;}
	else if (tag=='offmsg') 	{return LASToffMsgT;}
	else if (tag=='nameasleft') {return LASTleavingusersT;}
	else return 0;
}

function getLASTw(tag)
{
	if (tag=='nameasenter') 	{return LASTentringusersXML;}
	else if (tag=='msg') 		{return LASTMsgXML;}
	else if (tag=='offmsg') 	{return LASToffMsgXML;}
	else if (tag=='nameasleft') {return LASTleavingusersXML;}
	else return '';
}

function setLASTv(tag, t, w)
{
	if (tag=='nameasenter') 	{LASTentringusersT=t; LASTentringusersXML=w;}
	else if (tag=='msg') 		{LASTMsgT=t			; LASTMsgXML=w;}
	else if (tag=='offmsg') 	{LASToffMsgT=t		; LASToffMsgXML=w;}
	else if (tag=='nameasleft') {LASTleavingusersT=t; LASTleavingusersXML=w;}
}


/*****************************************************************************************************************/

