
//BROWSER DETECTION
var ns4 = document.layers;
var ns6 = document.getElementById && !document.all;
var ie4 = document.all;
 
function DetectBrowser(){ //Detectarea browserului folosit
	this.ver=navigator.appVersion
	this.agent=navigator.userAgent
	this.dom=document.getElementById?1:0
	this.opera5=(navigator.userAgent.indexOf("Opera")>-1 && document.getElementById)?1:0
	this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom && !this.opera5)?1:0; 
	this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom && !this.opera5)?1:0;
	this.ie4=(document.all && !this.dom && !this.opera5)?1:0;
	this.ie=this.ie4||this.ie5||this.ie6
	this.mac=this.agent.indexOf("Mac")>-1
	this.ns6=(this.dom && parseInt(this.ver) >= 5) ?1:0; 
	this.ns4=(document.layers && !this.dom)?1:0;
	this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera5)
	return this
}
var bw=new DetectBrowser();

//FIELDS
function imgField(field, img){
	if(field.type == 'textarea'){
		if(img == "over") field.className='textarea1_over';
		else field.className='textarea1';
	}else if(field.type == 'text' || field.type == 'password'){
		if(img == "over") field.className='field1_over';
		else field.className='field1';
	}else{
		//bgcolor
		if(img == "over"){
			bgcolor = "#FFFFFF";
			border_color = "#999999";
		}else {
			bgcolor = "#F9F9F9";
			border_color = "#999999";
		}
		field.style.borderColor = border_color;
		field.style.backgroundColor = bgcolor;
	}
}

function imgField2(field, img){
	
	if(field.type == 'textarea'){
		if(img == "over") field.className='textarea1_over';
		else field.className='textarea1';
	}else if(field.type == 'text' || field.type == 'password' || field.type == 'file'){
		if(img == "over") field.className='field1_over';
		else field.className='field1';
	}else{
		//bgcolor
		if(img == "over") bgcolor = "#FDFDFD";
					 else bgcolor = "#F9F9F9";
		field.style.backgroundColor = bgcolor;
		
		//border color
		if(img == "over") border_color = "#575656";
					 else border_color = "#999999";
		field.style.borderColor = border_color;
	}		
}

//BUTS
function imgBut(but, img){
	but.src = img;
}


//Reset Form
function resetForm(formName){
	if(ns6) form = eval("document.getElementById('"+formName+"')");
	else if(ns4) form = eval("document."+formName);
	else form = eval("document.all."+formName);
	form.reset();
}



function focus2(field){
	if(field.value == 0) field.value = '';
}	


function blur2(field){
	if(field.value == '') field.value = '0';
}	


function fieldValue(field_name){
	if(ns6) field = eval("document.getElementById('"+field_name+"')");
	else if(ns4) field = eval("document."+field_name);
	else field = eval("document.all."+field_name);
	return field.value;
}

function setFieldValue(field_name, val){
	if(ns6) field = eval("document.getElementById('"+field_name+"')");
	else if(ns4) field = eval("document."+field_name);
	else field = eval("document.all."+field_name);
	return field.value;
	field.value = val;
}

function writeIn(field_name, val){
/*
	if(ns6) field = eval("document.getElementById('"+field_name+"')");
	else if(ns4) field = eval("document."+field_name);
	else field = eval("document.all."+field_name);
*/
	document.getElementById(field_name).innerHTML = val;
}



function formatNR(nr, dec)
{
str = "" + Math.round(eval(nr) * Math.pow(10,dec));
while(str.length < dec)
	str = "0" + str;
decidx = str.length - dec;
tmp = str.substring(0,decidx);
if(tmp == '')
	tmp = '0';
if(dec > 0)
	tmp = tmp + '.' + str.substring(decidx, str.length);
return(tmp);
}



function getkey(e)
{
if (window.event)
   return window.event.keyCode;
else if (e)
   return e.which;
else
   return null;
}


