﻿var no_wmp = '<font face="Tahoma"><font size="2"><span lang="ar-sa">لا يمكن عرض المحطة لأنه<br></span>لا يوجد لديك برنامج <br><font color="#008000">Windows Media Player</font></font><br><a style="TEXT-DECORATION: none" href="http://download.microsoft.com/download/1/2/A/12A31F29-2FA9-4F50-B95D-E45EF7013F87/MP10Setup.exe"><font color="#FF0000" size="2">تستطيع تحميله من هنا</font></a></font><br></p>';
var no_real = '<font face="Tahoma"><font size="2"><span lang="ar-sa">لا يمكن عرض المحطة لأنه<br></span>لا يوجد لديك برنامج <br><font color="#008000">Real Player</font></font><br><a style="TEXT-DECORATION: none" href="http://software-dl.real.com/free/windows/RealPlayer10-5GOLD_bb.exe"><font color="#FF0000" size="2">تستطيع تحميله من هنا</font></a></font><br></p>';
var no_flash = '<font face="Tahoma"><font size="2"><span lang="ar-sa">لا يمكن عرض المحطة لأنه<br></span>غير مثبت لديك مشغل فلاش<br><font color="#008000">Adobe Flash Player</font></font><br><a style="TEXT-DECORATION: none" href="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash&Lang=English"><font color="#FF0000" size="2">تستطيع تنزيله من هنا</font></a></font><br></p>';
var loading = '<p dir="rtl"><font size="2" face="Tahoma">جاري التحميل</font></p>';
var http = createRequestObject();
function createRequestObject(){
    var req;
    var browser = navigator.appName;
    if(browser == "Microsoft Internet Explorer"){
        req = new ActiveXObject("Microsoft.XMLHTTP");
    }
    else{
        req = new XMLHttpRequest();
    }
    return req;
}

function viewmedia(sid, typ){
    doload(sid);
}

function viewmedia_detect(sid, typ){
    if ( typ == "wmp" )
	{
	
	if (detectWindowsMedia())
    {
    doload(sid);
	} else {
	document.getElementById('playdiv').innerHTML = no_wmp;
	}
	
	} else if ( typ == "real" )
	{
	
	if (detectReal() || detectRealOne())
    {
    doload(sid);
	} else {
	document.getElementById('playdiv').innerHTML = no_real;
	}
	
	} else {

	if (detectFlash())
    {
    doload(sid);
	} else {
	document.getElementById('playdiv').innerHTML = no_Flash;
	}

	}
}

function doload(sid){
    var baseurl = document.getElementById('baseurl').value;
	http.open('get', baseurl+'/index.php?act=play'+sid+'&nocache='+Math.random());
    http.onreadystatechange = handleInfo;
    http.send(null);
}

function inform(sid){
    var baseurl = document.getElementById('baseurl').value;
	http.open('get', baseurl+'/index.php?act=inform'+sid+'&nocache='+Math.random());
	document.getElementById('inform1').style.display = "none";
	document.getElementById('inform2').style.display = "";
    http.send(null);
}

function ToFriend(sid){
/*     http.open('get', 'index.php?act=inform'+ sid +'&nocache='+ Math.random());
	document.getElementById('inform1').style.display = "none";
	document.getElementById('inform2').style.display = "";
    http.send(null); */
	alert(sid);
}

function wopen( url, target, w, h, asize, title, res, rett ) 	{
	if( !url ) {
		event.cancelBubble = true;
		event.returnValue = false;
		return;
	}
	if( !target ) target = '_blank';
	if( !w ) w = 500;
	if( !h ) h = 400
	if( !title ) title = '';

	w = parseInt( w, 10 );
	h = parseInt( h, 10 );
	if( asize ) asize = true;
	else asize = false;

	var aw = screen.availWidth;
	var ah = screen.availHeight;
	if( w > aw ) w = aw;
	if( h > ah ) h = ah;

	var left = Math.round( ( aw - w ) / 2 );
	var top = Math.round( ( ah - h ) / 2 );

	var wd = window.open( url, target, 'channelmode= 0, directories=0, height='+h+'px, width='+w+'px, location=0, menubar=0, resizable='+res+', scrollbars=0, status=0, toolbar=0, top='+top+'px, left='+left+'px' );
	if ( !asize ) { 
		if( rett )return wd; 
		else return false;
	}

	if( url.indexOf( window.location.host ) != -1 || url.indexOf( 'http://' ) == -1  ) wd.attachEvent( "onload", function() {resize_new_win( wd, asize, title )	} );
	//if( rett )return wd; 
}

