var strBuyerURL = "http://dev.collectivepoint.com/ChatVisitor/"
				  
function getexpirydate(nodays)
{
	var UTCstring;
	Today = new Date();
	nomilli = Date.parse(Today);
	Today.setTime(nomilli + nodays * 24 * 60 * 60 * 1000);
	UTCstring = Today.toUTCString();
	return UTCstring;
}

function setCookie(name,value,duration)
{
	if (document.iscookiesenable == 'false') return;
	document.cookie=name+"="+escape(value)+";EXPIRES="+getexpirydate(duration);
}

function getCookie(cookiename)
{
	var cookiestring=""+document.cookie;
	var index1=cookiestring.indexOf(cookiename);
	
	try
	{
		if (document.iscookiesenable == 'false') 
			return "";
		
		if (index1==-1 || cookiename=="")
			return "";

		var index2=cookiestring.indexOf(';',index1);

		if (index2==-1)
			index2=cookiestring.length;

		if( cookiestring.substring( index1+cookiename.length, index1+cookiename.length+1 ) != "=")
			return "";
				
		return unescape( cookiestring.substring( index1+cookiename.length+1, index2 ) );
	}
	catch(e)
	{}
}

function setValuesForRegisterPage()
{
	document.UserFName = ( getCookie( 'AutoIM_UserFirstName' )	== null )? "" : getCookie( 'AutoIM_UserFirstName'	);
	document.UserMName = ( getCookie( 'AutoIM_UserMiddleName' ) == null )? "" : getCookie( 'AutoIM_UserMiddleName'	);
	document.UserLName = ( getCookie( 'AutoIM_UserLastName' )	== null )? "" : getCookie( 'AutoIM_UserLastName'	);
	document.UserEmail = ( getCookie( 'AutoIM_UserEmail' )		== null )? "" : getCookie( 'AutoIM_UserEmail'		);
	//document.UserQuestion = ( getCookie( 'AutoIM_UserQuestion' ) == null )? "" : getCookie( 'AutoIM_UserQuestion' );
}
function getIsUserReVisitor()
{
	var strReVisitor = getCookie( 'AutoIM_ReVisitor' );

	try
	{
		if( strReVisitor != null && strReVisitor != "" )
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	catch(e)
	{}
}

function setReVisitor()
{
	setCookie( 'AutoIM_ReVisitor', 'true', 365 );
}
function getLinks()
{
	try{
		sendRequest( strBuyerURL + "IconGen.aspx?LocationID=" + document.LocationID
				+ "&CompanyID=" + document.CompanyID + "&TeamID=" + document.TeamID 
				+ "&SettingID=" + document.SettingID + "&HasSkype=" + skypeCheck(), 1, 1);
	}
	catch(e){}
}

/**********************************************************
/*****************skype ***********************************/
var activex = ((navigator.userAgent.indexOf('Win')  != -1) && (navigator.userAgent.indexOf('MSIE') != -1) && (parseInt(navigator.appVersion) >= 4 ));
var CantDetect = ((navigator.userAgent.indexOf('Safari')  != -1) || (navigator.userAgent.indexOf('Opera')  != -1));

function oopsPopup() {
	var windowName = "oops";
	var URLtoOpen = "http://download.skype.com/share/skypebuttons/oops/oops.html";
	var popW = 540, popH = 305;
	var scrollB = 'no';
	w = screen.availWidth;
	h = screen.availHeight;
	var leftPos = (w-popW)/2, topPos = (h-popH)/2;
	oopswindow = window.open(URLtoOpen, windowName,'width=' + popW + ',height=' + popH + ',scrollbars=' + scrollB + ',screenx=' +leftPos +',screeny=' +topPos +',top=' +topPos +',left=' +leftPos);
	return false;
}

if(typeof(detected) == "undefined" && activex) {
    document.write(
        ['<script language="VBscript">',
        'Function isSkypeInstalled()',
        'on error resume next',
        'Set oSkype = CreateObject("Skype.Detection")',
        'isSkypeInstalled = IsObject(oSkype)',
        'Set oSkype = nothing',
        'End Function',
        '</script>'].join("\n")
    );
}

function skypeCheck() {
    if(CantDetect) {
        return true;
    } else if(!activex) {
        var skypeMime = navigator.mimeTypes["application/x-skype"];
        detected = true;
        if(typeof(skypeMime) == "object") {
            return true;
        } else {
            return false;
        }
    } else {
        if(isSkypeInstalled()) {
            detected = true;
            return true;
        }
    }
    
    detected = true;
    return false;
}