function goodchars(e, goods)
{
var key, keychar;
key = getkey(e);
if (key == null) return true;

// get character
keychar = String.fromCharCode(key);
keychar = keychar.toLowerCase();
goods = goods.toLowerCase();

// check goodkeys
if (goods.indexOf(keychar) != -1)
	return true;

// control keys
if ( key==null || key==0 || key==8 || key==9 || key==13 || key==27 )
   return true;

// else return false
return false;
}



function getSelectedRadio(buttonGroup) {
   // returns the array number of the selected radio button or -1 if no button is selected
   if (buttonGroup[0]) { // if the button group is an array (one button is not an array)
      for (var i=0; i<buttonGroup.length; i++) {
         if (buttonGroup[i].checked) {
            return i
         }
      }
   } else {
      if (buttonGroup.checked) { return 0; } // if the one button is checked, return zero
   }
   // if we get to this point, no radio button is selected
   return -1;
} // Ends the "getSelectedRadio" function

function getSelectedRadioValue(buttonGroup) {
   // returns the value of the selected radio button or "" if no button is selected
   var i = getSelectedRadio(buttonGroup);
   if (i == -1) {
      return "";
   } else {
      if (buttonGroup[i]) { // Make sure the button group is an array (not just one button)
         return buttonGroup[i].value;
      } else { // The button group is just the one button, and it is checked
         return buttonGroup.value;
      }
   }
} // Ends the "getSelectedRadioValue" function

function getSelectedCheckbox(buttonGroup) {
   // Go through all the check boxes. return an array of all the ones
   // that are selected (their position numbers). if no boxes were checked,
   // returned array will be empty (length will be zero)
   var retArr = new Array();
   var lastElement = 0;
   if (buttonGroup[0]) { // if the button group is an array (one check box is not an array)
      for (var i=0; i<buttonGroup.length; i++) {
         if (buttonGroup[i].checked) {
            retArr.length = lastElement;
            retArr[lastElement] = i;
            lastElement++;
         }
      }
   } else { // There is only one check box (it's not an array)
      if (buttonGroup.checked) { // if the one check box is checked
         retArr.length = lastElement;
         retArr[lastElement] = 0; // return zero as the only array value
      }
   }
   return retArr;
} // Ends the "getSelectedCheckbox" function

function getSelectedCheckboxValue(buttonGroup) {
   // return an array of values selected in the check box group. if no boxes
   // were checked, returned array will be empty (length will be zero)
   var retArr = new Array(); // set up empty array for the return values
   var selectedItems = getSelectedCheckbox(buttonGroup);
   if (selectedItems.length != 0) { // if there was something selected
      retArr.length = selectedItems.length;
      for (var i=0; i<selectedItems.length; i++) {
         if (buttonGroup[selectedItems[i]]) { // Make sure it's an array
            retArr[i] = buttonGroup[selectedItems[i]].value;
         } else { // It's not an array (there's just one check box and it's selected)
            retArr[i] = buttonGroup.value;// return that value
         }
      }
   }
   return retArr;
} // Ends the "getSelectedCheckBoxValue" function
  

//Email Validation
function emailValid(email)
{ 
  var result = false
  var theStr = new String(email)
  var index = theStr.indexOf("@");
  if (index > 0)
  {
    var pindex = theStr.indexOf(".",index);
    if ((pindex > index+1) && (theStr.length > pindex+1))
	result = true;
  }
  return result;
}

function formSubmit(form, act){
	document.forms[form].action = act;
	document.forms[form].submit();
}

function fieldOb(field_name){
	if(ns6) field = eval("document.getElementById('"+field_name+"')");
	else if(ns4) field = eval("document."+field_name);
	else field = eval("document.all."+field_name);
	return field;
}

function changeRowColor(row, color){
	rOb = fieldOb(row);
	rOb.bgColor = color;  
}

