
// form validation
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}
//-->




// Open Pop-Up Window
function openWindow(theURL,winName,features) {
	window.open(theURL,winName,features);
}

// Set Form Function

function CV_setForm() {
  
	var doc = document.forms['search'];
	var price_min = doc.price_min.value; 
  
	if (price_min=="") {
	doc.price_max.value = '';
	return;
	}
  
	if (price_min=="0") {
  	doc.price_max.value = '15';
	}
  
	if (price_min=="15") {
	doc.price_max.value= '30';
	}
  
	if (price_min=="30") {
	doc.price_max.value = '50';
	}
  
	if (price_min=="50") {
	doc.price_max.value = '100';
	}
  
	if (price_min=="100") {
	doc.price_max.value = '';
	} 

}

// Get current domain
var thisDomain = "";
thisDomain = document.domain;

//<![CDATA[
function bookmark(anchor){
   if(window.external)
   {
       window.external.AddFavorite(anchor.getAttribute('href'), anchor.getAttribute('title'));
       return false;
   }
   return true;
}
//]]>


// Browser Detect

var detect = navigator.userAgent.toLowerCase();
var OS,browser,version,total,thestring;

if (checkIt('konqueror'))
{
        browser = "Konqueror";
        OS = "Linux";
}
else if (checkIt('safari')) browser = "Safari"
else if (checkIt('omniweb')) browser = "OmniWeb"
else if (checkIt('opera')) browser = "Opera"
else if (checkIt('webtv')) browser = "WebTV";
else if (checkIt('icab')) browser = "iCab"
else if (checkIt('msie')) browser = "Internet Explorer"
else if (!checkIt('compatible'))
{
        browser = "Netscape Navigator"
        version = detect.charAt(8);
}
else browser = "An unknown browser";

if (!version) version = detect.charAt(place + thestring.length);

if (!OS)
{
        if (checkIt('linux')) OS = "Linux";
        else if (checkIt('x11')) OS = "Unix";
        else if (checkIt('mac')) OS = "Mac"
        else if (checkIt('win')) OS = "Windows"
        else OS = "an unknown operating system";
}

function checkIt(string)
{
        place = detect.indexOf(string) + 1;
        thestring = string;
        return place;
}

/***********************************************
* Bookmark site script-  Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/


	
function bookmarkPage(title, url){
	if (document.all)
	window.external.AddFavorite(url, title);
	else if (window.sidebar)
	window.sidebar.addPanel(title, url, "");
}




function swapImage (img) {
var target = document.getElementById('largePhoto');
target.src = '/cms_media/images/200x200_fitbox-' + img;
}

// Pop Up Window
var currentImage = "";
var newwindow;
function popuppic(pic){
	if(currentImage != ''){
		newwindow=window.open('/cms_media/images/400x400_fitbox-' + currentImage,'name','height=400,width=400, scrollbars=yes, toolbar=no, menubar=no, resizable=yes');
	}else{
		newwindow=window.open('/cms_media/images/400x400_fitbox-' + pic,'name','height=400,width=400, scrollbars=yes, toolbar=no, menubar=no, resizable=yes');
	}
	if (window.focus){
		newwindow.focus();
	}
}

function updatepic(image){
	currentImage = image;
	var largePhoto = document.getElementById('largePhoto');
	var enlargeLink = document.getElementById('enlarge');
	largePhoto.src = '/cms_media/images/200x200_fitbox-' + image;
	enlargeLink.href = '/cms_media/images/400x400_fitbox-' + image;
}
