//flash
function EmbedFlash(file,width,height,doc_id,media_id){
	
	var hasRightVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
	
	if(hasRightVersion) {  // if we've detected an acceptable version
	    var oeTags = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" '
	    + 'width="'+width+'" height="'+height+'" '
	    + 'codebase="http://download.macromedia.com/pub/shockwave/cabsswflash.cab">'
	    + '<param name="movie" value="'+file+'" /><param name="menu" value="false" /><param name="quality" value="high" /><param name="scale" value="noscale" /><param name="salign" value="t" /><param name="wmode" value="transparent" /><param name="bgcolor" value="#ffffff" />'
	    + '<embed id="theflash" src="'+file+'" menu="false" quality="high" scale="noscale" salign="t" wmode="transparent" bgcolor="#ffffff" '
	    + 'width="'+width+'" height="'+height+'" name="basis" align="middle" '
	    + 'play="true" '
	    + 'loop="true" '
	    + 'quality="high" '
	    + 'allowScriptAccess="sameDomain" '
	    + 'type="application/x-shockwave-flash" '
	    + 'pluginspage="http://www.macromedia.com/go/getflashplayer">'
	    + '</embed>'
	    + '</object>';
	    return(oeTags);   // embed the flash movie
  } else {  // flash is too old or we can't detect the plugin
	    var alternateContent = '<a href="'+(doc_id!=null?'/?id='+doc_id:'javascript:void(0)')+'"><img src="/media.php?id='+media_id+'" alt=""/></a>';
	    return(alternateContent);  // insert non-flash content
  }
}

//popup windows
var win=null;

//MSIE?
var bMSIE=(navigator.appVersion.indexOf("MSIE") != -1)?true:false;

if(document.getElementById) {
	window.getObj = function(id) {
		return document.getElementById(id);
	}
} else {
	window.getObj = function(id) {
		return false;
	}
}

function changeExternalLinkTarget() {
	if (document.links && document.links.length>0) {
		for (i=0;i<document.links.length;i++) {
			if (document.links[i].hostname != '' && (document.links[i].protocol=='http:' || document.links[i].protocol=='index.html') && document.links[i].hostname.toLowerCase().indexOf(document.location.hostname.toLowerCase())==-1){
				document.links[i].target = 'externalwebsite';
			}
		}
	}
}
function OpenWin(name,doc_id,unique){
	var width = 747;
	var height = 370;
	
	var iLeft = ( screen.width  - width ) / 2 ;
	var iTop  = ( screen.height - height ) / 2 ;

	var sOptions = "toolbar=no,status=no,scrollbars=no,resizable=no,dependent=yes" ;
	sOptions += ",width=" + width ;
	sOptions += ",height=" + height ;
	sOptions += ",left=" + iLeft ;
	sOptions += ",top=" + iTop ;
	
	win_local=window.open('/?id='+doc_id+(unique!=null?'&unique='+unique:''),name,sOptions);
	win_local.focus();
}

function OpenWin2(name,doc_id,width,height,unique){
	var iLeft = ( screen.width  - width ) / 2 ;
	var iTop  = ( screen.height - height ) / 2 ;

	var sOptions = "toolbar=no,status=no,scrollbars=no,resizable=no,dependent=yes" ;
	sOptions += ",width=" + width ;
	sOptions += ",height=" + height ;
	sOptions += ",left=" + iLeft ;
	sOptions += ",top=" + iTop ;
	
	win=window.open('/?id='+doc_id+(unique!=null?'&unique='+unique:''),name,sOptions);
	win.focus();
}

function CheckEmail(field){
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(document.getElementById(field).value)) return true;
	alert('Please fill in a valid e-mail address.');
	document.getElementById(field).focus();
	return false;	
}
function chkKeywords(){
	var f=document.getElementById('frmSearch');
	var field=f.keywords;
	
	if (field.value.replace(/[\s]/gi,'').length < 3){
		alert('Please enter at least 3 characters.');
		field.focus();
		return false;
	}
	return true;
}

function chkFrmNewsletter(){
	var frmNewsletter=document.getElementById('frmNewsletter');
	var name=document.getElementById('tName');
	var subject=frmNewsletter.elements['subject_id[]'];
	
	if (name.value.length==0){
		alert('Please fill in name.');
		name.focus();
		return;
	}
	
	if (!CheckEmail('tEmail')){
		return;
	}
	var bSubject=false;
	
	if(subject.length && subject.length>0){
		for (var i=0;i<subject.length;i++){
			if (subject[i].checked){
				bSubject=true;
				break;
			}
		}
		if (bSubject==false){
			alert('Please select subject.');
			return false;
		}
	} else {
		if (!subject.checked){ 
			alert('Please select subject.');
			return false;
		}
	}
	
	frmNewsletter.submit();
}

function chkFrmContact(){
	var frmContact=document.getElementById('frmContact');
	var name=document.getElementById('tName');
	var email=document.getElementById('tEmail');
	var country=document.getElementById('sCountry');
	var project=document.getElementById('sProject');
	
	if (name.value.length==0){
		alert('Please fill in name.');
		name.focus();
		return;
	}
	
	if (!CheckEmail('tEmail')){
		return;
	}
	
	if (country.selectedIndex==0){
		alert('Please select country.');
		country.focus();
		return;
	}
	if (project.selectedIndex==0){
		alert('Please select project.');
		project.focus();
		return;
	}
	
	frmContact.submit();
}

function chkFrmContact2(){
	var frmContact=document.getElementById('frmContact');
	var name=document.getElementById('tName');
	var email=document.getElementById('tEmail');
	var country=document.getElementById('tCountry');
	
	if (name.value.length==0){
		alert('Please fill in name.');
		name.focus();
		return;
	}
	if (!CheckEmail('tEmail')){
		return;
	}
	if (country.value.length==0){
		alert('Please fill in emirate/country.');
		country.focus();
		return;
	}
	
	frmContact.submit();
}

function chkFrmShare(){
	var frmShare=document.getElementById('frmShare');
	var name=document.getElementById('sendername');
	var email=document.getElementById('sharepage_email');
	var senderemail=document.getElementById('senderemail');
	
	if (!CheckEmail('email')){
		return;
	}
	if (name.value.length==0){
		alert('Please fill in name.');
		name.focus();
		return;
	}
	if (!CheckEmail('senderemail')){
		return;
	}
	
	frmShare.submit();
}


window.onunload=function(){
	if (win) win.close();
}