﻿$J(function() {
	// Preload images
	$J("img.jq_hover").each(function() {
		$J("<img>").attr("src", $J(this).attr("src").replace(/^(.*)(\.\w+)$/, "$1_a$2"));
	});

	$J("img.jq_hover").hover(
		function()
		{
		    if($J(this).attr("src").toLowerCase().indexOf("pixel.gif")!=-1)
		    {
		        $J(this)[0].style.filter = $J(this)[0].style.filter.replace("_a.png", ".png");
		        $J(this)[0].style.filter = $J(this)[0].style.filter.replace(".png", "_a.png");
		    }
		    else
		    {
		        $J(this).attr("src", $J(this).attr("src").replace(/^(.*)_a(\.\w+)$/, "$1$2"));
			    $J(this).attr("src", $J(this).attr("src").replace(/^(.*)(\.\w+)$/, "$1_a$2"));
			}
		},
		function()
		{
		    if($J(this).attr("src").toLowerCase().indexOf("pixel.gif")!=-1)
		        $J(this)[0].style.filter = $J(this)[0].style.filter.replace("_a.png", ".png");
		    else
			    $J(this).attr("src", $J(this).attr("src").replace(/^(.*)_a(\.\w+)$/, "$1$2"));
			
		}
	);
	
	$J("input.jq_hover_i").hover(
		function()
		{
		    if($J(this).attr("src").toLowerCase().indexOf("pixel.gif")!=-1)
		    {
		        $J(this)[0].style.filter = $J(this)[0].style.filter.replace("_a.png", ".png");
		        $J(this)[0].style.filter = $J(this)[0].style.filter.replace(".png", "_a.png");
		    }
		    else
		    {
		        $J(this).attr("src", $J(this).attr("src").replace(/^(.*)_a(\.\w+)$/, "$1$2"));
			    $J(this).attr("src", $J(this).attr("src").replace(/^(.*)(\.\w+)$/, "$1_a$2"));
			}
		},
		function()
		{
		    if($J(this).attr("src").toLowerCase().indexOf("pixel.gif")!=-1)
		        $J(this)[0].style.filter = $J(this)[0].style.filter.replace("_a.png", ".png");
		    else
			    $J(this).attr("src", $J(this).attr("src").replace(/^(.*)_a(\.\w+)$/, "$1$2"));
			
		}
	);
});

/// This function is used on About.aspx page to leave selection on image when mouse leave it
var LastUsedImage;
$J(function() {
	// Preload images
	$J("img.jqe_hover").each(function() {
		$J("<img>").attr("src", $J(this).attr("src").replace(/^(.*)(\.\w+)$/, "$1_a$2"));
	});

	$J("img.jqe_hover").hover(
		function()
		{
			if(LastUsedImage)
			{
				$J(LastUsedImage).attr("src", $J(LastUsedImage).attr("src").replace(/^(.*)_a(\.\w+)$/, "$1$2"));
			}
			$J(this).attr("src", $J(this).attr("src").replace(/^(.*)(\.\w+)$/, "$1_a$2"));
			LastUsedImage = this;
		},
		function()
		{
		}
	);

	if($J("img.selected").length > 0)
	{
		$J("img.selected").attr("src", $J("img.selected").attr("src").replace(/^(.*)_a(\.\w+)$/, "$1$2"));
		$J("img.selected").attr("src", $J("img.selected").attr("src").replace(/^(.*)(\.\w+)$/, "$1_a$2"));
		LastUsedImage = $J("img.selected");
	}
});

/// This function is used on Default.aspx page to choose content for selected link
function ShowContent(pDivToShow, pDivContent)
{
    $J("#"+pDivToShow).html($J("#"+pDivContent).html());
}

/// This function is used to simulate the submit by pressing 'Enter'
function CheckEnter(event, id)
{
	if(window.event) event = window.event;
	switch(event.keyCode ? event.keyCode: event.which)
	{
		case 13:
			var el = document.getElementById(id);
			if(el.onclick) el.onclick();
			if(el.href) eval(unescape(el.href));
		break;
	}
}

/// This code extends inner html of a link of css class "button"
$J(function() {
	for(var i = 0;i < $J("a.button").length; i++)
	{
		$J("a.button")[i].innerHTML = "<span class=\"l\">&nbsp;</span><span class=\"text\">" + $J("a.button")[i].innerHTML + "</span><span class=\"r\">&nbsp;</span>";
	}
});

function ShowChat(MemberId)
{
	var height = 440;
	var width = 600;
	
	var spec = 'height='+height+',width='+(width + 20)+',scrollbars=no,status=no,toolbar=no,location=no,resizable=no,menubar=no,modal=yes';        
	var left = (screen.availWidth - width - 20)/2;
	var top = (screen.availHeight - height)/2;
	
	if(left > 0 && top > 0)
	{   
		spec = spec + ',left=' + left + ',top='+top;
}

	var ret = window.open('/Chat/Member/Chat.aspx?MemberId=' + MemberId, MemberId, spec);
	if(ret)
	{
		ret.focus();
	}
}


function ShowFreeConsultations()
{
	var height = 200;
	var width = 600;
	
	var spec = 'height='+height+',width='+(width + 20)+',scrollbars=no,status=no,toolbar=no,location=no,resizable=no,menubar=no,modal=yes';        
    var left = (screen.availWidth - width - 20)/2;
    var top = (screen.availHeight - height)/2;
    
    if(left > 0 && top > 0)
    {   
        spec = spec + ',left=' + left + ',top='+top;
}

    var ret = window.open("/FreeConsultations/GateWay.aspx", "FreeConsultations", spec);
    ret.focus();
}
function ShowPrivacyStatement()
{
	var height = 500;
	var width = 800;

	var spec = 'height='+height+',width='+(width + 20)+',scrollbars=yes,status=no,toolbar=no,location=no,resizable=yes,menubar=no,modal=yes';        
    var left = (screen.availWidth - width - 20)/2;
    var top = (screen.availHeight - height)/2;
    
    if(left > 0 && top > 0)
    {   
        spec = spec + ',left=' + left + ',top='+top;
    }        
            
    var ret = window.open("/PrivacyPolicyForAutomaticLeads.html", "PrivatyStatement", spec);
    ret.focus();
}

function sizeDiv(obj,pos){
	if(obj.scrollHeight>(null != arguments[2]?arguments[2]:100)){
		obj.style.height = (null != arguments[2]?arguments[2]:'100') + 'px';
	}
	else{
		obj.style.height = obj.scrollHeight + 'px';
	}
	if(null != pos)
	{
		obj.style.position = pos;
		obj.style.zIndex = 1000;
	}
}

function unsizeDiv(obj,pos){
	for(var i=0;i<obj.childNodes.length;i++){
		if(obj.childNodes[i]==document.activeElement){
			return false;
		}
	}
	obj.style.height = (null != arguments[2]?arguments[2]:'22')+'px';
	if(null != pos)
	{
		obj.style.position = pos;
		obj.style.zIndex = 20;
	}
}

function SelectAll(pchek,pInputName)
{
    var arrcheck = document.getElementsByName(pInputName);
    for(var i=0;i<arrcheck.length;i++) arrcheck[i].checked=pchek.checked;
}