function confirm_del() {
  var reply = confirm("This will permanantly delete this record! You can't restore it in future.");

  if (reply) {
     return true;
  } else {
     return false;
  }
}


function popUpImg(url, pageWidth, pageHeight) {
    var args = "width=" + (pageWidth + 20) + ",height=" + (pageHeight + 10) + "";
    var date = new Date();
    var now = date.getTime();
    var name = (now).toString(10);

    _w = window.open('',name,args);
    _w.document.open();
    _w.document.write("<html>\n<head><title>Viewing " + url + "</title>\n");
    _w.document.write("<meta http-equiv='imagetoolbar' content='no'>\n");
    _w.document.write("<link href='screen_a.css' type='text/css' rel='stylesheet'  media='screen' />\n");
    _w.document.write("<script language='javascript'><!--\n");
    _w.document.write("var i=0;\n");
    _w.document.write("function resize() {\n");
    _w.document.write("if (navigator.appName == 'Netscape') i=40;\n");
    _w.document.write("if (document.images[0]) window.resizeTo(document.images[0].width +30, document.images[0].height+100-i);\n");
    _w.document.write("self.focus();\n");
    _w.document.write("}\n");
    _w.document.write("//--></script></head>\n");
    _w.document.write("<body onload='resize();'>\n");
    _w.document.write("<table width='100%' border='0' cellpadding='0' cellspacing='0' style='height: 100%'>\n");
    _w.document.write("<tr><td><a href='javascript:window.close()' class='popup'>Close window</a></td></tr>\n");
    _w.document.write("<tr>\n<td align='center' valign='middle'>\n");
    _w.document.write("<a href='javascript:window.close()'><img src='" + url + "' alt='Click to close' border='0' /></a>\n");
    _w.document.write("</td></tr></table>\n");
    _w.document.write("</body>\n</html>");
    _w.document.close();
}

function popUpMap(address, pageWidth, pageHeight) {
    var args = "width=" + (pageWidth + 20) + ",height=" + (pageHeight + 10) + "";
    var date = new Date();
    var now = date.getTime();
    var name = (now).toString(10);


    _w = window.open('',name,args);

    _w.document.open();
    _w.document.write("<html>\n<head><title>Show on the Google Map</title>\n");
    _w.document.write("<meta http-equiv='imagetoolbar' content='no'>\n");
    _w.document.write("<link href='screen_a.css' type='text/css' rel='stylesheet'  media='screen' />\n");
    _w.document.write("<script src='http://maps.google.com/maps?file=api&amp;v=2.x&amp;key=ABQIAAAAsElOHl5qZ-IjI0IFiaRQZRT-9xDPnygmUGx_Q9HxpCkbH81BQhRuzVBzWSBU8zJtDhkf8inGv55vTw' type='text/javascript'></script>\n");    
    _w.document.write("<script language='javascript'><!--\n");    
    _w.document.write("var map = null;\n");        
    _w.document.write("var geocoder = null;\n");        
    _w.document.write("function initialize() {\n");        
    _w.document.write("if (GBrowserIsCompatible()) {\n");        
   _w.document.write(" map = new GMap2(document.getElementById('map_canvas'));\n");        
_w.document.write("var mapControl = new GMapTypeControl();\n");        
_w.document.write("map.addControl(mapControl);\n");        
_w.document.write("map.addControl(new GLargeMapControl());\n");        


_w.document.write("        map.setCenter(new GLatLng(37.4419, -122.1419), 13);\n");        
_w.document.write("        geocoder = new GClientGeocoder();    }    }\n");        

_w.document.write("    function showAddress(address) {\n");        
_w.document.write("      if (geocoder) {\n");        
_w.document.write("        geocoder.getLatLng(\n");        
_w.document.write("          address,\n");        
_w.document.write("          function(point) {\n");        
_w.document.write("            if (!point) {\n");        
_w.document.write("              alert(address + ' not found');\n");        
_w.document.write("            } else {\n");        
_w.document.write("              map.setCenter(point, 13);\n");        
_w.document.write("              var marker = new GMarker(point);\n");        
_w.document.write("              map.addOverlay(marker);\n");        
_w.document.write("              marker.openInfoWindowHtml(address);\n");        
_w.document.write("            }       }      );     }    }\n");        


    _w.document.write("//--></script></head>\n");
    

  _w.document.write("<body onload=\"initialize();showAddress('"+address+"');\">\n");
     _w.document.write("<div id='map_canvas' style='width: 500px; height: 300px'></div>\n");
    _w.document.write("</body>\n</html>");
    _w.document.close();
}



