function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function checkedDate(count){
    var cnt = parseInt(count);
    if (isNaN(cnt)) {
        cnt = ''
    } else {
        cnt = '_' + cnt;
    }

    var a = document.getElementById('check_date' + cnt);

    var color = "#d2caa1";
    var background = "#cccccc";
    var disable = true;
    var cursor = 'none';

    if(a.checked){
       color = "#ada166";
       background = "white";
       disable = false;
       cursor = 'pointer';
    }
    try {
        document.getElementById('begin_date_btn' + cnt).disabled = disable;
        document.getElementById('end_date_btn' + cnt).disabled = disable;
        document.getElementById('begin_date_inp' + cnt).disabled = disable;
        document.getElementById('end_date_inp' + cnt).disabled = disable;
        document.getElementById('calendar_date_block_begin' + cnt).style.color=color;
        document.getElementById('calendar_date_block_end' + cnt).style.color=color;
        document.getElementById('begin_date_inp' + cnt).style.backgroundColor = background;
        document.getElementById('end_date_inp' + cnt).style.backgroundColor = background;
        document.getElementById('begin_date_btn' + cnt).style.cursor = cursor;
        document.getElementById('end_date_btn' + cnt).style.cursor = cursor;
    } catch (e) {}
}

function checkFormSearch(count){
    var cnt = parseInt(count);
    if (isNaN(cnt)) {
        cnt = ''
    } else {
        cnt = '_' + cnt;
    }

    var a = document.getElementById('check_date'+ cnt);
    if(a.checked){
        var end_date = document.getElementById('end_date_inp'+ cnt);
        var begin_date = document.getElementById('begin_date_inp'+ cnt);
        if( ! (DateFormat(begin_date) && DateFormat(end_date))) {
            alert('Please specify the arrival/departure dates or uncheck availability selection');
            return false;
         }
    }
    return true;
}

function DateFormat(date){
    var reFormat = /[0-9]{2}\/[0-9]{2}\/[0-9]{4}/;
    return reFormat.test(date.value);
}

function synchroDate(date, count){
    var cnt = parseInt(count);
    if (isNaN(cnt)) {
        cnt = ''
    } else {
        cnt = '_' + cnt;
    }

    if(DateFormat(date)){
        var dname = date.name;

        if(dname.indexOf("begin_date") == 0){
            var date_end = document.getElementById('end_date_inp' + cnt);
            date_end.value = date.value;
        }
        var a = document.getElementById('check_date' + cnt);
        a.checked = true;
        checkedDate(count);
    }
}


function isCheckboxLocation(field) {
    if(field.tagName.toLowerCase() == 'input' && field.type.toLowerCase() == 'checkbox' && field.name == 'saylocation[]'){
        return true;
    }
    return false;
}

function checkedLocation(ym){
    check_ym = ym.checked;

    var form = ym.form;

    for (var i = 0; i < form.elements.length; i++) {
        var chbox = form.elements[i];
        if(isCheckboxLocation(chbox)){
           chbox.checked = check_ym;
       }
    }
}

function loadHomes(){
/*    var params = '';
    var url = 'map_upload.php';

    var popup_name = 'map_upload';
    var ajax = new Ajax.Request(url, {
        onSuccess: function(request) {
            try {
                //alert(request.responseText);
                eval(request.responseText);
            }
            catch (e) {
              alert(e);
            }
        }
    }
    );*/




}


function loadRealestateItems(){

    var params = '';
    var url = 'map_realestate_upload.php';

    var popup_name = 'map_realestate_upload';
    var ajax = new Ajax.Request(url, {
        onSuccess: function(request) {
            try {
                //alert(request.responseText.length);
            eval(request.responseText);
            }
            catch (e) {
              alert(e);
            }
        }
    }
    );
}


function viewBigPhoto(photo, width, height){
    block_big = document.getElementById('homephoto_big');
    reFilename = /\/([^\/]+)$/i;
    var bigsrc   = photo.src.replace(reFilename, "/big/$1");
    var supersrc = photo.src.replace(reFilename, "/super/$1");

    if(bigsrc != ''){
        var block_bigInnerHTML = '<a href="#" onclick="viewSuperPhoto(\''
            + supersrc + '\', \'' + width + '\', \'' + height
            +'\'); return false;">'
            + '<img src="' + bigsrc + '"></a><div class="enlarge"><a href="#" '
            + ' onclick="viewSuperPhoto(\''
            + supersrc + '\', \'' + width + '\', \'' + height
            + '\'); return false;"><img src="/img/slideshow-icon.gif" '
            + ' alt="" border="0"></a><a href="#" onclick="viewSuperPhoto(\''
            + supersrc + '\', \'' + width + '\', \'' + height
            + '\'); return false;">Begin Slideshow</a></div>';
        $(block_big).update(block_bigInnerHTML);
        if (Prototype.Browser.IE) {
            block_big.focus()
        } else {
            $(block_big).scrollTo();
            window.scrollBy(0, -10);
        }
    }

}