//Validates a field
function ValidateField(elem, name){
	if((elem.value == ''))	{ // ||(elem.value == 0)
    		alert('Warning: Not all mandatory fields (*) have been filled!');
    		elem.focus();
   	 		return(false);
   	}
	else if(name.indexOf('email') != -1 || name.indexOf('sEmail') != -1){ 
			 	if(!echeck(elem)){
				//	alert('Invalid E-mail address !');
					elem.focus();
   	 				return(false);
				}
	}
	return(true);
}

//Just Validates a field without (alert & focus)
function JustValidateField(elem){
	if((elem.value == '')||(elem.value == 0))	return(false);
	else if(name.indexOf('Email') != -1){
			 	if(!emailValid(elem.value)){
   	 				return(false);
				}
	}
	return(true);
}


//Validate form for Mandatory fields to be filled properly
function Validate(form, fields){ 
   	mandatory_fields = fields.split(',');
	for(i=0; i<mandatory_fields.length; i++){
		
		if(mandatory_fields[i].indexOf('|')){
			//groupped fields (at least one of them must be filled/selected)
			mandatory_group_fields = mandatory_fields[i].split('|');
			valid = 0;
			for(j=0; j<mandatory_group_fields.length; j++){
				elem = eval('form.' + mandatory_group_fields[j]);
				if(ValidateField(elem, mandatory_group_fields[j]) ) valid = 1;
				else return(false);
			}
			if(!valid){
				//no fields filled
				elem = eval('form.' + mandatory_group_fields[0]);
				if(!ValidateField(elem, mandatory_group_fields[0])) return(false);
			}
			
		}else{
			//single field
			elem = eval('form.' + mandatory_fields[i]);
			if(!ValidateField(elem, mandatory_fields[i])) return(false);
		}
		
	}//for
	return(true);
}

//Login Form Check
function checkLogin(form){
   	if(form.login_user.value == '')	{
    		alert('Insert Username');
    		form.login_user.focus();
   	 	return(false);
   	}
   	if(form.login_pass.value == '')	{
    		alert('Insert Password');
    		form.login_pass.focus();
   	 	return(false);
   	}
	return(true);
}

function checkFormPass(form){
   	if(form.pass_veche.value == '')	{
    		alert('Enter current password!');
    		form.pass_veche.focus();
   	 	return(false);
   	}
	
   	if(form.pass_noua_1.value == '')	{
    		alert('Enter new password!');
    		form.pass_noua_1.focus();
   	 	return(false);
   	}
	
   	if(form.pass_noua_2.value == '')	{
    		alert('Reenter new password!');
    		form.pass_noua_2.focus();
   	 	return(false);
   	}
	
   	if(form.pass_noua_1.value != form.pass_noua_2.value)	{
    		alert('Error! You have reentered a different new password!');
    		form.pass_noua_1.focus();
   	 	return(false);
   	}

	return(true);
}

function GotoPage(pag, GET){
	form = eval("document.forms['frms']");
	form.action = PHP_SELF + "?"+GET+"&pag="+pag;
	form.submit();
}


function SearchSite(){ 
	document.location = HTTP + 'search/' + unescape(document.forms['frm_search'].keyword.value);
}
function SearchSiteibook247(){ 
	document.location = HTTP + 'search/' + unescape(document.forms['frm_search'].keyword.value)+'/';
	
}


function showFilter(nr){
	if(document.getElementById('comboFilter'+nr).style.visibility == 'visible') closeFilter(nr);
	else{
		for(i=1; i<=5; i++) {
			if(i!=nr) closeFilter(i);
		}
		document.getElementById('comboFilter'+nr).style.visibility = 'visible';
		document.getElementById('bgFilter'+nr).style.background = 'url('+HTTP+'_layouts/images/site_header_click_09.jpg)';
	}
}

function selectFilterOption(nr, val, txt){
	document.getElementById('comboFilter'+nr).style.visibility = 'hidden';
	if(nr == 1) clicked1 = 0;
	else if(nr == 2) clicked2 = 0;
	else if(nr == 3) clicked3 = 0;
	else if(nr == 4) clicked4 = 0;
	else if(nr == 5) clicked5 = 0;
	writeIn('valFilter'+nr, txt);
	ob = eval("document.forms['form_search'].filter"+nr);
	ob.value = val;
	document.getElementById('bgFilter'+nr).style.background = 'url('+HTTP+'_layouts/images/site_header_09.jpg)';
}