function uninform(sid){
    http.open('get', 'index.php?act=uninform'+ sid +'&nocache='+ Math.random());
	document.getElementById('uninform').disabled = "disabled";
    http.send(null);
}

function handleInfo(){
    if(http.readyState == 1){
        document.getElementById('playdiv').innerHTML = loading;
    }
    if(http.readyState == 4){
        var response = http.responseText;
        document.getElementById('playdiv').innerHTML = response;
    }

}





function detectFlash() {
if ((navigator.appName == "Microsoft Internet Explorer" &&
    navigator.appVersion.indexOf("Mac") == -1 &&   navigator.appVersion.indexOf("3.1") == -1) ||

    (navigator.plugins && navigator.plugins["Shockwave Flash"])
                       || navigator.plugins["Shockwave Flash 2.0"]){

   //Load a pre-defined HTML page with Flash Player in it into the browser window.
    return true;
}
else {
    //Load a pre-defined HTML page without Flash Player into the browser window.
    return false;
}
}

// -----------------------------------------------------------------------------------
var detectableWithVB = false;
var pluginFound = false;


function canDetectPlugins() {
	if ( detectableWithVB || (navigator.plugins && navigator.plugins.length > 0) ) {
		return true;
	}
	return false;
}

function detectReal() {
	pluginFound = detectPlugin( 'RealPlayer' );
	// if not found, try to detect with VisualBasic
	if ( !pluginFound && detectableWithVB ) {
		pluginFound = ( detectActiveXControl('rmocx.RealPlayer G2 Control') ||
			detectActiveXControl('RealPlayer.RealPlayer(tm) ActiveX Control (32-bit)') ||
			detectActiveXControl('RealVideo.RealVideo(tm) ActiveX Control (32-bit)')
		);
	}
	return pluginFound;
}

function detectRealOne() {
	pluginFound = detectPlugin( 'RealOne Player Version Plugin' ) || detectPlugin( 'RealPlayer Version Plugin' );
	// if not found, try to detect with VisualBasic
	if ( !pluginFound && detectableWithVB ) {
		pluginFound = detectRealOneActiveXControl();
	}
	return pluginFound;
}

function detectWindowsMedia() {
	pluginFound = detectPlugin( 'Windows Media' );
	// if not found, try to detect with VisualBasic
//	if ( !pluginFound && detectableWithVB ) {
//		pluginFound = detectActiveXControl( 'MediaPlayer.MediaPlayer.1' );
//	}
	if ( !pluginFound && detectWMPSupport() ) {
		pluginFound = true;
	}
	return pluginFound;
}

function detectWMPSupport(){

    var wmp64 = "MediaPlayer.MediaPlayer.1";
    var wmp7 = "WMPlayer.OCX.7";
    if((window.ActiveXObject && navigator.userAgent.indexOf('Windows') != -1) || window.GeckoActiveXObject)
    {
        if(createActiveXObject(wmp7)){ 
            return true;

        }else{
            if(createActiveXObject(wmp64)){
                return true;
            }else{
                return false;
            }
        }
    }else{ 
        return false;
    }
}

function createActiveXObject(id){
  var error;
  var control = null;

  try{
    if (window.ActiveXObject){
      control = new ActiveXObject(id);
    }else if (window.GeckoActiveXObject){
      control = new GeckoActiveXObject(id);
    }
  }
  catch (error){;}
  return control;
}

function detectPlugin() {
	// allow for multiple checks in a single pass
	var daPlugins = arguments;
	// consider pluginFound to be false until proven true
	var pluginFound = false;
	// if plugins array is there and not fake
	if ( navigator.plugins && navigator.plugins.length > 0 ) {
		var pluginsArrayLength = navigator.plugins.length;
		// for each plugin...
		for ( var pluginsArrayCounter = 0; pluginsArrayCounter < pluginsArrayLength; pluginsArrayCounter++ ) {
			// loop through all desired names and check each against the current plugin name
			var numFound = 0;
			for ( var namesCounter = 0; namesCounter < daPlugins.length; namesCounter++ ) {
				// if desired plugin name is found in either plugin name or description
				if ( (navigator.plugins[pluginsArrayCounter].name.indexOf(daPlugins[namesCounter]) >= 0) ||
					(navigator.plugins[pluginsArrayCounter].description.indexOf(daPlugins[namesCounter]) >= 0) ) {
					// this name was found
					numFound++;
				}
			}
			// now that we have checked all the required names against this one plugin,
			// if the number we found matches the total number provided then we were successful
			if ( numFound == daPlugins.length ) {
				pluginFound = true;
				// if we've found the plugin, we can stop looking through at the rest of the plugins
				break;
			}
		}
	}
	return pluginFound;
} // detectPlugin


