﻿// JScript File
function load(imgLoad)
{
    var loader = document.getElementById(imgLoad);
    if (loader)
    {
       
        loader.style.display = "";
    }
}
function selectAllItems(chkAll, id) 
{
    var re = new RegExp(id);
    for(i = 0; i < document.forms[0].elements.length; i++) 
    {
        elm = document.forms[0].elements[i];
        if (elm.type == 'checkbox') 
        {
            if (re.test(elm.name)) 
            {
                elm.checked = chkAll.checked;
            }
        }
    }
}
 function SelectOne(rdo,gridName)
{
/* Getting an array of all the "INPUT" controls on the form.*/
 all=document.getElementsByTagName("input");
 for(i=0;i<all.length;i++)
 {
  if(all[i].type=="radio")/*Checking if it is a radio button*/
  {
       /*I have added '__ctl' ASP.NET adds '__ctl' to all 
       the controls of DataGrid.*/
       var count=all[i].id.indexOf(gridName); 
       if(count!=-1)
       {
            all[i].checked=false;
       }
  }
 }
 rdo.checked=true;/* Finally making the clicked radio button CHECKED */
}
function listen(evnt, elem, func) 
{
    if (elem.addEventListener) // W3C DOM
        elem.addEventListener(evnt,func,false);

    else if (elem.attachEvent) 
    { // IE DOM
        var r = elem.attachEvent("on"+evnt, func);
        return r;
    }
    else 
        window.alert('I\'m sorry Dave, I\'m afraid I can\'t do that.');
}
function chkAllImage(txtID,optional)
{
    var txt = document.getElementById(txtID)
    
    if(!optional)
    {
        if(txt.value=="")
        {
            alert("أختر ملف الصورة");
            txt.focus();
            return false;
        }
    }
    if(txt.value != "" )
    {
        var im = txt.value;
        if(im.indexOf(".") == -1)
        {
            alert("أختر ملف صحيح للصورة");
            txt.focus();
            return false;
        }
        var ext = im.substr(im.lastIndexOf(".")+1)
        ext = ext.toLowerCase();
        if( ext != "jpg" && ext != "gif" && ext != "jpeg" )
        {
            alert("أختر ملف صورة بأمتداد صحيح, الأمتدادات المسموح بها هي: jpg,gif,jpeg");
            txt.focus();
            return false;
        }
    }
    return true;
}     
function isNumberKey(evt)
{
    var charCode = (evt.which) ? evt.which : event.keyCode
    if (charCode > 31 && (charCode < 48 || charCode > 57))
        return false;

    return true;
}

function ToggleWindow(img,pnl)
{
    var p = document.getElementById(pnl);
    var i = document.getElementById(img);
    if( p.style.display == "none")
    {
        i.src=minus.src;
        p.style.display="";
    }
    else
    {
        i.src=plus.src;
        p.style.display="none";
    }
   
}
function chkPrice(id)
{
    var txt = document.getElementById(id);
    //alert("TXT: "+txt);
    if(!txt)
        return false;
    //alert("PARSE: "+parseFloat(txt.value));
    if(!parseFloat(txt.value) && parseFloat(txt.value) != 0)
    {
        //alert("GETTING OUT");
        return false;
    }
    var f = parseFloat(txt.value);
    //alert("F: "+f);
    if(f<0)
        return false;
    txt.value=f;
    return true;
}


function removeAllOptions(selectbox)
{
	var i;
	for(i=selectbox.options.length-1;i>=0;i--)
	{
		//selectbox.options.remove(i);
		selectbox.remove(i);
	}
}
function addOption(selectbox, value, text )
{
	var optn = document.createElement("OPTION");
	optn.text = text;
	optn.value = value;

	selectbox.options.add(optn);
}  

function checkItem(cntr)
{
    re = new RegExp("rdBodyStyle"); 
    for(i = 0; i < document.forms[0].elements.length; i++) 
    {
        elm = document.forms[0].elements[i];
        if (elm.type == 'radio') 
             elm.checked = false;
    }
    cntr.checked = true;
}
