////////////////////////  open window function  ////////////////////////
// opens new window and centers it on the screen, 
// returns true if window opens, returns false if window is bloked
function openWin(winURL, winName, winWidth, winHeight, statusBar, scrollBars)
{
	var topVal = Math.floor(screen.height/2 - winHeight/2);
	var leftVal = Math.floor(screen.width/2 - winWidth/2);
	var winPopup = window.open(winURL,winName.replace(/ /g),'width='+winWidth+',height='+winHeight+',location=no,menubar=no,status='+statusBar+',toolbar=no,scrollbars='+scrollBars+',resizable=yes,top='+topVal+',left='+leftVal+';');
	winPopup.focus();
	return winPopup;
}

////////////////////////  get client height, with and top  ////////////////////////
function getClientHeight()
{
    if (document.compatMode && document.compatMode != "BackCompat")
       return document.documentElement.clientHeight;
    else
       return document.body.clientHeight;
}
function getClientWidth()
{
    if (document.compatMode && document.compatMode != "BackCompat")
       return document.documentElement.clientWidth;
    else
       return document.body.clientWidth;
}
function getClientTop()
{
    if (document.documentElement && document.documentElement.scrollTop)
	    return document.documentElement.scrollTop;
    else if (document.body)
	    return document.body.scrollTop
}

////////////////////////  loading message functions  ////////////////////////
function showLoadingMessage(ev)
{
    document.getElementById("divLoading").style.display = "block"
}

function hideLoadingMessage(){
    document.getElementById('divLoading').style.display = "none"
}

/////////////////////// coockie value reading function //////////////////////
function getCookie(c_name)
{
	if (document.cookie.length>0)
	{
		c_start=document.cookie.indexOf(c_name + "=")
		if (c_start!=-1){ 
			c_start=c_start + c_name.length+1 
			c_end=document.cookie.indexOf(";",c_start)
			if (c_end==-1) c_end=document.cookie.length 
			return unescape(document.cookie.substring(c_start,c_end)) 
		} 
	}
	return null
}

//////////////////////// switch measurement system function  ////////////////////////
function changeSystem(){
    if (getCookie("system") == "metric"){ 
        document.cookie='system='+escape('english')+"; path=/"
        window.location.assign(window.location)
        //window.location.reload()
    }
    else {
        document.cookie='system='+escape('metric')+"; path=/"
        window.location.assign(window.location)
        //window.location.reload()
    }
}

///////////////////////// bookmark site //////////////////////////////????????????????

function bookmarkSite(title, url){
    if (document.all){ 
        window.external.AddFavorite(url, title)
    } else {
        if (window.sidebar) window.sidebar.addPanel(title, url, "") 
    }
}

//////////////////////// switches panels of listing details page ////////////////////////

//panelName could be Delails, Photos, Location, or Contact
//parentName - name of the parent control
function showPanel(panelName, parentName){
    if (panelName == "" || panelName == null) panelName = "Details"
    //alert(panelName)
    var panels = new Array()
    panels[0] = "Details"
    panels[1] = "Photos"
    panels[2] = "Location"
    panels[3] = "Contact"
    var i 
    
    //make all panel buttons inacvive
    for (i in panels){
        document.getElementById(parentName + 'panel' + panels[i]).style.display = 'none'
        document.getElementById('lft' + panels[i]).innerHTML = '<img src="/_img/tabs/tab-inactv-lft.gif" alt="" style="border-width:0px;" />'
        document.getElementById('rt' + panels[i]).innerHTML = '<img src="/_img/tabs/tab-inactv-rt.gif" alt="" style="border-width:0px;" />'
        document.getElementById('txt' + panels[i]).className = 'tab-inactive'
    }
   
    //make active panel button
    document.getElementById(parentName + 'panel' + panelName).style.display = ''
    document.getElementById('lft' + panelName).innerHTML = '<img src="/_img/tabs/tab-actv-lft.gif" alt="" style="border-width:0px;" />'
    document.getElementById('rt' + panelName).innerHTML = '<img src="/_img/tabs/tab-actv-rt.gif" alt="" style="border-width:0px;" />'
    document.getElementById('txt' + panelName).className = 'tab-active'
    
    //document.cookie='tab='+escape(panelName)
} 

//////////////////////// left menu functions ////////////////////////