// Here we write out the VBScript block for MSIE Windows
if ( (navigator.userAgent.indexOf('MSIE') != -1) && (navigator.userAgent.indexOf('Win') != -1) ) {
	document.writeln( '<script language="VBscript">' );

	document.writeln( '\'do a one-time test for a version of VBScript that can handle this code' );
	document.writeln( 'detectableWithVB = False' );
	document.writeln( 'If ScriptEngineMajorVersion >= 2 then' );
	document.writeln( '  detectableWithVB = True' );
	document.writeln( 'End If' );

	document.writeln( '\'this next function will detect most plugins' );
	document.writeln( 'Function detectActiveXControl( activeXControlName )' );
	document.writeln( '  on error resume next' );
	document.writeln( '  detectActiveXControl = False' );
	document.writeln( '  If detectableWithVB Then' );
	document.writeln( '     detectActiveXControl = IsObject( CreateObject( activeXControlName ) )' );
	document.writeln( '  End If' );
	document.writeln( 'End Function' );

	document.writeln( '\'and the following function handles QuickTime' );
	document.writeln( 'Function detectQuickTimeActiveXControl()' );
	document.writeln( '  on error resume next' );
	document.writeln( '  detectQuickTimeActiveXControl = False' );
	document.writeln( '  If detectableWithVB Then' );
	document.writeln( '    detectQuickTimeActiveXControl = False' );
	document.writeln( '    hasQuickTimeChecker = false' );
	document.writeln( '    Set hasQuickTimeChecker = CreateObject( "QuickTimeCheckObject.QuickTimeCheck.1" )' );
	document.writeln( '    If IsObject( hasQuickTimeChecker ) Then' );
	document.writeln( '      If hasQuickTimeChecker.IsQuickTimeAvailable( 0 ) Then ' );
	document.writeln( '        detectQuickTimeActiveXControl = True' );
	document.writeln( '      End If' );
	document.writeln( '    End If' );
	document.writeln( '  End If' );
	document.writeln( 'End Function' );

	document.writeln( '\'and the following function handles RealOne' );
	document.writeln( 'Function detectRealOneActiveXControl()' );
	document.writeln( '  on error resume next' );
	document.writeln( '  detectRealOneActiveXControl = False' );
	document.writeln( '  If detectableWithVB Then' );
	document.writeln( '    detectRealOneActiveXControl = False' );
	document.writeln( '    hasRealOneVersionPlugin = false' );
	document.writeln( '    Set hasRealOneVersionPlugin = CreateObject( "IERPCtl.IERPCtl.1" )' );
	document.writeln( '    If IsObject( hasRealOneVersionPlugin ) Then' );
	document.writeln( '      If hasRealOneVersionPlugin.RealPlayerVersion Then ' );
	document.writeln( '        detectRealOneActiveXControl = True' );
	document.writeln( '      End If' );
	document.writeln( '    End If' );
	document.writeln( '  End If' );
	document.writeln( 'End Function' );

	document.writeln( '<\/scr' + 'ipt>' );
}

// ________________________________________________________________ LaunchVideo

function disableSelection(target){
if (typeof target.onselectstart!="undefined") //IE route
	target.onselectstart=function(){return false}
else if (typeof target.style.MozUserSelect!="undefined") //Firefox route
	target.style.MozUserSelect="none"
else //All other route (ie: Opera)
	target.onmousedown=function(){return false}
target.style.cursor = "default"
}

function copy(inElement) {
    var flashcopier = 'flashcopier';
    if(!document.getElementById(flashcopier)) {
      var divholder = document.createElement('div');
      divholder.id = flashcopier;
      document.body.appendChild(divholder);
    }
    document.getElementById(flashcopier).innerHTML = '';
    var divinfo = '<embed src="images/_clipboard.swf" FlashVars="clipboard='+encodeURIComponent(inElement.value)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';
    document.getElementById(flashcopier).innerHTML = divinfo;
	alert('تم نسخ الكود \n\r لوضع المحطة بموقعك إستخدم هذا الكود');
}