
function OpenWindow(name){
	w1 = window.open(name, "popup", "resizable=yes,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,copyhistory=0,width=645,height=520");
	w1.moveTo(0,0);window.defaultStatus='';w1.focus();
}


function AddToFavorites(){
	  if ((navigator.appVersion.indexOf("MSIE") > 0) && (parseInt(navigator.appVersion) >= 4)) {
	    window.external.AddFavorite('http://www.easyBG.com', 'easyBG - Properties in Bulgaria (UK)');
	  }
}


function OpenMapWindow(name, w, h){
	generate=window.open("", "map", "resizable=no,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,copyhistory=0,width=224,height=180");
	generate.moveTo(0,0);window.defaultStatus=''
	generate.document.open("text/html","replace");
	map_name = '../images/maps/' + name.substr(0,2) + '-map-template-new-full.gif';
	generate.document.write("<HTML><HEAD><TITLE>easyBG.com - Map Location of " + name + "</TITLE></HEAD><BODY onBlur=\"window.close();\" bgcolor=\"#cccccc\"><table width=\"224\" height=\"150\" cellspacing=\"0\" cellpadding=\"0\" border=\"1\"><tr><td align=\"left\" valign=\"top\" background=\"" + map_name + "\"><a href=\"javascript:window.close();\"><img alt=\"Click to Close\" src=\"../_dot.gif\" width=\"" + w + "\" height=\"" + h + "\" border=\"0\"><img src=\"../images/maps/marker1.gif\" width=\"9\" height=\"9\" border=\"0\" alt=\"Here\"></a></td></tr></table><center><font face=arial size=1><b>Location of " + name + "</body></html>");
	generate.document.close();
	generate.self.focus();
}


function OpenImageWindow(name,w,h){
	if (w == null) {w=535; h=403}
	generate=window.open("", "image", "resizable=no,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,copyhistory=0,width="+w+",height="+h+"");
	generate.moveTo(0,0);window.defaultStatus=''
	generate.document.open("text/html","replace");
	generate.document.write("<HTML><HEAD><TITLE>www.easyBG.com</TITLE></HEAD>");
	generate.document.write("<BODY onBlur=window.close(); bgcolor=#ffffff leftmargin=0 topmargin=0 marginheight=0 marginwidth=0><a href=javascript:window.close()><img src=");
	generate.document.write(name);
	generate.document.write(" width="+w+" height="+h+" border=0></a></body></html>");
	generate.document.close();
	generate.self.focus();
}


function OpenImageWindowMap(name){
	generate=window.open("", "image", "resizable=no,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,copyhistory=0,width=517,height=574");
	generate.moveTo(0,0);window.defaultStatus=''
	generate.document.open("text/html","replace");
	generate.document.write("<HTML><HEAD><TITLE>www.easyBG.com</TITLE></HEAD>");
	generate.document.write("<BODY onBlur=window.close(); bgcolor=#ffffff leftmargin=0 topmargin=0 marginheight=0 marginwidth=0><a href=javascript:window.close()><img src=");
	generate.document.write(name);
	generate.document.write(" width=517 height=574 border=0></a></html>");
	generate.document.close();
	generate.self.focus();
}