var popupWindow = null;

function popup(wName, url, width, height, options)
{
    var iLeft = ( screen.availWidth  - width ) / 2 ;
    var iTop  = ( screen.availHeight - height ) / 2 ;

    var sOptions = {};
    if (options) {
        sOptions.toolbar = options.toolbar || 'no';
        sOptions.status  = options.status || 'no';
        sOptions.resizable = options.resizable || 'no';
        sOptions.dependent = options.dependent || 'yes';
        sOptions.scrollbars = options.scrollbars || 'no';
    }

    sOptions.width  = width;
    sOptions.height = height;
    sOptions.left   = iLeft;
    sOptions.top    = iTop;

    var wOptions = '';
    for (var x in sOptions) {
        if (wOptions != '') {
            wOptions += ',';
        }
        wOptions += x + '=' + sOptions[x];
    }

    var isOpera = !!window.opera;

    try {
        if (popupWindow) {
            popupWindow.close();
        }
    }
    catch(e){/* Handle opera bug */}

    var popupBlocker = "The resources browser could not be opened." +
                        " Make sure that" +
                        " all popup blockers are disabled.";

    var isMSIE = /*@cc_on!@*/false;
    if ( isMSIE ) {
        // The following change has been made otherwise IE will open the file
        // browser on a different server session (on some cases):
        // http://support.microsoft.com/default.aspx?scid=kb;en-us;831678
        // by Simone Chiaretta.
        popupWindow = window.open(url, wName, wOptions) ;

        if ( popupWindow ) {
            // Detect Yahoo popup blocker.
            try {
                var sTest = popupWindow.name ; // Yahoo returns "something",
                // but we can't access it, so detect that and avoid strange errors for the user.
                popupWindow.opener = window ;
            } catch(e) {
                alert(popupBlocker) ;
            }
        } else {
            alert(popupBlocker) ;
        }
    } else {
            popupWindow = window.open(url, wName, wOptions);
    }

    if (!popupWindow) {
        alert(popupBlocker) ;
    }
}

function detectPopupBlocker() {
    var test = window.open("about:blank","","directories=no,height=100,width=100,menubar=no,resizable=no,scrollbars=no,status=no,titlebar=no,top=5000,location=no");     if(test) { // not blocked
        test.close();
        return true;
     } else { // blocked
        // show help dialog for disabling popups
        return false;
     }
}

function viewSuperPhoto(image_href, width, height){
    reFilename = /^http:\/\/([^\/]+)?\/photos\/(.+)$/i;
    var bigsrc = image_href.replace(reFilename, "$2");
    if(bigsrc != ''){
        var iWidth = parseInt(width);
        if (isNaN(iWidth)) {
            iWidth = 300;
        } else {
            iWidth = iWidth + 50 ;
        }

        var iHeight = parseInt(height);
        if (isNaN(iHeight)) {
            iHeight = 300;
        } else {
            iHeight = iHeight + 100 ;
        }

        if (screen.availWidth < iWidth + 20 ) {
            iWidth = screen.availWidth - 20;
        }

        if (screen.availHeight < iHeight + 20 ) {
            iWidth = screen.availHeight - 20;
        }

        iWidth  = iWidth  < 250 ? 250 : iWidth;
        iHeight = iHeight < 250 ? 250 : iHeight;

        popup('viewSuperPhoto', '/view_img.php?f=' + bigsrc, iWidth, iHeight, {'scrollbars':'yes'});
    }
    return false;
}

function checkDateFormat(date){
    var name_date;
    var reFormat = /[0-9]{2}\/[0-9]{2}\/[0-9]{4}/;
    if(!reFormat.test(date.value)){
        return false;
    }else return true;
}

function synchroDate2(date){
try{
    if(checkDateFormat(date)){
        var dname = date.name;
        if(dname.indexOf("date_begin") == 0){
            var date_end = document.getElementById('date_end_inp');
            date_end.value = date.value;
        }
    }
}catch(e){
    alert(e.message);
}
}