opera = (navigator.userAgent.indexOf('Opera') >= 0)? true : false;
ie = (document.all && !opera)? true : false;
dom = (document.getElementById && !ie && !opera)? true : false;

var expiration = new Date();
expiration.setTime(expiration.getTime() + 3600*3600*3600);


function popUpMap2(address){

document.getElementById('gmap').style.marginLeft = Math.floor(document.body.clientWidth/2)-300+'px';
document.getElementById('gmap').style.marginTop = (document.documentElement.scrollTop+(screen.height/2)-300)+'px';
document.getElementById('gbox-overlay').style.width = (document.body.clientWidth+20)+'px';
document.getElementById('gbox-overlay').style.height = screen.height+'px';
document.getElementById('gbox-overlay').style.marginLeft = '-'+(Math.floor(document.body.clientWidth/2)-298)+'px';
document.getElementById('gbox-overlay').style.marginTop = '-'+((screen.height/2)-300)+'px';
document.getElementById('gmap').style.display = 'block';
document.getElementById('map_iframe').src=address;    
document.body.style.overflow='hidden';
    
}

function doPreview(param1, param2) {

  if (dom) {
    var src = document.getElementById(param1).value;
  } else if (ie) {
    var src = document.all[param1].value;
  }

  if (src.charAt(1)==":") src = "file:/" + src;

  if (dom) {
    document.getElementById(param2).src=src;
  } else if (ie) {
    document.all[param2].src = src;
  }

}


function doPreview1(param1, param2) {

  if (dom) {
    document.getElementById(param2).src=param1;
  } else if (ie) {
    document.all[param2].src = param1;
  }

}


function showtranscript(elemId,displayValue) {
    if (dom || opera) {
        if (displayValue) {
            if (document.getElementById(elemId)) {
                document.getElementById(elemId).style.display = displayValue;
            }
            return 0;
        }

        if (document.getElementById(elemId).style.display == "none") {
            document.getElementById(elemId).style.display = "block";
        } else if (document.getElementById(elemId).style.display == "block") {
            document.getElementById(elemId).style.display = "none";
        }

    } else if (ie) {
        if (displayValue) {
            if (document.all[elemId]) {
                document.all[elemId].style.display =  displayValue;
            }
            return 0;
        }

        if (document.all[elemId].style.display == "block") {
            document.all[elemId].style.display = "none";
        } else if (document.all[elemId].style.display == "none") {
            document.all[elemId].style.display = "block";
        }

    }
}

function display(cookie_name, id) {
    var template_category_cookie;

    template_category_cookie = GetCookie(cookie_name);

    if (template_category_cookie) {
        SetCookie(cookie_name, "1", expiration, "", "","")
        showtranscript(id, 'block');
    } else {
        SetCookie(cookie_name, "", expiration, "", "","")
        showtranscript(id, 'none');
    }

    return true;
}


function onCookieChange(cookie_name, id) {

    if (dom || opera) {

        if (document.getElementById(id).style.display == "none") {
            SetCookie(cookie_name, "", expiration, "", "","")
        } else if (document.getElementById(id).style.display == "block") {
            SetCookie(cookie_name, "1", expiration, "", "","")
        }

    } else if (ie) {
        if (document.all[id].style.display == "block") {
            SetCookie(cookie_name, "1", expiration, "", "","")
        } else if (document.all[id].style.display == "none") {
            SetCookie(cookie_name, "", expiration, "", "","")
        }
    }
}


