



/*
 * Extended Functions
 */

function open_form (o,url,uri,width, height,refuri,refid) {

    if (uri) {
        if (uri == 'download') {
            var uri = refuri;
            var isProtected = getFile("/tpl/php_scripts/is_download_protected.php?id="+refid);
            if (!(isProtected == 1)) {
                window.location.href = url;
                return;
            }

        } else {
            var uri = url+'?uri="'+uri+'"';
        }

    } else {
        var parameter = o.options[o.selectedIndex].value;
        if (parameter == 'nothing') {
            var uri = parameter;
        } else {
            var uri = url+'?id='+parameter;
        }
    }

    if (!width) {
        var width = 320;
    }

    if (!height) {
        var height = 360;
    }

     if (refuri) {
        uri = uri + "&refuri=" + refuri + "";
    }

    if (uri != 'nothing') {
//alert( uri);

        $.modal("<iframe src='" + uri + "' width='305' height='360' style='border:0'>", {
            closeHTML:"",
            containerCss:{
                backgroundColor:"#fff",
                borderColor:"#fff",
                width:325,
                height:380,
                padding:10
            },
            overlayCss: {backgroundColor:"#000"},
            overlayClose:true
    
        });
    }

}

function open_form_old (o,url,uri,width, height,refuri,refid) {

    if (uri) {
        if (uri == 'download') {
            var uri = refuri;
            var isProtected = getFile("/tpl/php_scripts/is_download_protected.php?id="+refid);
            if (!(isProtected == 1)) {
                window.location.href = url;
                return;
            }

        } else {
            var uri = url+'?uri="'+uri+'"';
        }

    } else {
        var parameter = o.options[o.selectedIndex].value;
        if (parameter == 'nothing') {
            var uri = parameter;
        } else {
            var uri = url+'?id='+parameter;
        }
    }

    if (!width) {
        var width = 320;
    }

    if (!height) {
        var height = 360;
    }

     if (refuri) {
        uri = uri + "&refuri=" + refuri + "";
    }

    if (uri != 'nothing') {
        SqueezeBox.initialize({
            size: {x: 200, y: 200}
        });

        SqueezeBox.open (uri, {handler:'iframe',size:{x:width,y:height}});
    }

}

//simpleHttpRequest("/tpl/php_scripts/is_download_protected.php?id="+refid, uri);

function simpleHttpRequest(url,uri) {
    var request = makeHttpObject();

    request.open("GET", url, true);
    request.send(null);

    request.onreadystatechange = function() {

        if (request.readyState == 4) {
            if (request.status == 200) {
                security = request.responseText;

                if (security == 1) {
                    var userID='<?php echo $_SESSION["user"]; ?>';
                    if( userID =='')
                    {
                        alert("Please Login to enable download of this file.");
                        return false;
                    }
                }
                window.location.href = uri;
                return true;
            }
        }
    }
}
//alert('readyState='+request.readyState+', status='+request.status);


function makeHttpObject() {
  try {return new XMLHttpRequest();}
  catch (error) {}
  try {return new ActiveXObject("Msxml2.XMLHTTP");}
  catch (error) {}
  try {return new ActiveXObject("Microsoft.XMLHTTP");}
  catch (error) {}

  throw new Error("Could not create HTTP request object.");
}

function getFile(url) {
  if (window.XMLHttpRequest) {
    AJAX=new XMLHttpRequest();
  } else {
    AJAX=new ActiveXObject("Microsoft.XMLHTTP");
  }
  if (AJAX) {
     AJAX.open("GET", url, false);
     AJAX.send(null);
     return AJAX.responseText;
  } else {
     return false;
  }
}


