var domain="";
function openHelpPopUp(helpID,width, height)
{
    if (typeof(width) == "undefined")
    {
        width = 575;
    } 
    if (typeof(height) == "undefined")
    {
        height = 500;
    }
	
	URL = "/help/help-popup.aspx?ID="+helpID+"&Type=1";
	
	if (domain!=null && domain != "")
	{	   
	    URL = "http://" + domain + URL;
	}
	
	window.open(URL,"KasambaHelp", "width=" + width + ", height=" + height + ", resizable=1, scrollbars=1");
}

function recommendExpert(qs){
	window.open('/account/recommend-us.aspx?' + qs,'recommend','scrollbars=no,height=565,width=585,menubar=no,resizable=yes,titlebar=no,toolbar=no,status=no')
}

function recommendKasamba(){
			window.open('/account/recommend-us.aspx','recommendKasamba','scrollbars=no,height=565,width=585,menubar=no,resizable=yes,titlebar=no,toolbar=no,status=no')
}

function recommendCategory(catID){
	window.open('/account/recommend-us.aspx?' + catID,'recommend','scrollbars=no,height=565,width=585,menubar=no,resizable=yes,titlebar=no,toolbar=no,status=no')
}

function openPrivacy()
{
    window.open('/help/help-popup.aspx?ID=554','privacy','scrollbars=yes,height=500,width=575,menubar=no,resizable=yes,titlebar=no,toolbar=no,status=no')
}

function closeWindow()	
{			
	window.close(); 
}

function display(element, displayValue)	// displayValue: none , block, inline
{       
    element.style.display = displayValue;
}

function handlePhoneNumbersDisplay(divPhoneNumbers, checkBoxPhones)
{   
    divPhoneNumbersID = document.getElementById(divPhoneNumbers);
    checkBoxPhonesID  = document.getElementById(checkBoxPhones);
    if ( checkBoxPhonesID.checked )
        display(divPhoneNumbersID, 'block');
    else
        display(divPhoneNumbersID, 'none');
}

function goBack()
{
	window.history.go(-1);
}
	
function checkSearchTxt(strSearchTxt)
{			
	if (strSearchTxt.length>50)
	{
		strSearchTxt = strSearchTxt.substring(0,50);
	}
	for (i=0;i<strSearchTxt.length;i++){
		
		if ( strSearchTxt.charAt(i)==')' || strSearchTxt.charAt(i)=='\\' || strSearchTxt.charAt(i)==',' || strSearchTxt.charAt(i)=='"' || strSearchTxt.charAt(i)==']' || strSearchTxt.charAt(i)=='[' || strSearchTxt.charAt(i)=='~' || strSearchTxt.charAt(i)=='!' || strSearchTxt.charAt(i)=='&' || strSearchTxt.charAt(i)=='%' || strSearchTxt.charAt(i)=='\'' || strSearchTxt.charAt(i)=='<' || strSearchTxt.charAt(i)=='>'){
			strUntil = strSearchTxt.substring(0,i);
			strAfter = strSearchTxt.substring(i+1,strSearchTxt.length);
			strSearchTxt = strUntil + strAfter;
		}
	}	
	 	
	return (strSearchTxt);
}	

function searchClick(srcbtn)
{
    document.location = "/expert-match/" + checkSearchTxt(document.getElementById(srcbtn).value) + "/";   
}

function OpenWindow(url, width, height)	
{	
    if (typeof(width) == "undefined")
    {
        width = 420;
    }
    if (typeof(height) == "undefined")
    {
        height = 300;
    }
	window.open(url, 'winHelp', "width=" + width + ", height=" + height + ", resizable=1, scrollbars=1"); 
}

function smartOpenWindow(url, openTarget)
{   
	// are we in an iframe?
    if (self != window.top)
    {
        window.open(url,"_blank");	
    }
    // are we in a popup?
    else 
    { 
        if (openTarget == "_top")
        {
			if ((window.opener == null) || (window.opener.closed))
			{
			//	window.open(url, "_blank", "width=800 height=600");
	            window.open(url ,'_blank','scrollbars=yes,height='+ screen.height + ',width='+ screen.width +',left =1 ,top =1 ,menubar=yes,resizable=yes,titlebar=yes,toolbar=yes,status=yes')

			}
			else
			{
				window.opener.location = url;
			}
            window.close();
        }
        else  //regular case
        {
             window.open(url,"_self");	
        }
     }
}