function SetCookie(name, value, expires, path, domain, secure) {
    var mycookie = name + "=" + escape(value);
    var myexpires = new Date();
    myexpires.setTime(myexpires.getTime() + 5000);
    mycookie = mycookie + "; myexpires=" + myexpires.toGMTString() + "; path=" + '/';
    document.cookie = mycookie;
}


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 getCookieVal (offset) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1) endstr = document.cookie.length;
   return unescape(document.cookie.substring(offset, endstr));
}

function top_search_type_change(ref_spa_type) {
if(document.getElementById('location').value == "City, State, Zip Code ..." || document.getElementById('location').value == "City, State, Country" || document.getElementById('location').value == ""){  
  if (ref_spa_type == 2){
      document.getElementById('location').value = "City, State, Country";
  }else{
      document.getElementById('location').value = "City, State, Zip Code ...";      
  }
}
}


function check_review_form(frm) {
   var prefix0 = 'get_';
   var input_array = new Array('title','review');
   var error_array = new Array('Title','Review');
   if(!document.getElementById('visit_again_1').checked && !document.getElementById('visit_again_2').checked){
     alert("Please check 'I would visit this spa again?'");  
     return false;
   }
   
   for (var i=0; i<input_array.length; i++) {
      var source = prefix0+input_array[i];          
      if (frm.elements[source].value.length == 0) {
         alert('Please enter '+error_array[i]);
         frm.elements[source].focus();
         return false;
      }
   }
   xajax_review_submit(xajax.getFormValues('review_form'));


   
   return true;
}


function validEmail_(email) {
  invalidChars = " /:,;";
  if (email == "") {
    return false;
  }
  for (i=0; i<invalidChars.length;i++) {
    badChar = invalidChars.charAt(i);
    if (email.indexOf(badChar,0) > -1) {
      return false;
    }
  }
  atPos = email.indexOf("@",1);
  if (atPos == -1) {
    return false;
  }
  if (email.indexOf("@",atPos+1) > -1) {
    return false;
  }
  periodPos = email.indexOf(".",atPos);
  if (periodPos == -1) {
    return false;
  }
  if (periodPos+3 > email.length) {
    return false;
  }
  return true;
}

function check_supplier_form(frm, ref_item) {
   var prefix0 = 'get_';
   var input_array = new Array('name','email','phone','subject','message');
   var error_array = new Array('Contact Name','E-Mail Address','Phone Number','Subject','Message');

   
   for (var i=0; i<input_array.length; i++) {
      var source = prefix0+input_array[i];          
      if (frm.elements[source].value.length == 0) {
         alert('Please enter '+error_array[i]);
         frm.elements[source].focus();
         return false;
      }
   }

   if(!validEmail_(frm.elements['get_email'].value)){
     alert("Please enter valid E-mail Address!");  
     return false;
   }
   xajax_email_inquiry_submit(xajax.getFormValues('email_inquiry_form'), ref_item, 1);
   
   return true;
}

function check_supplier_form_2(frm, ref_item) {
   var prefix0 = 'get_';
   var input_array = new Array('name','email');
   var error_array = new Array('Contact Name','E-Mail Address');

   
   for (var i=0; i<input_array.length; i++) {
      var source = prefix0+input_array[i];          
      if (frm.elements[source].value.length == 0) {
         alert('Please enter '+error_array[i]);
         frm.elements[source].focus();
         return false;
      }
   }

   if(!validEmail_(frm.elements['get_email'].value)){
     alert("Please enter valid E-mail Address!");  
     return false;
   }
   xajax_email_inquiry_submit(xajax.getFormValues('email_inquiry_form'), ref_item, 2);
   
   return true;
}


