function clearText(myField){
	if (myField.defaultValue==myField.value)
	{
		myField.value = ""
	}
}

function fillText(myField) {
	if (myField.value=="")
	{
		myField.value = myField.defaultValue
	}
}

/*function popUp(mySrc, myWidth, myHeight)
{
	var myHor = (screen.width/2)-(myWidth/2);
	var myVert = (screen.height/2)-(myHeight/2);
	myWindow = window.open(mySrc,'portfolio','toolbar=0, location=0, directories=0, status=1, menubar=0, scrollbars=0, resizable=0');
	myWindow.resizeTo(myWidth,(eval(myHeight)+56));
	myWindow.moveTo(myHor,myVert);
	myWindow.focus();
}*/

//Set myWindow as global var
var myWindow = '';

function popUpEmbed(mySrc, myWidth, myHeight, myType, myPlayer)
{

	var myBrowser = getBrowser();
	var initString = "";

	var myDimensions = setDimensions(myType, myBrowser ,myWidth, myHeight);
	myWidth = myDimensions[0];
	myHeight = myDimensions[1];
	var myOuterWidth = myDimensions[2];
	var myOuterHeight= myDimensions[3];
	
	var myHor = (screen.width/2)-(myWidth/2);
	var myVert = (screen.height/2)-(myHeight/2);	

	if(myBrowser == 'Firefox')
	{
		initString = "toolbar=0, location=0, directories=0, status=1, menubar=0, scrollbars=0, resizable=1, outerHeight="+myOuterHeight+", outerWidth="+myOuterWidth+"";
	}
	else
	{
		initString = "toolbar=0, location=0, directories=0, status=1, menubar=0, scrollbars=0, resizable=1, height="+myOuterHeight+", width="+myOuterWidth+"";
	}
	
	//Close window if open
	if(myWindow && !myWindow.closed)
	{
		myWindow.close();
	}

	myWindow = window.open("embed.aspx?file_name="+mySrc+"&width="+myWidth+"&height="+myHeight+"&file_type="+myType+"&player="+myPlayer+"","portfolio",""+initString+"");
	myWindow.moveTo(myHor,myVert);
	
}

