String.prototype.replaceAll=function(find, replace_to){
    return this.replace(new RegExp(find, "g"), replace_to)};

function I(a){
	if (document.getElementById) {
               return document.getElementById(a);
         } else if (document.all){
               return document.all[a];
         } else if (document.layers){
               return document.layers[a];
         }
}

function add038(str) {
	return str.replaceAll('&','##038');
}

function ShowOrHide(d1) {
         if (d1 != '') DoDiv(d1);
       }
       function DoDiv(id) {
         var item = null;
         if (document.getElementById) {
               item = document.getElementById(id);
         } else if (document.all){
               item = document.all[id];
         } else if (document.layers){
               item = document.layers[id];
         }
         if (!item) {
         }
         else if (item.style) {
               if (item.style.display == "none"){ item.style.display = ""; }
               else {item.style.display = "none"; }
         }else{ item.visibility = "show"; }
        }

function AjaxWorkOn(){
I('ajaxwork').style.display='';
I('sendbutton').style.display='none';
}

function AjaxWorkOff(){
I('ajaxwork').style.display='none';
I('sendbutton').style.display='';
}

function checkForm(obj, elems) {	
var element, pattern;	
    for (var i = 0; i < obj.elements.length; i++) { 	
        element = obj.elements[i];	
        if (elems != undefined)	
            if (elems.join().indexOf(element.type) < 0) continue;	
	
        if (!element.getAttribute("check_message")) continue;	
        if (pattern = element.getAttribute("check_pattern")) { 	
            pattern = new RegExp(pattern, "g");	
            if (!pattern.test(element.value)) {	
                alert(element.getAttribute("check_message"));	
                element.focus();	
                return false;	
            }	
        } else if(/^\s*$/.test(element.value)) { 
            alert(element.getAttribute("check_message"));	
            element.focus();	
            return false;	
        }	
    }	
return true;	
}

function getAjax(){
if (window.ActiveXObject)
   return new ActiveXObject("Microsoft.XMLHTTP");
else if (window.XMLHttpRequest) 
   return new XMLHttpRequest();
else {
   alert("Browser does not support AJAX.");
   return null;
  }
}

function updatecode(){
I('captcha').src = 'securimage/securimage_show.php?' + Math.random();
I('captcha_code').value = '';
AjaxWorkOff();
}

function opt(elem){
	if (I(elem).className == 'option e1')
		{ I(elem).className = 'option e0'; I(elem).target="0"; }
		else
		{ I(elem).className = 'option e1'; I(elem).target="1"; }
}

function showPhoto(elem) {
popupWin = window.open(elem.href, elem.id, 'location,width=640,height=480,scrollbars=yes,resizable=yes,status=no,top=0');
popupWin.focus();
}

function codeAddressCity() {
	codeAddress(I('statename').value+', '+I('city').value);
}

function toInt(val) {
	if (val) {return '1';} else {return '0';}
}

function getStateName(id){
ajax=getAjax();
var param;
if (ajax != null) {
   ajax.open("GET","includes/functions.php?action=getstatename&id="+id,true);
   ajax.onreadystatechange = function(){
     if(ajax.readyState==4 && ajax.status==200) {

          I('statename').value=ajax.responseText;
	  codeAddressCity();
   }}
   ajax.send(null);  

}
}

var ajax=null;

