$(document).ready(function() {
	/*$('input[@type=text]').focus(function(){
		var currentVal = $(this).val();										// Read initial field value
		$(this).val('');														// Clear initial value

		$(this).blur(function(){
			var getNewVal = $(this).val();										// Read new input value
			if ( getNewVal == '' || getNewVal == ' ' ) {
				$(this).val(currentVal);										// Switch to initial value
			}
		});
	});
*/
	var profiles = {
		window800: {
			height:800,
			width:800,
			status:1
		},

		window200: {
			height:200,
			width:200,
			status:1,
			resizable:0
		}
	};


   	$(function(){
   		$(".popupwindow").popupwindow();
   	});

	/* custom radio */
	$("span.radio.like").each(function(){
		$(this).click(function(){
			var likeArray = ['like_Buy','like_Sell','like_Both'];
			var clikedId = $(this).attr('id');
			var val = $(this).html();
			var getPosition = likeArray.indexOf(clikedId);

			// check clicked ID
			$(this).toggleClass('r_on');
			$('input#like2').val(val);

			// uncheck the others
			for ( var k = 0; k < likeArray.length; k++ ) {
				if ( k != getPosition ) {
					document.getElementById(likeArray[k]).setAttribute('class','radio like');
					document.getElementById(likeArray[k]).setAttribute('className','radio like');
				}
			}
		})
	});

	$("span.radio.publish").each(function(){
		$(this).click(function(){
			var likeArray = ['publish_Yes','publish_No'];
			var clikedId = $(this).attr('id');
			var val = $(this).html();
			var getPosition = likeArray.indexOf(clikedId);

			// check clicked ID
			$(this).toggleClass('r_on');
			$('input#publish').val(val);

			// uncheck the others
			for ( var k = 0; k < likeArray.length; k++ ) {
				if ( k != getPosition ) {
					document.getElementById(likeArray[k]).setAttribute('class','radio publish');
					document.getElementById(likeArray[k]).setAttribute('className','radio publish');
				}
			}
		})
	});

	$("span.radio.bulletin").each(function(){
		$(this).click(function(){
			var likeArray = ['bulletin_Yes','bulletin_No'];
			var clikedId = $(this).attr('id');
			var val = $(this).html();
			var getPosition = likeArray.indexOf(clikedId);

			// check clicked ID
			$(this).toggleClass('r_on');
			$('input#bulletin').val(val);

			// uncheck the others
			for ( var k = 0; k < likeArray.length; k++ ) {
				if ( k != getPosition ) {
					document.getElementById(likeArray[k]).setAttribute('class','radio bulletin');
					document.getElementById(likeArray[k]).setAttribute('className','radio bulletin');
				}
			}
		})
	});

	$("span.radio.terms").each(function(){
		$(this).click(function(){
			var likeArray = ['terms_Yes','terms_No'];
			var clikedId = $(this).attr('id');
			var val = $(this).html();
			var getPosition = likeArray.indexOf(clikedId);

			// check clicked ID
			$(this).toggleClass('r_on');
			$('input#terms').val(val);

			// uncheck the others
			for ( var k = 0; k < likeArray.length; k++ ) {
				if ( k != getPosition ) {
					document.getElementById(likeArray[k]).setAttribute('class','radio terms');
					document.getElementById(likeArray[k]).setAttribute('className','radio terms');
				}
			}
		})
	});

	$("span.radio.newsletter").click(function(){
		// check clicked ID
		$(this).toggleClass('r_on');
		if( $(this).attr('class').indexOf('r_on') > -1 )
			$('input#newsletter2').val('true');
		else
			$('input#newsletter2').val('false');	
	});

	$("img.ballon").hide();
});

if (!Array.prototype.indexOf)
{
  Array.prototype.indexOf = function(elt /*, from*/)
  {
    var len = this.length;

    var from = Number(arguments[1]) || 0;
    from = (from < 0)
         ? Math.ceil(from)
         : Math.floor(from);
    if (from < 0)
      from += len;

    for (; from < len; from++)
    {
      if (from in this &&
          this[from] === elt)
        return from;
    }
    return -1;
  };
}

Array.prototype.inArray = function (value)
// Returns true if the passed value is found in the
// array.  Returns false if it is not.
{
    var i;
    for (i=0; i < this.length; i++) {
        // Matches identical (===), not just similar (==).
        if (this[i] === value) {
            return true;
        }
    }
    return false;
};

var detect = navigator.userAgent.toLowerCase();
var os_ = navigator.platform.toLowerCase();
var browser,thestring;

if (checkIt('safari')) browser = "Safari"
else browser = "not Safari"

if ( os_ == 'macppc' || os_ == 'macintel' ) os = "Mac"
else os = "not Mac"

function checkIt(string)
{
	place = detect.indexOf(string) + 1;
	thestring = string;
	return place;
}

