// start version 2.2
function GetXmlHttpObject(handler)
{
var objXmlHttp=null

if (navigator.userAgent.indexOf("Opera")>=0)
{
//alert("This example doesn't work in Opera")
return
}
if (navigator.userAgent.indexOf("MSIE")>=0)
{
var strName="Msxml2.XMLHTTP"
if (navigator.appVersion.indexOf("MSIE 5.5")>=0)
{
strName="Microsoft.XMLHTTP"
}
try
{
objXmlHttp=new ActiveXObject(strName)
objXmlHttp.onreadystatechange=handler
return objXmlHttp
}
catch(e)
{
//alert("Error. Scripting for ActiveX might be disabled")
return
}
}
if (navigator.userAgent.indexOf("Mozilla")>=0)
{
objXmlHttp=new XMLHttpRequest()
objXmlHttp.onload=handler
objXmlHttp.onerror=handler
return objXmlHttp
}
}

var xmlHttp




   function CheckAll() {

      for (var i=0;i<document.form.elements.length;i++) {
        var e = document.form.elements[i];
        if ((e.name != 'allbox') && (e.type=='checkbox')) {
          e.checked = document.form.allbox.checked;
        }
      }

    }


    function CheckCheckAll() {

      var TotalBoxes = 0;
      var TotalOn = 0;
      for (var i=0;i<document.form.elements.length;i++) {
        var e = document.form.elements[i];
        if ((e.name != 'allbox') && (e.type=='checkbox')) {
          TotalBoxes++;
          if (e.checked) {
            TotalOn++;
          }
        }
      }
      if (TotalBoxes==TotalOn) {
        document.form.allbox.checked=true;
      }
      else {
        document.form.allbox.checked=false;
      }
    }








function handleInfo(){

    if(http.readyState == 1){

        document.getElementById('mydiv').innerHTML = '...';

    }

    if(http.readyState == 4){

        var response = http.responseText;

        document.getElementById('mydiv').innerHTML = response;

    }

}



function Check_admin_fileds ( form )
{
  // ** START **
  if (form.adminname.value == "") {
    alert( "برجاء كتابة الاسم" );
    form.adminname.focus();
    return false ;
  }
   if (form.pass.value == "") {
    alert( "برجاء كتابة كلمة المرور" );
    form.pass.focus();
    return false ;
  }
  // ** END **
  return true ;
}

function check_login_fields() {
if (login.username.value == ""){
alert("برجاء كتابة الاسم");
login.username.focus();
return false;
}

if (login.pass.value == ""){
alert("برجاء كتابة كلمة المرور");
login.pass.focus();
return false;
}
}

function check_login_fields2() {
if (login2.username.value == ""){
alert("برجاء كتابة الاسم");
login2.username.focus();
return false;
}

if (login2.pass.value == ""){
alert("برجاء كتابة كلمة المرور");
login2.pass.focus();
return false;
}
}


function enable() {
document.form.delete1.disabled=false
}

function check_it() {
document.form.search_date.checked=true
}


function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=1,menubar=0,resizable=0,width=300,height=300,left = 476,top = 332');");
}










function ExpandCollapse(sDivIndex)
{
    if (document.getElementById("tablayer-result-" + sDivIndex).style.display == "block")
    {
        document.getElementById("tablayer-result-" + sDivIndex).style.display = "none";
        //document.getElementById("tablayer-result-lw-" + sDivIndex).style.display = "none";
        document.getElementById("imgExpandCollapse" + sDivIndex).src = "themes/newpower/images/icon_expand.gif";
    }
    else
    {
        document.getElementById("tablayer-result-" + sDivIndex).style.display = "block";
        //cument.getElementById("tablayer-result-lw-" + sDivIndex).style.display = "block";
        document.getElementById("imgExpandCollapse" + sDivIndex).src = "themes/newpower/images/icon_collapse.gif";
    }
}