function closeFilter(nr){
	document.getElementById('comboFilter'+nr).style.visibility = 'hidden';
	if(nr == 1) clicked1 = 0;
	else if(nr == 2) clicked2 = 0;
	else if(nr == 3) clicked3 = 0;
	else if(nr == 4) clicked4 = 0;
	else if(nr == 5) clicked5 = 0;
	document.getElementById('bgFilter'+nr).style.background = 'url('+HTTP+'_layouts/images/site_header_09.jpg)';
}

function closeFilters(){
	for(i=1; i<=5; i++) closeFilter(i);
}

function alignFilters(){
	posLeft = document.getElementById('xy').offsetLeft + 16;
	for(i=1; i<=5; i++){
		ob1 = fieldOb('comboFilter'+i);	
		ob1.style.left = posLeft + 'px';
	}
	
	obc = fieldOb('comboCurrency');	
	obc.style.left = (posLeft + 847) + 'px';
}

onresize = alignFilters;

function showCurrency(){
	if(document.getElementById('comboCurrency').style.visibility == 'hidden')
		document.getElementById('comboCurrency').style.visibility = 'visible';
	else document.getElementById('comboCurrency').style.visibility = 'hidden';	
}

function SearchHotels(){
	search_url = HTTP + 'hotels/';
	f1 = document.forms['form_search'].filter1.value;
	f2 = document.forms['form_search'].filter2.value;
	f3 = document.forms['form_search'].filter3.value;
	f4 = document.forms['form_search'].filter4.value;
	f5 = document.forms['form_search'].filter5.value;
	//f = getSelectedRadioValue(document.forms['form_search'].offer_type);
	//if(f!="" ) search_url += f + '/';
	
	if(f1 != '') search_url += 'destination_'+f1+'/';
	if(f2 != '') search_url += 'location_'+f2+'/';
	if(f3 != '') search_url += 'stars_'+f3+'/';
	if(f4 != '') search_url += 'price_'+f4+'/';
	if(f5 != '') search_url += 'type_'+f5+'/';
	
	document.location = search_url;
}



function SearchHotels2(){ 
	search_url = HTTP + 'hotels/';
	f1 = document.forms['form_search2'].filter1.value;
	f2 = document.forms['form_search2'].filter2.value;
	f3 = document.forms['form_search2'].filter3.value;
//	f4 = document.forms['form_search2'].filter4.value;
	f5 = document.forms['form_search2'].filter5.value;
	f6 = document.forms['form_search2'].filter6.value;
	s = document.forms['form_search2'].f_sort.value;
//	f = getSelectedRadioValue(document.forms['form_search2'].offer_type);
	//f = document.getElementById('specialoffer').value;
	//if(f!="" ) search_url += f + '/';
	//alert(search_url);
	
	if(f1 != '') search_url += 'destination_'+f1+'/';
	
	if(f2 != '') search_url += 'location_'+f2+'/';
	
	if(f3 != '') search_url += 'stars_'+f3+'/';

	
	if(f5 != '') search_url += 'type_'+f5+'/';

	if(f6 != '') search_url += 'country_'+f6+'/';

	if(s != 'hotel_name') search_url += 'sort_'+s+'/';

	document.location = search_url;
}