function VerifyEmailAddress(checkStr) {
	var Reason  = "Your Email Address appears incorrect.  \n\nPlease check. \n\nReason:"
	var Success = "Email Address entered Correctly!"
//	var checkStr = document.ContactForm.email.value;
	var ix = (checkStr.length - 4)
	var RC = true;
	var x = AtSignValid = DoublePeriod = PeriodValid = SpaceValid = ExtValid = RL = 0;

	  for (i = 0;  i < checkStr.length;  i++) {
    	if (checkStr.charAt(i) == '@')
	      AtSignValid++;
    	else if (checkStr.charAt(i) == '.')
	    {
    	  if (x == (i-1))
        	DoublePeriod++;
	      else
    	  {
        	x = i;
	        PeriodValid++;
    	  }
	    }
    	else if (checkStr.charAt(i) == ' ')
	      SpaceValid ++;
	  }

	  if (checkStr.indexOf(".com", ix) > -1)
	    ExtValid++;
	  else if (checkStr.indexOf(".edu", ix) > -1)
	    ExtValid++;
	  else if (checkStr.indexOf(".net", ix) > -1)
	    ExtValid++;
	  else if (checkStr.indexOf(".org", ix) > -1)
	    ExtValid++;
	  else if (checkStr.indexOf(".gov", ix) > -1)
	    ExtValid++;
	  else if (checkStr.indexOf(".mil", ix) > -1)
	    ExtValid++;
	  else if (checkStr.indexOf(".cc", ix) > -1)
	    ExtValid++;
	  RL = Reason.length;
	  if (AtSignValid != 1)
	    Reason += "\nOnly one '@' allowed, " + AtSignValid + " found.";
	  if (PeriodValid == 0)
	    Reason += "\nAddress must contain at least one period.";
	  if (SpaceValid > 0)
	    Reason += "\nNo Spaces allowed. Address contains " + SpaceValid + " space";
	  if (SpaceValid > 1)
	    Reason += "s.";
	  if (checkStr.length > 120)
	    Reason += "\nPlease limit the Email Address to 120 characters.";

	  if (RL != Reason.length)
	  {
	 alert(Reason);
 	 document.ContactForm.email.focus();
	 return false;
	  }
	  return true;
}


function everything(){
	var TimeVisited = new Date();
	document.ContactForm.realname.value = document.ContactForm.First_Name.value + ' ' + document.ContactForm.Last_Name.value;
	document.ContactForm.Time_GMT.value = TimeVisited.toGMTString();
	document.ContactForm.Zip.value = document.ContactForm.Zip.value.toUpperCase();
	if (document.ContactForm.First_Name.value == '') {alert('Please fill out all required fields\nmarked with asterisks.\n\nFirst name empty'); document.ContactForm.First_Name.focus(); return false}
	if (document.ContactForm.Last_Name.value == '') {alert('Please fill out all required fields\nmarked with asterisks.\n\nLast name empty'); document.ContactForm.Last_Name.focus(); return false}
	if (document.ContactForm.Address.value == '') {alert('Please fill out all required fields\nmarked with asterisks.\n\nStreet address empty'); document.ContactForm.Address.focus(); return false}
	if (document.ContactForm.City.value == '') {alert('Please fill out all required fields\nmarked with asterisks.\n\nCity empty'); document.ContactForm.City.focus(); return false}
	if (document.ContactForm.Zip.value == '') {alert('Please fill out all required fields\nmarked with asterisks.\n\nZIP/POSTAL CODE Code empty'); document.ContactForm.Zip.focus(); return false}
	if (document.ContactForm.Country.value == '') {alert('Please fill out all required fields\nmarked with asterisks.\n\nCountry empty'); document.ContactForm.Country.focus(); return false}
	if ( (document.ContactForm.Country.value == 'U.S.A.' || document.ContactForm.Country.value == 'Canada') && document.ContactForm.State.value == '') {alert('Please fill out all required fields\nmarked with asterisks.\n\nState empty'); document.ContactForm.State.focus(); return false}
	if (document.ContactForm.Country.value == 'U.S.A.' && document.ContactForm.State.value == '') {alert('Please fill out all required fields\nmarked with asterisks.\n\nState empty'); document.ContactForm.State.focus(); return false}
	if (document.ContactForm.Country.value == 'U.S.A.' && document.ContactForm.State.value == 'Outside US and Canada') {alert('Please fill out all required fields\nmarked with asterisks.\n\nState empty'); document.ContactForm.State.focus(); return false}
	if (document.ContactForm.email.value == '') {alert('Please fill out all required fields\nmarked with asterisks.\n\nEmail address empty'); document.ContactForm.email.focus(); return false}
	var valid=VerifyEmailAddress(document.ContactForm.email.value);
	if (!valid) {document.ContactForm.email.focus();return false;}
	if (document.ContactForm.subject.value == '') {alert('Please fill out all required fields\nmarked with asterisks.\n\nSelect Subject'); document.ContactForm.subject.focus(); return false}
	if (document.ContactForm.source.value == '') {alert('Please fill out all required fields\nmarked with asterisks.\n\nHelp us to improve our service\nTell us how did you found us'); document.ContactForm.source.focus(); return false}
	if (document.ContactForm.source.value == 'other' && document.ContactForm.other.value == '') {alert('Please help us to improve our service\nTell us how did you found us'); document.ContactForm.other.focus(); return false}
	if (document.ContactForm.Inquiry.value == '') {alert('Please fill out all required fields\nmarked with asterisks.\n\nEnter your inquiry'); document.ContactForm.Inquiry.focus(); return false}
	return true;
}

			
var Included=new Array(120);


