var PopURL="";
var PopWin=null;

function setCookie(c_name,value,expiredays)
{
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function getCookie(c_name)
{
	if (document.cookie.length>0)
	{
		var c_start=document.cookie.indexOf(c_name + "=");
		
		if (c_start!=-1)
		{ 
			c_start=c_start + c_name.length+1; 
			
			var 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 "";
}

function writeFlashToPage(flashURL, width, height, divID, swfID, transparent)
{
	if(width==null) { width = '100%'; }
	if(height==null) { height = '100%'; }
	
	var objTransparent = '';
	var embedTransparent = '';
	
	if(transparent)
	{
		objTransparent = '<param name="wmode" value="transparent">';
		embedTransparent = ' wmode="transparent"';
	}
	
	var objIDSt = '';
	var embedIDSt = '';
	
	if(swfID)
	{
		objIDSt = ' id="' + swfID + '"';
		embedIDSt = ' name="' + swfID + '"';
	}
		
	var objectHTML = 
		'<object' + objIDSt + ' classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="' + width + '" height="' + height + '">'
 		+ '<param name="movie" value="' + flashURL + '">'
		+ '<param name="quality" value="high">'
		+ '<param name="menu" value="true">'
		+ objTransparent
		+ '<embed' + embedIDSt + ' src="' + flashURL + '" quality="high" menu="true" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="' + width + '" height="' + height + '"' + embedTransparent + '></embed>'
		+ '</object>';
	
	if(divID==null)
	{
		document.write(objectHTML);
	}
	else
	{
		document.getElementById(divID).innerHTML = objectHTML;
	}
}

function openWindow(url,width,height,status,full)
{
    PopURL=url;

    if(!PopWin || PopWin.closed){
        PopWin=PopWinOpen(width,height,status,full);
    }
    else {
        PopWin.close();
        PopWin=null;
        PopWin=PopWinOpen(width,height,status,full);
    }
    
    top.onfocus = null;
    
    return PopWin;
}

function PopWinOpen(width,height,status,full){
    var x =(screen.availWidth-width)/2;
    var y =(screen.availHeight-height)/2;
	var status_st = '';
	
	if(status)
	{
		status_st = ',status';
	}
	
	if(full)
	{
		status_st = ',fullscreen=yes';
	}

	var date_obj = new Date();
	var date_st = '' + date_obj.getTime();

  	var winfeatures="width="+width+",height="+height+",top="+y+",left="+x+",resizable=yes,scrollbars=0" + status_st;
	openpopwin=null;
	openpopwin=window.open(PopURL,"wkapp" + date_st,winfeatures);
	
	return openpopwin;
}

function openModalWindow(loc, width, height, args)
{	
	var props = 'center:yes;status:no;resizable:no;dialogWidth:' + width + 'px;dialogHeight:' + height + 'px;help:no;scroll:no;status:no;';

	var ret = window.showModalDialog(loc, args, props);

	return ret;
}

function closeModalWindow()
{
	alert('hello');
	
	if(PopWin && !PopWin.closed)
	{
		PopWin.close();
	}
}

function getURLParameter(name)
{
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");

	var regexS = "[\\?&]"+name+"=([^&#]*)";
	var regex = new RegExp( regexS );

	var results = regex.exec(window.location.href);

	if( results == null )
	{
		return "";
	}
	else
	{
		return results[1];
	}
}

function alertText(st)
{
	alert(st);
}