function ListHotelwithTopBreadCrumbs(bread){ 
	search_url = HTTP + 'hotels/';
	f1 = document.forms['form_search2'].filter1.value;
	f2 = document.forms['form_search2'].filter2.value;
	f3 = document.forms['form_search2'].filter3.value;
//	f4 = document.forms['form_search2'].filter4.value;
	f5 = document.forms['form_search2'].filter5.value;
//	f6 = document.forms['form_search2'].filter6.value;
	s = document.forms['form_search2'].f_sort.value;
//	f = getSelectedRadioValue(document.forms['form_search2'].offer_type);
//	f = document.getElementById('specialoffer').value;
//	if(f!="" ) search_url += f + '/';

	if(f1 != '') search_url += 'destination_'+f1+'/';
	if(f2 != '') search_url += 'location_'+f2+'/';
	if(f3 != '') search_url += 'stars_'+f3+'/';
//	if(f4 != '') search_url += 'price_'+f4+'/';
	if(f5 != '') search_url += 'type_'+f5+'/';
//	if(f6 != '') search_url += 'country_'+f6+'/';
	if(s != 'hotel_name') search_url += 'sort_'+s+'/';
	if(bread != '') search_url += bread+'/';
	
	
	document.location = search_url;
}



function SearchHotelsHomePage(){ 
	search_url = HTTP + 'hotels/';
	f1 = document.forms['form_search2'].filter1.value;
	f2 = document.forms['form_search2'].filter2.value;
	f3 = document.forms['form_search2'].filter3.value;
//	f4 = document.forms['form_search2'].filter4.value;
	f5 = document.forms['form_search2'].filter5.value;
//	f6 = document.forms['form_search2'].filter6.value;
	s = document.forms['form_search2'].f_sort.value;
//	f = getSelectedRadioValue(document.forms['form_search2'].offer_type);
//	f = document.getElementById('specialoffer').value;
//	if(f!="" ) search_url += f + '/';

	if(f1 != '') search_url += 'destination_'+f1+'/';
	if(f2 != '') search_url += 'location_'+f2+'/';
	if(f3 != '') search_url += 'stars_'+f3+'/';
//	if(f4 != '') search_url += 'price_'+f4+'/';
	if(f5 != '') search_url += 'type_'+f5+'/';
//	if(f6 != '') search_url += 'country_'+f6+'/';
	if(s != 'hotel_name') search_url += 'sort_'+s+'/';
	
	document.location = search_url;
}

function SearchHotels2ForCountry(){ 
	search_url = HTTP + 'hotels/';
	f6 = document.forms['form_search2'].filter6.value;
	s = document.forms['form_search2'].f_sort.value;
//	f = getSelectedRadioValue(document.forms['form_search2'].offer_type);
	


	if(f6 != '') search_url += 'country_'+f6+'/';
	if(s != 'hotel_name') search_url += 'sort_'+s+'/';
	
	document.location = search_url;
}

function clearFilterValue(){
	 document.forms['form_search2'].filter2.value='';
	 document.forms['form_search2'].filter3.value='';
	// document.forms['form_search2'].filter4.value='';
	 document.forms['form_search2'].filter5.value='';
	document.forms['form_search2'].f_sort.value='';
	
}


function Action(actionlink){
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null){
	  alert ("Please install the newest version for your browser!");
	  return;
	} 
	
	var url = "?" + actionlink + "&height=" + document.body.offsetHeight;
	url=url+"&sid="+Math.random();
	//alert(url);
	xmlHttp.onreadystatechange=getDiv;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
} 

function GetXmlHttpObject(){
	var xmlHttp=null;
	try { xmlHttp=new XMLHttpRequest(); }
	catch (e) {
	  try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); }
	  catch (e) { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); }
	}
	return xmlHttp;
}

function getDiv(){
	if (xmlHttp.readyState==4){
		response=xmlHttp.responseText;	
		
		var update = new Array();
		update = response.split('|ajaxresponse|');

		if(update[0] == 'combo_locations'){
			writeIn('filter2_options', update[1]);
			selectFilterOption(2, '', '...');
		}else if(update[0] == 'combo_locations2'){
			writeIn('f2_options', update[1]);
		}
	}
}


function getLocations(dest_id){
	writeIn('filter2_options', '');
	selectFilterOption(2, '', '<img src="'+HTTP+'_layouts/images/ajax_loader_3.gif" border="0" height="12" width="12">');
	Action("get_locations=" + dest_id);
}