function set_included() {
	var content = GetCookie('EasyBGProperties');
	if (content == null) {
		for (var i in Included) {
			Included[i]="";
		}
	} else {
		var arg = "|";
		var alen = arg.length;
		var clen = content.length;
		var i = 0;
		var count = 0;
		while (i < clen) {
			var pos = content.indexOf(arg, i);
			var pro = content.substring(i,pos);
			Included[count] = pro;
			count = count + 1;
			i = content.indexOf(arg, pos) + 1;
			if (i == 0)
				break;
		}
	}
}


set_included();

pathname = location.pathname;
var largeExpDate = new Date ();
largeExpDate.setTime(largeExpDate.getTime() + (180 * 24 * 3600 * 1000));


function getCookieVal (offset) {
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1)

		endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}


function GetCookie (name) {
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) {
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg)
			return getCookieVal (j);

		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0)
			break;
	}
	return null;
}


function SetCookie (name, value) {
	var argv = SetCookie.arguments;
	var argc = SetCookie.arguments.length;
	var expires = (argc > 2) ? argv[2] : null;
	var path = (argc > 3) ? argv[3] : null;
	var domain = (argc > 4) ? argv[4] : null;
	var secure = (argc > 5) ? argv[5] : false;
	var path = "/";
	document.cookie = name + "=" + escape (value) +
		((expires == null) ? "" : ("; expires=" +
		expires.toGMTString())) +
		((path == null) ? "" : ("; path=" + path)) +
		((domain == null) ? "" : ("; domain=" + domain)) +
		((secure == true) ? "; secure" : "");
}


function AddProperty(name) {
	content = GetCookie('EasyBGProperties');
	incontent = content;
	if (content != null && content.indexOf(name)>=0){
		alert('Property Ref.ID: '+name+' has already been\nincluded in your personalised properties information pack');
		return false;
	}
	if (content != null) {
		content += name+'|';
	} else {
		content = name + '|';
	}
	SetCookie('EasyBGProperties',content,largeExpDate);
	content = GetCookie('EasyBGProperties');
	if (content != null && content.indexOf(name)>=0){
		alert('Property '+name+' will be included\nin your e-mailed personalised FREE\nproperty information pack');
		if (incontent == null) {
			self.location.href = self.location.href;
		}
		if (document.all) {
			document.all['cart'+name].innerHTML='<small><b><font color=#ffffff>UNCHECK THIS BOX TO REMOVE FROM \"MY PROPERTIES\" FOLDER</small>';
		}
		return true;
	} else {
		alert('Sorry, we can not include this property\nRef.ID: '+name+'\nin your personalised properties information pack\n\nCookies disabled!\n\nTurn your browser cookies ON and\nreload/refresh this page');
		return false;
	}
}


function RemoveProperty(name) {
	content = GetCookie('EasyBGProperties');
	if (content.indexOf(name)>=0){
		if (confirm('Are you sure you want to remove\nproperty '+name+' from your\npersonalised FREE property\ninformation pack?')) {
			set_included();
			var newContent;
			newContent = "";
			for (var i in Included) {
				if (Included[i] != name) 
					newContent = newContent + Included[i] + "|";
			}
			SetCookie('EasyBGProperties',newContent,largeExpDate);
			incontent = GetCookie('EasyBGProperties');
			if (incontent == null) {
				self.location.href=self.location.href;
			}
			if (document.all) {
				document.all['cart'+name].innerHTML='<small><b><font color=#ffffff>CHECK THIS BOX TO ADD TO \"MY PROPERTIES\" FOLDER</small>';
			}
			return true;
		} else {
			return false;
		}
	}
}