function openNewWindow(hyperlink)
{
	var url = hyperlink.href;
	var target = hyperlink.target;
	var params = "location=yes, menubar=yes, resizable=yes, scrollbars=yes, status=yes, titlebar=yes, toolbar=yes";
	var w= window.open(url, target, params);
	w.focus();
	return false;
}

function openSearchWindow(url)
{
	var params = "location=yes, menubar=yes, resizable=yes, scrollbars=yes, status=yes, titlebar=yes, toolbar=yes";
	window.open(url, '_blank', params);
	return false;
}

function StartOpenMenuLayer()
{
    if (MiniHeader == '1')
    {
        document.getElementById(ImgMyKasambaID).src = '/UserControlsLibrary/images/Header/MyLivePersonClickedHP.gif';
    }
    else
    {
       document.getElementById(ImgMyKasambaID).src = '/UserControlsLibrary/images/Header/MyLivePersonClicked.gif'; 
    }
    document.getElementById(tblClientExpertMenu).style.display='block';
}

function EndOpenMenuLayer()
{
    openedMenuLayer=true;
}

function StartCloseMenuLayer()
{
    if (MiniHeader == '1')
    {
        document.getElementById(ImgMyKasambaID).src = '/UserControlsLibrary/images/Header/MyLivePersonHP.gif';
    }
    else
    {
        document.getElementById(ImgMyKasambaID).src = '/UserControlsLibrary/images/Header/MyLivePerson.gif';
    }
}

function EndCloseMenuLayer()
{
    document.getElementById(tblClientExpertMenu).style.display='none';
    openedMenuLayer=false;
}

function OpenConfirmBox(openBox,text)
{       
    if (openBox == true)
    {
        return window.confirm(text);        
    }
    return true;    
}

function openRating(MemID)
{
	url = "/rating/expert-rating.aspx?i_MemID=" + MemID
	window.open(url, 'rating', 'scrollbars=yes,height=400,width=450,menubar=no,resizable=yes,titlebar=no,toolbar=no,status=no');
} 
function openViewProfile(memID,CatID)
{
	window.open('/professional/expert-profile.aspx?conMemID=' + memID +'&CatID=' + CatID ,'ViewProfile','scrollbars=yes,height='+ screen.height + ',width='+ screen.width +',left =1 ,top =1 ,menubar=yes,resizable=yes,titlebar=yes,toolbar=yes,status=yes')
	window.close();
}

function RedirectTo(url)
{
    document.location = url;
}

function OnHeaderMenuOver(obj)
{
    obj.className='headermenu-over';
}

function OnHeaderMenuOut(obj)
{
    obj.className='headermenu';
}



/*** referedetect.js ***/
if (document.URL.indexOf('https:') > -1) { 
	var scriptLoc_s = 'https://'; 
} else { 
	var scriptLoc_s = 'http://'; 
} 

var scriptLoc = scriptLoc_s+'myap.liveperson.com/rep.asp';

var kbId = 0;
var queryString = window.location.search.substring(1);
var imgdata = '';
var subdata = '';
var overwrite = 0;
var refdata = document.referrer;
var daysToLive = 365;
var multiDomain = false;

if (queryString.length > 0)
{
	var pairs = queryString.split('&');
							
	for(var i = 0; i < pairs.length; i++)
	{
		var pairs2 = pairs[i].split('=');
		
		switch(pairs2[0].toLowerCase())
		{
			case 'kbid':
				kbId = pairs2[1];
				break;
			case 'clearcookie':
				if (pairs2[1] == 1)
				{
					DeleteCookie("kbid");
				}
				break;
			case 'img':
				imgdata = pairs2[1];
				break;
			case 'sub':
				subdata = pairs2[1];
				break;
		}
	} //end for
}//end if

if (GetCookie("kbid") == null || overwrite == 1)
{
	if (kbId != 0)
	{
		var xrn = Math.round(Math.random()*9999999);
		var img = new Image();
		var url = scriptLoc + '?xrn=' + xrn.toString() +'&id=' + kbId;
		if (imgdata != '')
		{
			url += '&img=' + imgdata
		}

		if (subdata != '')
		{
			url += '&sub=' + subdata
		}
		if (refdata != '')
		{
			url += '&ref=' + refdata;
		}

		img.src = url;
		
		SetCookie("kbid", kbId, daysToLive);
	}
}//end if