function mnuOver(ob){
    ob.className = 'mnu-i-hover'
}
function mnuOut(ob){
    ob.className = 'mnu-i'
}
function mnuOverM(ob){
    ob.className = 'mnu-i-mnfg-hover'
}
function mnuOutM(ob){
    ob.className = 'mnu-i-mnfg'
}
function go(sURL) {
	if (sURL.indexOf('http://') == -1 && sURL.indexOf('#') == -1 && sURL.indexOf('www') != -1) { sURL = 'http://' + sURL; }
	window.location = sURL
}
//////////////////////// logs cliks and redirects to the provided URL ////////////////////////
function l(url, channel) {
	window.location = "/c.ashx?u=" + escape(url) + "&c=" + channel + "&l=" + escape(window.location);
}

//////////////////////// changes table row background ////////////////////////
function rowOver(ob_row)
{
    ob_row.style.backgroundColor = "#FFFEEB"
}
function rowOut(ob_row)
{
    ob_row.style.backgroundColor = "#FFFFFF"
}

function switchDIV(DivId){
        
    var panel = document.getElementById(DivId)
    
    if (panel == null) {return}
    
    if (panel.style.display == 'none'){
        panel.style.display = ''
        }
        else{
            panel.style.display = 'none'
            }
}

//////////////////////// switches panels of user control page ////////////////////////

//panelName could be AccountSettings, ChangePassword
//parentName - name of the parent control
function showUserPanel(panelName){
    if (panelName == "" || panelName == null) panelName = "AccountSettings"
        
    var panels = new Array()
    panels[0] = "AccountSettings"
    panels[1] = "ChangePassword"
    var i
    var wasVisible
    
    wasVisible = document.getElementById('panel' + panelName).style.display
    
    //make all panel buttons
    for (i in panels){
        document.getElementById('panel' + panels[i]).style.display = 'none'
    }
       
    //make active panel
    if (wasVisible == 'none'){
		document.getElementById('panel' + panelName).style.display = ''    
    }
    else{
        document.getElementById('panel' + panelName).style.display = 'none'
    }
}

/////////////////// function check enter ////////////////////////
function pressEnter(e){
    var keynum
    if(window.event) // IE
    {
	    keynum = e.keyCode
    }	
    else if(e.which) // Netscape/Firefox/Opera
    {
	    keynum = e.which
    }
    if (keynum == 13) {
	    return true
    } else {
        return false
    }
}

//////////////////////////// positions the panel at the center of the browser window //////////////////////////

function centerPanel(oPanel)
{		
	var scrollLeft = (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
    var scrollTop = (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
    var clientBounds = CommonToolkitScripts.getClientBounds();
    var clientWidth = clientBounds.width;
    var clientHeight = clientBounds.height;
  
	var panelWidth = oPanel.style.width;
  	var panelHeight = oPanel.style.height;
  	
	if (panelWidth.indexOf("px")) panelWidth = panelWidth.substr(0, panelWidth.length - 2);
	if (panelHeight.indexOf("px")) panelHeight = panelHeight.substr(0, panelHeight.length - 2);
		
    oPanel.style.left = scrollLeft+((clientWidth - panelWidth)/2) + 'px';
    oPanel.style.top = scrollTop+((clientHeight - panelHeight)/2) + 'px';
}

////////// returns X and Y for given element Width ang Height to center the element in a browser window ////

function getCenterCoords(oWidth, oHeight)
{
	var scrollLeft = (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
  var scrollTop = (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
  var clientBounds = CommonToolkitScripts.getClientBounds();
  var clientWidth = clientBounds.width;
  var clientHeight = clientBounds.height;
  
	var centerX = parseInt(scrollLeft+((clientWidth - oWidth)/2));
  var centerY = parseInt(scrollTop+((clientHeight - oHeight)/2));

	var coords = new Array(centerX, centerY);
  
  return coords;
}

//////////////////////////// drop-down menues (div layers) //////////////////////////
function hideDDMenu(mnuName)
{
	var t = setTimeout("document.getElementById('" + mnuName + "').style.visibility = 'hidden'", 200);
}
function showDDMenu(mnuName)
{
	var menu = document.getElementById(mnuName)
	menu.style.visibility = menu.style.visibility == "hidden" ? "visible" : "hidden";
}


//////////////////////////// subscribe form //////////////////////////
function toggleSubscribeForm() {
	var f = $("#subscribe_form");
	var w = f.width() + 5;
	if (f.css("left") == "-"+w+"px") {
		f.animate({ "left": "+="+w+"px" }, "fast");
	} else {
		f.animate({ "left": "-="+w+"px" }, "fast");
	}
}