// Transparent png in IE6 -------------------------------------
function fixPNG(element)
{

  //if IE 5.5-6
  if (/MSIE (5\.5|6).+Win/.test(navigator.userAgent))
  {
    var src;
    if (element.tagName=='IMG') // if IMG
    {
        src = element.src;
        element.src = "/images/branding/blank.gif"; //replace the image by transparent gif
    }
    else // if not IMG
    {
      src = element.currentStyle.backgroundImage.match(/url\("(.+)"\)/i);
      if (src)
      {
        src = src[1]; 
        element.runtimeStyle.backgroundImage="none"; 
      }
    }
    // use AlphaImageLoader
    if (src) element.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "',sizingMethod='image')";
  }
  
}


// functions for your-profile page
function ChangeCompanyType(pDrop)
{
	if( pDrop.selectedIndex == 0 )
	{
		document.getElementById('pnlFile1').style.display = 'none';
		return;
	}
	sText = new String(pDrop.options[pDrop.selectedIndex].text);	
	sType = sText.split(' ');
	if( sText.indexOf('Estate Agent or Broker',0) >= 0 || sText.indexOf('Property Developer') >= 0 )
	{
		document.getElementById('pnlFile1').style.display = 'block';
	}
	else
	{
		document.getElementById('pnlFile1').style.display = 'none';
	}
		
}

function viewOtherCountry(pDrop)
{
	if( pDrop.selectedIndex == 0 )
	{
		document.getElementById('pnlOtherCountry').style.display = 'none';
		return;
	}
	sText = new String(pDrop.options[pDrop.selectedIndex].value);	
	sType = sText.split(' ');
	if( sText.indexOf('Other',0) >= 0  )
	{
		document.getElementById('pnlOtherCountry').style.display = 'block';
	}
	else
	{
		document.getElementById('pnlOtherCountry').style.display = 'none';
	}
}

// functions for regions bind with ajax

sRegion1 = "";
sRegion2 = "";
sRegion3 = "";

function SetSelected(pDrop, sValue)
{
	for(var i = 0; i < pDrop.options.length; i++)
	{		
		if( pDrop.options[i].value == sValue )
			pDrop.selectedIndex = i;
	}
}

function SetRegionVisible(Region1, Region2, Region3)
{
	var ddlCountry = getCustomElementByIdInFrontEnd('ddlCountry');
	
	if( ddlCountry.selectedIndex > 0)
	{
		sRegion1 = Region1;
		sRegion2 = Region2;
		sRegion2 = Region2;
		
		AjaxHelper.GetRegionsByCountry(ddlCountry.options[ddlCountry.selectedIndex].value, 1, BindRegions);
		if( sRegion1 != "-1" )
			AjaxHelper.GetRegionsByCountry(sRegion1, 2, BindRegions);
		if( sRegion2 != "-1" )		
			AjaxHelper.GetRegionsByCountry(sRegion2, 3, BindRegions);								
	}
}

function getCustomElementByIdInFrontEnd(sID)
{
	for (var i = 0; document.forms[1].elements.length; i++)
		if( document.forms[1].elements[i].id.indexOf(sID) != -1 )
			return document.forms[1].elements[i];
	return null;
}
function getCustomElementById(sID)
{
	for (var i = 0; document.forms[1].elements.length; i++)
		if( document.forms[1].elements[i].id.indexOf(sID) != -1 )
			return document.forms[1].elements[i];
	return null;
}

function ChangeCountry(pDrop, Index)
{
	for( var i = Index; i < 4; i++ ) // hide all children
	{
		document.getElementById('pnlRegion' + i).style.display = 'none';
		getCustomElementByIdInFrontEnd('ddlRegion' + i).options.length = 1;
	}
		
	
	// reset selected values
	sRegion1 = '-1';
	sRegion2 = '-1';
	sRegion3 = '-1';
	
	AjaxHelper.GetRegionsByCountry(pDrop.options[pDrop.selectedIndex].value, Index, BindRegions);
}

// back from ajax
function BindRegions(pResult)
{
	if( pResult != null && pResult.value != null)
	{
		var ddlRegion = getCustomElementByIdInFrontEnd('ddlRegion' + pResult.value.Index);
		
		if( pResult.value.RegionNames1 != null )
		{
			for(var i = 0; i < pResult.value.RegionNames1.length; i++)
			{
				ddlRegion.options[i + 1] = new Option(pResult.value.RegionNames1[i], pResult.value.RegionIDs1[i]);
			}
			ddlRegion.selectedIndex = 0;
			ddlRegion.options.length = pResult.value.RegionNames1.length + 1;
			if( pResult.value.Index == 1 )
				SetSelected(ddlRegion, sRegion1);
			if( pResult.value.Index == 2 )
				SetSelected(ddlRegion, sRegion2);
			if( pResult.value.Index == 3 )
				SetSelected(ddlRegion, sRegion3);	
			// show if there are more than 0 regions
			if( pResult.value.RegionNames1.length > 0 )
				visibleRegion( pResult.value.Index );
		}				
	}
}
//-end functions for ajax

// set visible of region's area
function visibleRegion(k) {

	document.getElementById('pnlRegion'+k).style.display='block';
	document.getElementById('pnlRegion'+k).className='cur';
}

function addBookmark(url, title)
{
  if (!url) url = location.href;
  if (!title) title = document.title;
  
 //Gecko
  if ((typeof window.sidebar == "object") && (typeof window.sidebar.addPanel == "function")) window.sidebar.addPanel (title, url, "");
 //IE4+
  else if (typeof window.external == "object") window.external.AddFavorite(url, title);
 //Opera7+
  else if (window.opera && document.createElement)
  {
    var a = document.createElement('A');
    if (!a) return false; //IF Opera 6
    a.setAttribute('rel','sidebar');
    a.setAttribute('href',url);
    a.setAttribute('title',title);
    a.click();
  }
  else return false;
  
  return true;
}


function CheckBoxListSelect(cbControl, state)
{   
	var chkBoxList = document.getElementById(cbControl);
    var chkBoxCount= chkBoxList.getElementsByTagName("input");
    for(var i=0;i<chkBoxCount.length;i++)
    {
        chkBoxCount[i].checked = state;
    }
      
    return false; 
}

function ChangeStatus(pDrop)
{
	if( pDrop.selectedIndex == 0 )
	{
		document.getElementById('pnl1').style.display = 'none';
		document.getElementById('pnl2').style.display = 'none';
		document.getElementById('pnl3').style.display = 'none';
	}
	else
	{
		document.getElementById('pnl1').style.display = 'block';
		document.getElementById('pnl2').style.display = 'block';
		document.getElementById('pnl3').style.display = 'block';
	}		
}