function getCookieVal (offset) 
{
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1)
		endstr = document.cookie.length;

	return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie (name) 
{
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	
	while (i < clen) 
	{
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg)
			return getCookieVal (j);
		
		i = document.cookie.indexOf(" ", i) + 1;

		if (i == 0) break; 
	}
	
	return null;
}

function WriteCookie (name, value, expires) 
{
	var argv = SetCookie.arguments;
	var argc = SetCookie.arguments.length;
	var path = "/";

		//inserted by Andrew Herron to fix cross-sub-domain cookie compatibility, 05/02/2006
		if (multiDomain) {
			rootDomain = document.domain;
		} else {
			domain = document.domain;
			dparts = domain.split(".");
			if (dparts.length == 3) {
				rootDomain = dparts[1]+"."+dparts[2];
			} else {
				rootDomain = domain;
			}
		}

	var secure = (argc > 5) ? argv[5] : false;
	
	var cookie = name + "=" + escape(value) +
		((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
		((path == null) ? "" : ("; path=" + path)) +
		((rootDomain == null) ? "" : ("; domain=" + rootDomain)) +
		((secure == true) ? "; secure" : "");
	
	document.cookie = cookie;
}

function DeleteCookie (name) 
{
	var exp = new Date();
	exp.setTime (exp.getTime() - 1000000000);  // This cookie is history (changed -1 to make it previous time)
	var cval = GetCookie (name);
	document.cookie =name + "=" + cval + "; expires=" + exp.toGMTString();
}

function SetCookie(name, value, expiredays)
{
	var expdate = new Date(); 
	expdate.setTime(expdate.getTime() + (24 * 60 * 60 * 1000 * expiredays)); 
	WriteCookie(name, value, expdate);  
}


// limits the number of characters in a multiline textbox
function limitTextLengthInTextArea(textBox, length)
{   
    var maxlength = new Number(length); 
	if (textBox.value.length > maxlength)
	{
		textBox.value = textBox.value.substring(0,maxlength);		
	}
}

function sendPBQ(){
			str = window.document.Form1.txt_Question.value;
			str = str.replace(/\n/g,"~NL~");
			window.location.href = "/post-request/default.aspx?S1=" + str;
}
// opens the 'My Kasamba' pop up panel in the header
function openMyKasamba(ImgMyKasambaID)
{    
    ImgMyKasamba = document.getElementById(ImgMyKasambaID);
    ImgMyKasamba.click();
}
function setFocus(objID)
{   
    obj = document.getElementById(objID);    
    obj.focus();
}

function CountInvalid()
{
  var vCount = 0;
  if (gVAM_Vals != null)
  {
    for (var vI = 0; vI < gVAM_Vals.length; vI++)
    {
        if (gVAM_Vals[vI]!=null && gVAM_Vals[vI].IsValid == false)
        {
            vCount++;
        }
    }
  }
  return vCount;
}

//get count of invalid validators in some group 
 function CountInvalidInGroup(sGroupName)
	{
		var vCount = 0;
		if (gVAM_Vals != null)
		{
		for (var vI = 0; vI < gVAM_Vals.length; vI++)
		{
		if (gVAM_Vals[vI]!=null  && gVAM_Vals[vI].Group==sGroupName && gVAM_Vals[vI].IsValid == false)
        {
           vCount++;
        }
    
    }
	
	}
    return vCount;
	
	}



function SetLpChatNumber(number)
{
    if(lpMTagConfig)
        lpMTagConfig.lpNumber=number;
}
function smartOpenHrf(aObject, openTarget)
{   
	
	var url = aObject.href;
	// are we in an iframe?
    if (self != window.top)
    {
        window.open(url,"_blank");	
    }
    // are we in a popup?
    else 
    { 
        if (openTarget == "_top")
        {
			if ((window.opener == null) || (window.opener.closed))
			{
			//	window.open(url, "_blank", "width=800 height=600");
	            window.open(url ,'_blank','scrollbars=yes,height='+ screen.height + ',width='+ screen.width +',left =1 ,top =1 ,menubar=yes,resizable=yes,titlebar=yes,toolbar=yes,status=yes')

			}
			else
			{
				window.opener.location = url;
			}
            window.close();
        }
        else  //regular case
        {
             window.open(url,"_self");	
        }
     }
}
 function CheckMaxLen(objID)
        {
           
            var obj = document.getElementById(objID);
            if( obj.value.length > 32 )
            {
                obj.value = "";
               // obj.focus();
             }
        }
        