function ExpandAll(max)
{
    var imgExpandAll = document.getElementById("imgExpandAll");
    var sDivState = "";
    var nLinkTop = document.getElementById("nextLinkTop");
    var nLinkBottom = document.getElementById("nextLinkBottom");
    var pLinkTop = document.getElementById("prevLinkTop");
    var pLinkBottom = document.getElementById("prevLinkBottom");

    if (imgExpandAll.src.indexOf("collapseall") > 0)
    {
        // do collapse all
        document.getElementById("imgExpandAll").src ="themes/newpower/images/icon_expand.gif";
        sDivState = "none"
        sExpandOrCollapse = "expand";

        // turn off expandAll tag
        if ( nLinkTop && nLinkBottom ) {
            if ( nLinkTop.href.indexOf("expandAll=1") > 0 ) {
                nLinkTop.href = nLinkTop.href.replace("expandAll=1", "expandAll=0");
                nLinkBottom.href = nLinkBottom.href.replace("expandAll=1", "expandAll=0");
            } else {
                nLinkTop.href += "&expandAll=0";
                nLinkBottom.href += "&expandAll=0";
            }
        }
        if ( pLinkTop && pLinkBottom ) {
            if ( pLinkTop.href.indexOf("expandAll=1") > 0 ) {
                pLinkTop.href = pLinkTop.href.replace("expandAll=1", "expandAll=0");
                pLinkBottom.href = pLinkBottom.href.replace("expandAll=1", "expandAll=0");
            } else {
                pLinkTop.href += "&expandAll=0";
                pLinkBottom.href += "&expandAll=0";
            }
        }
        if ( self.location.href.indexOf("expandAll=1") > 0 ) {
            self.location.href = self.location.href.replace("expandAll=1", "expandAll=0");
        }
    } else {
        // do expand all
        document.getElementById("imgExpandAll").src ="themes/newpower/images/icon_collapseall.gif";
        sDivState = "block"
        sExpandOrCollapse = "collapse";

        // turn on expandAll tag
        if ( nLinkTop && nLinkBottom ) {
            if ( nLinkTop.href.indexOf("expandAll=0") > 0 ) {
                nLinkTop.href = nLinkTop.href.replace("expandAll=0", "expandAll=1");
                nLinkBottom.href = nLinkBottom.href.replace("expandAll=0", "expandAll=1");
            } else {
                nLinkTop.href += "&expandAll=1";
                nLinkBottom.href += "&expandAll=1";
            }
        }
        if ( pLinkTop && pLinkBottom ) {
            if ( pLinkTop.href.indexOf("expandAll=0") > 0 ) {
                pLinkTop.href = pLinkTop.href.replace("expandAll=0", "expandAll=1");
                pLinkBottom.href = pLinkBottom.href.replace("expandAll=0", "expandAll=1");
            } else {
                pLinkTop.href += "&expandAll=1";
                pLinkBottom.href += "&expandAll=1";
            }
        }
        if ( self.location.href.indexOf("expandAll=0") > 0 ) {
            self.location.href = self.location.href.replace("expandAll=0", "expandAll=1");
        }
    }

    // update search result items
    for ( i=1; i<=max; i++ )
    {
        document.getElementById("tablayer-result-" + i).style.display = sDivState;
        document.getElementById("imgExpandCollapse" + i).src = "themes/newpower/images/icon_collapse.gif";
    }
}

function ExpandAllFlag(max) {
    if ( self.location.href.indexOf("expandAll=1") > 0 ) {
        ExpandAll(max);
    }
}

function Expand()
{

}

function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=838,height=628');");
}








function downloadNow(file,redUrl,extUrl) {
    var isIe = (window.navigator.userAgent.toUpperCase().indexOf('MSIE') != -1);
    var isOpera = (window.navigator.userAgent.toUpperCase().indexOf('OPERA') != -1);

    if (isIe && extUrl == 0 && !isOpera) {
        window.open(file,'dlnow','toolbar=0,location=no,directories=0,status=0, scrollbars=no,resizable=0,width=1,height=1,top=0,left=0');
        window.focus();
        location.href = redUrl + '?idl=n';
    } else {
        location.href = redUrl;
    }
}

function dlNow(file,redUrl,extUrl) {
    // skip if external url or old browser
   // if (extUrl == 0 && document.readyState) {
        // first try to download file in same window
   //     location.href = file;
        // mozilla readyState is always undefined
        // safari readyState is always complete
        // ie readyState is loading -> interactive -> complete
   //     if (document.readyState && document.readyState == 'loading') {
            // possible to detect when download dialog starts
            // check readyState every 250ms and
            // redirect to post download page with initiate download disabled
    //        setTimeout('dlComplete(\'' + redUrl + '%3Fidl=n\')', 250);
    //        return false;
    //    }
    //}
    // not possible to detect when download dialog starts
    // just follow href to post download page and let it initiate the download
    //location.href = redUrl;
    //return true;
    newDLNow(file,redUrl,extUrl);
    return false;
}

function dlComplete(redUrl) {
    if (document.readyState == 'loading') {
	/*window.onunload=function(){
		//alert("unloading in dlComplete: " + document.readyState);
		//if (document.readyState == 'loading') {
			// this means the file url is bad
			// redirect to post download page
			redUrl = redUrl.substring(0,redUrl.indexOf('%3Fidl=n'));
			location.href = redUrl;
		//}
	} */
        // still loading, check again in 250ms
        setTimeout('dlComplete(\'' + redUrl + '\')', 100);
    } else {
        // readyState = interactive or complete means download dialog started
        // redirect to post download page with initiate download disabled
        location.href = redUrl;
    }
}