function checkEmail2(email){
    var re=/^([\-_a-zA-Z0-9.]+@[\-_a-zA-Z0-9]+(\.[\-_a-zA-Z0-9]+)+){1}$/i;
    if (email.value == "" || !re.test(email.value)){
        alert( " E-mail address format is invalid!" );
        email.focus();
        return false;
    }else return true;
}

function checkFormEvents(form){
    var re_occurring = document.getElementById('re_occurring');
    if(form.name.value == ''){
        alert('Event Name should not be empty!');
        form.name.focus();
        return false;
    }

    if (form.region.value == 0) {
        alert('You should select a region!');
        form.region.focus();
        return false;
    }

    if(!checkDateFormat(form.date_begin)){
        alert('Format Event Date is invalid!');
        form.date_begin.focus();
        return false;
    }
    if(re_occurring.checked && !checkDateFormat(form.date_end)){
        alert('Format Final Date is invalid!');
        form.date_end.focus();
        return false;
    }

    if(!checkEmail2(form.email))
    	return false;
    
    if( typeof( form.event_type ) != 'undefined' )
    {
    	var status = false;
    	for( var i = 0; i < 19; i++ )
    		if( form.event_type[ i ].checked )
    		{
    			status = true;
    			break;
    		}
    
    	if( !status )
    	{
    		alert('Please select Event Type');
    		return false;
    	}
    }

    return true;

}

function visibleEventFdate(re_occurring){
    try{
    var event_fdate_th = document.getElementById('event_fdate_th');
    var event_fdate_td = document.getElementById('event_fdate_td');
    if(re_occurring.checked){
        event_fdate_th.style.display = "block";
        event_fdate_td.style.display = "block";
    }else{
        event_fdate_th.style.display = "none";
        event_fdate_td.style.display = "none";
    }
    }catch(e){
        alert(e.message);
    }
}

function checkFormClassifieds(form){
    if(form.item.value == ''){
        alert('Item should not be empty!');
        form.item.focus();
        return false;
    }

    if(form.category_id.value == 0){
        alert('Choose the category!');
        form.item.focus();
        return false;
    }

    if(!checkEmail2(form.email)) return false;

    return true;

}

function checkFormBusiness(form){
    if(form.email.value != '' && !checkEmail2(form.email)) return false;
    if(form.name.value == ''){
        alert('Name should not be empty!');
        form.name.focus();
        return false;
    }
    if(form.email.value == '' && form.phone.value == ''){
        alert('One of the two fields Email or Phone must be filled in!');
        form.email.focus();
        return false;
    }
    if(form.comments.value == ''){
        alert('Comments should not be empty!');
        form.comments.focus();
        return false;
    }
    if(form.imagecode.value == ''){
        alert('Number Verification should not be empty!');
        form.imagecode.focus();
        return false;
    }
    return true;
}

function checkFormBusinessContact(form){
    if(form.email.value != '' && !checkEmail2(form.email)) return false;
    if(form.contact_name.value == ''){
        alert('Contact Name should not be empty!');
        form.contact_name.focus();
        return false;
    }
    /*if(form.email.value == ''){
        alert('Email Address must be filled in!');
        form.email.focus();
        return false;
    }*/
    if(form.comments.value == ''){
        alert('Additional Comments should not be empty!');
        form.comments.focus();
        return false;
    }

    return true;
}

var fmCommentClear = false;

function checkFormReservation(form){
try{
    if(form.fmEmail.value == ''){
        alert('Email should not be empty!');
        form.fmEmail.focus();
        return false;
    }
    if(form.fmEmail.value != '' && !checkEmail2(form.fmEmail)) return false;
    if(form.imagecode.value == ''){
        alert('Number Verification should not be empty!');
        form.imagecode.focus();
        return false;
    }
    if(!fmCommentClear) {
        form.fmComments.value = '';
    }

    return true;
}catch(e){
    alert(e.message);
}
}

function clearFmComments(textarea) {
    if(!fmCommentClear) {
        textarea.value = '';
        textarea.style.color = 'black';
        fmCommentClear = true;
    }
}


function clearValueSearch(item, mode){
    if(mode) {
        item.value = '';
        item.className = 'gsn_request';
    }else{
        if(item.value != ''){
            item.className = 'gsn_request';
        }
    }
}

function loadBusinesses(){
    var params = '';
    var url = 'map_bus_upload.php';

    var popup_name = 'map_bus_upload';
    var ajax = new Ajax.Request(url, {
        onSuccess: function(request) {
            try {
               //alert(request.responseText);
                eval(request.responseText);
            }
            catch (e) {
              //alert(e+'!!'+request.responseText);
            }
        }
    }
    );
}