function getLocations2(dest_id){
	writeIn('f2_options', '<img src="'+HTTP+'_layouts/images/ajax_loader_3.gif" border="0" height="12" width="12">');
	Action("get_locations2=" + dest_id);
}


function showHideTable(tb_name){
	ob = fieldOb(tb_name);	
	if(ob.className == '') ob.className = 'ascuns';
	else ob.className = ''; 
}

function BookHotel(id, ref){
	if(ref == 0) popup(HTTP+'book_hotel/'+id+'/', 940, 700, 'yes');
	else popup(HTTP+'book_hotel/'+id+'/refresh/', 940, 700, 'yes');
}

function HotelMap(id){ 
	popup(HTTP+'hotelmap/'+id+'/', 900, 700, 'yes');
}

function CompareHotels(){
	popup(HTTP+'comparehotels/', 900, 700, 'yes');
}

function PrintVoucher(id){
	popup(HTTP+'printvoucher/'+id+'/', 810, 700, 'yes');
}

function ViewAllPeriod(id){
	popup(HTTP+'viewallperiod/'+id+'/', 1200, 400, 'yes');
}

function BookingSummary(id){
	popup(HTTP+'bookingsummary/'+id+'/', 940, 700, 'yes');
}

function PayDeposit(id){
//	popup(HTTP+'paydeposit/'+id+'/', 970, 700, 'yes');
window.location.href=HTTP+'paydeposit/'+id+'/';
}

function PayDepositTour(id){
//	popup(HTTP+'paydeposit/'+id+'/', 970, 700, 'yes');
window.location.href=HTTP+'paydeposit_tour/'+id+'/';
}

function PayFastTrackDirect(id){
//	popup(HTTP+'payfasttrackdirect/'+id+'/', 970, 700, 'yes');
window.location.href=HTTP+'payfasttrackdirect/'+id+'/';
}

function PayBallance(id){
//	popup(HTTP+'paybalance/'+id+'/', 970, 700, 'yes');
	window.location.href=HTTP+'paybalance/'+id+'/';
}

function PayBallanceTour(id){
//	popup(HTTP+'paybalance/'+id+'/', 970, 700, 'yes');
	window.location.href=HTTP+'paybalance_tour/'+id+'/';
}

function EditBookingHotelMain(id, ref){
	
	 popup(HTTP+'editbookingmain/'+id+'/refresh/', 940, 700, 'yes');
}

function CheckEmailAvail(div){
	email = document.MyForm3.email.value;
	name = document.MyForm3.name.value;
    //alert("http://"+location.host+"/ajax_check_email_avialability.php?email="+email+"&name="+name);
	makeRequest("http://"+location.host+"/ajax_check_email_avialability.php?email="+email+"&name="+name,div);
}
function SubmitFormVal(div){
	
	if(Validate(document.MyForm3, 'name,email,phone,country,address'))
	if(document.getElementById(div).innerHTML!=""){
		alert('Error: Your email already exists in our system. Please login or use another email address...');	
	}else{
		document.MyForm3.submit();	
	}
}

  function login(showhide){
    if(showhide == "show"){ 
        document.getElementById('popupbox').style.display = "block"; /* If the function is called with the variable 'show', show the login box */
    }else if(showhide == "hide"){
        document.getElementById('popupbox').style.display="none"; /* If the function is called with the variable 'hide', hide the login box */
    }
  }



// Validate email address