function newDLNow(file,redUrl,extUrl) {
//file = "ftp://ftp.download.com/pub/ppd/10306590-10415721/htfireman20shasdsfdsfdreeng.exe";
    var isIe = (window.navigator.userAgent.toUpperCase().indexOf('MSIE') != -1);
    var isOpera = (window.navigator.userAgent.toUpperCase().indexOf('OPERA') != -1);

    if (isIe && extUrl == 0 && !isOpera) {
	myDLWindow = window.open(file,'_blank','toolbar=0,location=no,directories=0,status=0, scrollbars=no,resizable=0,width=0,height=0,top=0,left=0');
	//location.href = redUrl + '?idl=n';
    } else {
    	//alert('this is not ie, is an ext url, or is Opera');
        location.href = redUrl;
    }
}

//sniffs out Safari
        var isSafari=(navigator.userAgent.indexOf('Safari')>=0)?true:false;
        if (isSafari == true) {
        //alert("Safari");
        document.write("<style>#cobr-header #search-bar .search-fields .input-search {float: left; width: 100px; padding: 0; margin: 2px 5px 0 7px;}</style>");
        }


function submit_downloadform()
{
  document.addlink.submit();
}



function flyedit_download_cat(lid)
{
var url= "index.php?do=flyedit_download_cat&lid="+lid
xmlHttp=GetXmlHttpObject(stateChanged)
xmlHttp.open("GET", url , true)
xmlHttp.send(null)
}


function stateChanged()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{

document.getElementById("d_cid").innerHTML=xmlHttp.responseText
}
}

function j_xajax_show_cat_details(id){
myvar = '<img src="images/remembermilk_orange.gif" />'
div = "cat_details"+id
document.getElementById(div).innerHTML=myvar
xajax_show_cat_details(id)
}

function j_xajax_show_sub_cats(id){
myvar = '<img src="images/remembermilk_orange.gif" />'
div = "sub_cats"+id
document.getElementById(div).innerHTML=myvar
xajax_show_sub_cats(id)
}





function submitflyedit_download(field){

formname = "flyedit_download_form"+field
xajax_process_flyedit_download(xajax.getFormValues(formname));
return false;
}


function submitflyedit_download_cat(){
xajax_process_flyedit_download_cat(xajax.getFormValues("flyedit_download_form_cat"));
return false;
}



function checkEnter(e,id,value,action){ //e is event object passed from function invocation
var characterCode //literal character code will be stored in this variable

if(e && e.which){ //if which property of event object is supported (NN4)
e = e
characterCode = e.which //character code is contained in NN4's which property
}
else{
e = event
characterCode = e.keyCode //character code is contained in IE's keyCode property
}

if(characterCode == 13){ //if generated character code is equal to ascii 13 (if enter key)
//document.forms[0].submit() //submit the form

xajax_process_flyedit_cat_name(id,value,action);
return false
}
else{
return true
}

}


function submitfriend_message(id){
    formid = "tellfriend" + id
    xajax_process_friend_message(xajax.getFormValues(formid));
    return false;
}

function j_ajax_teelfriend(id,Text){
    //myvar = '<img src="images/remembermilk_orange.gif" />'
    //div = "t_friend"+id
    //document.getElementById(div).innerHTML=myvar
    //xajax_ajax_teelfriend(id)
    ID = "friendwin"+ id
    URL = "index.php?do=tellfriend&SimpleHeader=1&lid="+id
    CreateNewFWindowWH(URL,ID, Text,500,200)
    return false;
} 
 
 
function CreateNewFWindowWH(URL,ID, Text,Width,Height){
    if(URL==""){
        alert("Invalid URL")
        return false;
    }
    parent = window.parent;

    TheWinId = Ext.getCmp("thewindow"+ID)
    if(TheWinId){
        TheWinId.focus()
        TheWinId.setPosition(100,100)
        return false;
    }
    new Ext.Window({
    id:"thewindow"+ID,
    animCollapse:true,
    closable:true,
    collapsible:true,
    maximizable:true,
    autoScroll :true,
    title:Text,
    width:Width,
    height:Height,
    body: new Ext.ux.ManagedIFrame({autoCreate:{id:"MyFrame"+ID,cls:"x-window-body",width:"100%",height:"100%",src:URL}})
    }).show();

}