function writeContent(mySrc, myWidth, myHeight, myType, myPlayer)
{
	switch(myType)
	{
		case 'mpg':
		case 'mpeg':
		case 'wmv':
			if(navigator.platform == 'Win32' && getBrowser() == 'Internet Explorer')
			{
				//Implementation with writeHTML:
				document.write("<script language=\"javascript\">\n\t\t\t");
				document.write("writeHTML('<embed name=\"embWrap\" type=\"application/x-mplayer2\" pluginspage=\"http://www.microsoft.com/Windows/MediaPlayer/\" src=\""+mySrc+"\" autoplay=\"true\" width=\""+myWidth+"\" height=\""+myHeight+"\"></embed>');\n\t\t");
				document.write("</script>\n\t");
			}
			else
			{
				//Clean implementation with QuickTime beacuse of FFF
				document.write("<object id='objWrap' classid='clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B' codebase='http://www.apple.com/qtactivex/qtplugin.cab' width='"+myWidth+"' height='"+myHeight+"'>\n\t\t\t");
				document.write("<param name='src' value='"+mySrc+"'>\n\t\t\t");
				document.write("<param name='autoplay' value='true'>\n\t\t\t");
				document.write("<embed name='embWrap' type='video/quicktime' pluginspage='http://www.apple.com/quicktime/download/' src='"+mySrc+"' autoplay='true' width='"+myWidth+"', height='"+myHeight+"'></embed>\n\t\t");
				document.write("</object>\n\t");
				
				//Clean implementation:
				//document.write("<object id='objwrap' classid='clsid:22d6f312-b0f6-11d0-94ab-0080c74c7e95' codebase='http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#version=5,1,52,701' standby='laster arbeidspr&oslash;ve' type='application/x-oleobject' width='"+myWidth+"' height='"+myHeight+"'>\n\t\t\t");
				//document.write("<param name='filename' value='"+mySrc+"'>\n\t\t\t");
				//document.write("<embed name='embwrap' type='application/x-mplayer2' pluginspage='http://www.microsoft.com/windows/mediaplayer/' src='"+mySrc+"' autostart='1' width='"+myWidth+"', height='"+myHeight+"'></embed>\n\t\t");
				//document.write("</object>\n\t");
			}
			break;
		case 'mov':
			if(navigator.platform == 'Win32' && getBrowser() == 'Internet Explorer')
			{
				//Implementation with writeHTML:
				document.write("<script language=\"javascript\">\n\t\t\t");
				document.write("writeHTML('<embed name=\"embWrap\" type=\"video/quicktime\" pluginspage=\"http://www.apple.com/quicktime/download\" src=\""+mySrc+"\" autoplay=\"true\" width=\""+myWidth+"\" height=\""+myHeight+"\"></embed>');\n\t\t");
				document.write("</script>\n\t");
			}
			else
			{
				//Clean implementation:
				document.write("<object id='objWrap' classid='clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B' codebase='http://www.apple.com/qtactivex/qtplugin.cab' width='"+myWidth+"' height='"+myHeight+"'>\n\t\t\t");
				document.write("<param name='src' value='"+mySrc+"'>\n\t\t\t");
				document.write("<param name='autoplay' value='true'>\n\t\t\t");
				document.write("<embed name='embWrap' type='video/quicktime' pluginspage='http://www.apple.com/quicktime/download/' src='"+mySrc+"' autoplay='true' width='"+myWidth+"', height='"+myHeight+"'></embed>\n\t\t");
				document.write("</object>\n\t");
			}
			break;
		case 'swf':
			document.write("<div id=\"holder\"></div>\n\t\t");
			document.write("<script type=\"text/javascript\">\n\t\t\t");
			document.write("var so = new SWFObject(\""+mySrc+"\", \"Arbeidspr&oslash;ve\", \""+myWidth+"\", \""+myHeight+"\", \"7\", \"#FFFFFF\");\n\t\t\t");
			document.write("so.write(\"holder\");\n\t\t");
			document.write("</script>\n\t");
			break;
		case 'flv':
			document.write("<div id=\"holder\"></div>\n\t\t");
			document.write("<script type=\"text/javascript\">\n\t\t\t");
			document.write("var so = new SWFObject(\""+myPlayer+"\", \"Arbeidspr&oslash;ve\", \""+myWidth+"\", \""+myHeight+"\", \"7\", \"#FFFFFF\");\n\t\t\t");
			document.write("so.write(\"holder\");\n\t\t");
			document.write("</script>\n\t");
			break;
		case 'mp3':
			document.write("<div id=\"holder\"></div>\n\t\t");
			document.write("<script type=\"text/javascript\">\n\t\t\t");
			document.write("var so = new SWFObject(\"flash/WoxPlayer_MP3.swf\", \"Arbeidspr&oslash;ve\", \""+myWidth+"\", \""+myHeight+"\", \"7\", \"#FFFFFF\");\n\t\t\t");
			document.write("so.addVariable(\"mediaUrl\",\""+mySrc+"\");\n\t\t\t");
			document.write("so.write(\"holder\");\n\t\t");
			document.write("</script>\n\t");
			break;
		default:
			document.write("<div style=\"margin:20px;color:#000000;font-size:12px;font-weight:bold;\">An error ocurred. Please close this window and try again!</div>\n\t");
			break;
	}

	document.write("</body>\n</html>");
	document.close();
}