/** (6)
	*  This method is used to checked 
	*  for the validity of the Email 
	*/
	function echeck(str) {
		emailStr = str.value;
		/* The following variable tells the rest of the function whether or not
		to verify that the address ends in a two-letter country or well-known
		TLD.  1 means check it, 0 means don't. */
		var checkTLD=1;
		/* The following is the list of known TLDs that an e-mail address must end with. */
		var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
		/* The following pattern is used to check if the entered e-mail address
		fits the user@domain format.  It also is used to separate the username
		from the domain. */
		var emailPat=/^(.+)@(.+)$/;
		/* The following string represents the pattern for matching all special
		characters.  We don't want to allow special characters in the address. 
		These characters include ( ) < > @ , ; : \ " . [ ] */
		var specialChars="\\(\\)><@,;:'\\\\\\\"\\.\\[\\]";
		/* The following string represents the range of characters allowed in a 
		username or domainname.  It really states which chars aren't allowed.*/
		var validChars="\[^\\s" + specialChars + "\]";
		/* The following pattern applies if the "user" is a quoted string (in
		which case, there are no rules about which characters are allowed
		and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
		is a legal e-mail address. */
		var quotedUser="(\"[^\"]*\")";
		/* The following pattern applies for domains that are IP addresses,
		rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
		e-mail address. NOTE: The square brackets are required. */
		var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
		/* The following string represents an atom (basically a series of non-special characters.) */
		var atom=validChars + '+';
		/* The following string represents one word in the typical username.
		For example, in john.doe@somewhere.com, john and doe are words.
		Basically, a word is either an atom or quoted string. */
		var word="(" + atom + "|" + quotedUser + ")";
		// The following pattern describes the structure of the user
		var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
		/* The following pattern describes the structure of a normal symbolic
		domain, as opposed to ipDomainPat, shown above. */
		var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
		/* Finally, let's start trying to figure out if the supplied address is valid. */
		/* Begin with the coarse pattern to simply break up user@domain into
		different pieces that are easy to analyze. */
		var matchArray=emailStr.match(emailPat);
		if (matchArray==null) {
			/* Too many/few @'s or something; basically, this address doesn't
			even fit the general mould of a valid e-mail address. */
			alert("Your email address is not correct ");
			str.select();
			str.focus();
			return false;
		}
		var user=matchArray[1];
		var domain=matchArray[2];
		// Start by checking that only basic ASCII characters are in the strings (0-127).
		for (i=0; i<user.length; i++) {
			if (user.charCodeAt(i)>127) {
				alert("Ths username contains invalid characters.");
				str.select();
				str.focus();
				return false;
			}
		}
		for (i=0; i<domain.length; i++) {
			if (domain.charCodeAt(i)>127) {
				alert("Ths domain name contains invalid characters.");
				str.select();
				str.focus();
				return false;
			}
		}
		// See if "user" is valid 
		if (user.match(userPat)==null) {
			// user is not valid
			alert("The username doesn't seem to be valid.");
			str.select();
			str.focus();
			return false;
		}
		/* if the e-mail address is at an IP address (as opposed to a symbolic
		host name) make sure the IP address is valid. */
		var IPArray=domain.match(ipDomainPat);
		if (IPArray!=null) {
			// this is an IP address
			for (var i=1;i<=4;i++) {
				if (IPArray[i]>255) {
					alert("Destination IP address is invalid!");
					str.select();
					str.focus();
					return false;
				}
			}
			return true;
		}
		// Domain is symbolic name.  Check if it's valid.
		var atomPat=new RegExp("^" + atom + "$");
		var domArr=domain.split(".");
		var len=domArr.length;
		for (i=0;i<len;i++) {
			if (domArr[i].search(atomPat)==-1) {
				alert("The domain name does not seem to be valid.");
				str.select();
				str.focus();
				return false;
			}
		}
		/* domain name seems valid, but now make sure that it ends in a
		known top-level domain (like com, edu, gov) or a two-letter word,
		representing country (uk, nl), and that there's a hostname preceding 
		the domain or country. */
		if (checkTLD && domArr[domArr.length-1].length!=2 && 
		domArr[domArr.length-1].search(knownDomsPat)==-1) {
			alert("The address must end in a well-known domain or two letter " + "country.");
			str.select();
			str.focus();
			return false;
		}
		// Make sure there's a host name preceding the domain.
		if (len<2) {
			alert("This address is missing a hostname!");
			str.select();
			str.focus();
			return false;
		}
		// If we've gotten this far, everything's valid!
		return true;
	}
	
	
	
	function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