function check_contact_form(frm) {
   var prefix0 = 'get_';
   var input_array = new Array('name','email','subject','message');
   var error_array = new Array('Your Name','E-mail','Email Subject','Message');

   
   for (var i=0; i<input_array.length; i++) {
      var source = prefix0+input_array[i];          
      if (frm.elements[source].value.length == 0) {
         alert('Please enter '+error_array[i]);
         frm.elements[source].focus();
         return false;
      }
   }

   
   if(!validEmail_(frm.elements['get_email'].value)){
     alert("Please enter valid E-mail!");  
     return false;
   }

   return true;
}


function check_top_search(frm) {

   if(frm.elements['get_treatment'].value == "" || frm.elements['get_treatment'].value == "Spa Type, Service, Treatment ..."){ 
     alert("A find is required, for example \"Massage\".");
     frm.elements['get_treatment'].focus();   
     return false;
   }  

   
   if(frm.elements['get_location'].value == "" || frm.elements['get_location'].value == "City, State, Zip Code ..."){ 
       alert("A location is required, for example \"New York, NY\".");
       frm.elements['get_location'].focus();   
       return false;
   }  
   
   return true;
}

function check_statistics_form(frm) {
   var prefix0 = 'get_';
   var input_array = new Array('from_date','to_date');
   var error_array = new Array('Date From', 'Date To');

   for (var i=0; i<input_array.length; i++) {
      var source = prefix0+input_array[i];          
      if (frm.elements[source].value.length == 0) {
         alert('Please enter '+error_array[i]);
         frm.elements[source].focus();
         return false;
      }
   }
   
   atPos = frm.elements['get_from_date'].value.indexOf("/",1);
   if (atPos == -1) {
    alert('Please enter valid date format in Date From');   
    return false;
   }

   atPos = frm.elements['get_to_date'].value.indexOf("/",1);
   if (atPos == -1) {
    alert('Please enter valid date format in Date To');   
    return false;
   }
   
if(frm.elements['get_ref_item'].value != ''){
  val = parseInt(frm.elements['get_ref_item'].value);
  if (isNaN(val)){
      alert('Please enter valid Spa Listing ID');  
      return false;
  }
 
  if (val != frm.elements['get_ref_item'].value){
      alert('Please enter valid Spa Listing ID');  
      return false;
  }
 
  if (val <= 0){
      alert('Please enter valid Spa Listing ID');  
      return false;
  }
}

   return true;
}

function check_tell_friends_form(frm) {
   var prefix0 = 'get_';
   var input_array = new Array('from_name','from','friend_name','to', 'subject', 'message');
   var error_array = new Array('Your Name','Your Email','Friend\'s Name','Friend\'s Email', 'Subject', 'Message');

   for (var i=0; i<input_array.length; i++) {
      var source = prefix0+input_array[i];          
      if (frm.elements[source].value.length == 0) {
         alert('Please enter '+error_array[i]);
         frm.elements[source].focus();
         return false;
      }
   }

   if(!validEmail_(frm.elements['get_to'].value)){
     alert("Please enter valid Friend\'s Email!");  
     frm.elements['get_to'].focus();     
     return false;
   }
   xajax_tel_freand_submit(xajax.getFormValues('tell_friends'));
   
   return true;
}


function check_article_email_form(frm) {
   var prefix0 = 'get_';
   var input_array = new Array('to_name','to_email','message','from_name', 'from_email');
   var error_array = new Array('Recipient\'s Name','Recipient\'s Email','Message','Your Name', 'Your Email');

   for (var i=0; i<input_array.length; i++) {
      var source = prefix0+input_array[i];          
      if (frm.elements[source].value.length == 0) {
         alert('Please enter '+error_array[i]);
         frm.elements[source].focus();
         return false;
      }
   }

   if(!validEmail_(frm.elements['get_to_email'].value)){
     alert("Please enter valid Recipient\'s Email!");  
     frm.elements['get_to_email'].focus();     
     return false;
   }
   xajax_article_email_submit(xajax.getFormValues('article_email'));
   
   return true;
}