//Adjust width and height according to file format. This is to make space for controls.
function setDimensions(myType, myBrowser, myWidth, myHeight)
{
	var myOuterWidth = 0;
	var myOuterHeight = 0;
	
	switch(myBrowser)
	{
		case 'Internet Explorer':
			switch(myType)
			{
				case 'mov':
					myOuterWidth = eval(myWidth);
					myOuterHeight = eval(myHeight)+15;
					myHeight = eval(myHeight)+15;
					break;
				case 'mpeg':
				case 'mpg':
				case 'wmv':
					myOuterWidth = eval(myWidth);
					myOuterHeight = eval(myHeight)+45;
					myHeight = eval(myHeight)+45;
					break;
				case 'swf':
				case 'flv':
				case 'mp3':
					myOuterWidth = eval(myWidth);
					myOuterHeight = eval(myHeight);
					break;
				default:
					myOuterWidth = eval(myWidth);
					myOuterHeight = eval(myHeight);
					break;
			}
			break;
		case 'Firefox':
			if(navigator.platform == 'Win32')
			{
				switch(myType)
				{
					case 'mov':
						myOuterWidth = eval(myWidth)+8;
						myOuterHeight = eval(myHeight)+71;
						myHeight = eval(myHeight)+15;
						break;
					case 'mpeg':
					case 'mpg':
					case 'wmv':
						myOuterWidth = eval(myWidth)+8;
						myWidth = eval(myWidth);
						myOuterHeight = eval(myHeight)+101;
						myHeight = eval(myHeight)+45;
						break;
					case 'swf':
					case 'flv':
					case 'mp3':
						myOuterWidth = eval(myWidth)+8;
						myOuterHeight = eval(myHeight)+56;
						myHeight = eval(myHeight);
						break;
					default:
						myOuterWidth = eval(myWidth);
						myOuterHeight = eval(myHeight);
						break;
				}
				break;
			}
			else
			{
				switch(myType)
				{
					case 'mov':
						myOuterWidth = eval(myWidth);
						myOuterHeight = eval(myHeight)+32;
						myHeight = eval(myHeight)+15;
						break;
					case 'mpeg':
					case 'mpg':
					case 'wmv':
						myOuterWidth = eval(myWidth)-30;
						myOuterHeight = eval(myHeight)+32;
						myWidth = eval(myWidth)-30;
						myHeight = eval(myHeight)+15;
						break;
					case 'swf':
					case 'flv':
					case 'mp3':
						myOuterWidth = eval(myWidth);
						myOuterHeight = eval(myHeight)+18;
						break;
					default:
						myOuterWidth = eval(myWidth);
						myOuterHeight = eval(myHeight);
						break;
				}
				break;
			}
		case 'Safari':
			switch(myType)
			{
				case 'mov':
					myOuterWidth = eval(myWidth);
					myHeight = eval(myHeight)+15;
					myOuterHeight = eval(myHeight);
					break;
				case 'mpeg':
				case 'mpg':
				case 'wmv':
					myWidth = eval(myWidth)-32;					
					myOuterWidth = eval(myWidth);
					myHeight = eval(myHeight)+15;
					myOuterHeight = eval(myHeight)+1;
					break;
				case 'swf':
				case 'flv':
				case 'mp3':
					myOuterWidth = eval(myWidth);
					myOuterHeight = eval(myHeight)+1;
					break;
				default:
					myOuterWidth = eval(myWidth);
					myOuterHeight = eval(myHeight);
					break;
			}
			break;
	}
	
	myDimensions = new Array(myWidth,myHeight,myOuterWidth,myOuterHeight);
	return myDimensions;
}

//Browser detection
function getBrowser()
{
	var agt = navigator.userAgent.toLowerCase();

	if (agt.indexOf("opera") != -1) return 'Opera';
	if (agt.indexOf("staroffice") != -1) return 'Star Office';
	if (agt.indexOf("webtv") != -1) return 'WebTV';
	if (agt.indexOf("beonex") != -1) return 'Beonex';
	if (agt.indexOf("chimera") != -1) return 'Chimera';
	if (agt.indexOf("netpositive") != -1) return 'NetPositive';
	if (agt.indexOf("phoenix") != -1) return 'Phoenix';
	if (agt.indexOf("firefox") != -1) return 'Firefox';
	if (agt.indexOf("safari") != -1) return 'Safari';
	if (agt.indexOf("skipstone") != -1) return 'SkipStone';
	if (agt.indexOf("msie") != -1) return 'Internet Explorer';
	if (agt.indexOf("netscape") != -1) return 'Netscape';
	if (agt.indexOf("mozilla/5.0") != -1) return 'Mozilla';
}