﻿function ctrl(ctrlID) /* get the control by search in all frames  */
{   
    for(var i=0 ; i < window.frames.length ; i++ )
    {
        try{
            if(ctrlID == window.frames[i].document.getElementById(ctrlID).id)
              return window.frames[i].document.getElementById(ctrlID);
        }catch(er){}
    }
    return document.getElementById(ctrlID); 
}
/*-----------------------------------------*/
function ctrlTop(ctrlID) /* get the control in the main frame  */
{    return top.document.getElementById(ctrlID); }
/*-----------------------------------------*/
function IsEmptyOrNull(strValue) /* check the value if Empty Or Null */
{ 
    if( strValue == null || strValue == 'undefined' || strValue == '' || strValue == '\t' || strValue == '\n' || strValue == '\r' )
        return true;
   
    try
    {
        while(strValue.indexOf(' ') != -1)
        {    strValue = strValue.replace(' ', ''); }
    }catch(er){}    
        
    if( strValue.length == 0)
        return true;
  
    return false;
}
/*-----------------------------------------*/
function viewLogin(validState, strMSG, ReturnPath, ReturnPath2,ReturnPathType, RefreshLogin)
{
    show_LoginDiv();
    return false;
}
/*-----------------------------------------*/
function ltrim(str) { 
 for(var k = 0; k < str.length && isWhitespace(str.charAt(k)); k++);
 return str.substring(k, str.length);
}
/*-----------------------------------------*/
function rtrim(str) {
 for(var j=str.length-1; j>=0 && isWhitespace(str.charAt(j)) ; j--) ;
 return str.substring(0,j+1);
}
/*-----------------------------------------*/
function trim(str) {
 return ltrim(rtrim(str));
}
/*-----------------------------------------*/
function isWhitespace(charToCheck)
{
 var whitespaceChars = " \t\n\r\f";
 return (whitespaceChars.indexOf(charToCheck) != -1);
}
/*-----------------------------------------*/
function TrimTxtCtrl(ctrlTxtID)
{
    try
    {
        var ctrlTxt = document.getElementById(ctrlTxtID);
        ctrlTxt.value = trim(ctrlTxt.value);
    }catch(er){};
}
/*-----------------------------------------*/  
function clickButton(e, buttonid)
{ 
    var bt = document.getElementById(buttonid); //buttonid); 
	if (typeof bt == 'object'){ 
			if(navigator.appName.indexOf("Netscape")>(-1)){ 
				if (e.keyCode == 13){
				        bt.focus();
				        bt.click(); 
				        return false; 
				} 
			} 
			if (navigator.appName.indexOf("Microsoft Internet Explorer")>(-1)){ 
				if (event.keyCode == 13){ 
				        bt.focus();
				        bt.click(); 
				      	return false; 
				} 
			} 
	} 
	
} 
/*-----------------------------------------*/
function checkInjection(txtID)
{
  var strText = new String();

  try{       
    Ctrl_txtID = document.getElementById(txtID);
    var tempValueCtrl= Ctrl_txtID.value;
   }catch(err){ Ctrl_txtID = txtID; }
   
    strText = Ctrl_txtID.value; 

    while(strText.indexOf("<") > -1 && strText.indexOf(">") > -1)
    {
        strText = strText.replace("<","");
        strText = strText.replace(">","");
    }
    
       while(strText.indexOf("<",0) != -1)
        { strText = strText.replace("<",""); }
        
        while(strText.indexOf(">",0) != -1)
        { strText = strText.replace(">",""); }
        
    document.getElementById(txtID).value = strText;
}
/*-----------------------------------------*/   
function hideDropDownList()
{   
    var items = document.getElementsByTagName('select');
    var i=0;
    for (i=0;i<items.length;i++)
    {
         items[i].style.display = "none";
    }
}
/*-----------------------------------------*/     
function showDropDownList()
{   
    var items = document.getElementsByTagName('select');
    var i=0;
    for (i=0;i<items.length;i++)
    {
         items[i].style.display = "block";
    }
}  
/*-----------------------------------------*/
function CheckEmailInput(txtID)
{
    var objTxt = document.getElementById(txtID)
    if(objTxt.value=="")
    {
        showMessage("الرجاء إدخال البريد الإلكتروني",'',txtID);
        return false;
    }
   
    var re = new RegExp("\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*");
    if(!objTxt.value.match(re))
    {
        showMessage("الرجاء إدخال بريد إلكتروني صحيح",'',txtID);
        return false;
    }
    checkInjection(txtID);
    
     return true;
}
/*-----------------------------------------*/
function CheckSearch(txtID)
{
    checkInjection(txtID);
    if( IsEmptyOrNull(ctrl(txtID).value) )
    {
        alert('الرجاء ادخال الكلمة او العبارة التي تيحث عنها');
        ctrl(txtID).focus();
        return false
    }
    
    return true;
}
    