﻿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 CheckComment(btnID,txtEmailID,txtNameID, txtCommentID)
{
    var boolValid = true;
    
    ctrl_txtCommentID = document.getElementById(txtCommentID);
       
    if (ctrl_txtCommentID.value == "")
    {
        showMessage('يجب ان تملأ حقل الاسم','',txtCommentID);
        boolValid = false;
    }
    
    ctrl_txtNameID = document.getElementById(txtNameID);
       
    if ( boolValid == true &&  ctrl_txtNameID.value == "")
    {
        showMessage('يجب ان تملأ حقل الاسم','',txtNameID);
        boolValid = false;
    }
    
    if ( boolValid == true && (! CheckEmailInputComment(txtEmailID)) )
    { 
        boolValid = false;
    }
     
    if(boolValid)
    {
        document.getElementById(btnID).disabled = true;
        GetPostBackComent();
     }
    else
     document.getElementById(btnID).disabled = false;
    
}


function CheckEmailInputComment(txtID)
{
    var objTxt = document.getElementById(txtID)
    if(objTxt.value=="")
    {
        return false;
    }
   
    var re = new RegExp("\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*");
    if(!objTxt.value.match(re))
    {
        return false;
    }
    checkInjection(txtID);
    
     return true;
}

function SendFlashStyleCommand(ctrID, ItemBG_Color, PanelBG_Color)
{
    try{
	document.getElementById(ctrID.toString()).SetVariable("PanelBG".toString() , PanelBG_Color.toString() );
	document.getElementById(ctrID.toString()).SetVariable("ItemBG".toString() , ItemBG_Color.toString().toString() );
	}catch(er)
	{
	   /* alert(er + " ctrID: " + ctrID); */
	}
}

    
    
    
    
   //------------------------------------------------------------
    function Close_Form()
	{
		document.getElementById('regform1').style.display="none";
	}
	function show_From()
    {
	    document.getElementById('regform1').style.display="block";
}
function ClearForm()
{
        var elements = document.forms[0];
        for (var i = 0; i < elements.length; ++i)
        {
            var e = elements[i];
            if (e.type == "checkbox")
            e.checked = false;
            if (e.type == "text" || e.type == "password" )
            e.value = "";
        }
} 
function ShowHide(pass)
{
	var t = document.getElementById(pass);
	var d = t.style.display;

	if ("block"==d ) 
	{
		Hide(pass) 
	}
	else
	{
	Show(pass)
	}
}

function Hide(pass)
{
	document.getElementById(pass).style.display='none'; 
}

function Show(pass)
{
	document.getElementById(pass).style.display='block';
}



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 taLimit(link) {
	if (link.value.length==link.maxLength*1) return false;
}

function taCount(link, visCnt, intMaxLen) { 
    if (link.value.length > intMaxLen)
	{
	    link.value = link.value.substring(0, intMaxLen);
	}
	
	var mySpan =document.getElementById(visCnt);
	mySpan.innerHTML = intMaxLen - link.value.length;
	
}

function show_menu(pass)
{
    var totalOffset=0;
    //document.getElementById(pass).top = 
    //document.getElementById(pass).left = 345; 
    document.getElementById(pass).style.display='block';

}
function hide_menu(pass)
{
    document.getElementById(pass).style.display='none';

}




//--------------------------------------------------------


var strType ="self";
     
    function SetValueAndTabStyle(strKey, txtID ,link)
    {
       SetTabStyle(link);
       
       try{       
        Ctrl_txtID = document.getElementById(txtID);
        var tempValueCtrl= Ctrl_txtID.value;
       }catch(err)
       {
        Ctrl_txtID = txtID;
       }
       
       Ctrl_txtID.value = strKey;
       
    }
    /*--------*/
    function ClearAllTabsStyles(strTempExt)
    {
        document.getElementById(strTempExt + "tab_self").className ="";
        document.getElementById(strTempExt + "tab_maktoob").className ="";
        document.getElementById(strTempExt + "tab_internet").className  ="";
    }
    /*--------*/
    function SetTabStyle(link)
    {
      var strTempName = link.substring(link.search("tab_"));
      var strTempExt = link.substring(0,link.search("tab_"));
     
      
       ClearAllTabsStyles(strTempExt);
       document.getElementById(link).className  ="on"; 
       
      
       switch(strTempName)
       {
         case "tab_self":
          strType = "self";
            break;
        
        case "tab_maktoob":
          strType = "maktoob";
            break;
        
        
         case "tab_internet":
          strType = "internet";
            break;
       }
       
    }
    /*--------*/
    function GoSearch(txtID,SitePath)
     {
      try{       
        Ctrl_txtID = document.getElementById(txtID);
        var tempValueCtrl= Ctrl_txtID.value;
       }catch(err)
       {
        Ctrl_txtID = txtID;
       }
       
        if (Ctrl_txtID.value == "")
        {
            showMessage('يجب ان تملأ حقل البحث','', txtID);
            
        }else
        {

            window.location = SitePath + "SearchResults.aspx?Key=" + encodeURI(Ctrl_txtID.value)  + "&SearchType=" + strType;
        }
        
 
     }
    
//--------------------------------------------------------

   function checkInjection(txtID){try{ var strText = new String(); 
    try{ Ctrl_txtID = document.getElementById(txtID);  
    var tempValueCtrl= trim(Ctrl_txtID.value,''); }catch(err) 
    {  Ctrl_txtID = txtID; }  strText = trim(Ctrl_txtID.value,'');
    while(strText.indexOf("<") > -1 && strText.indexOf(">") > -1) 
    { strText = strText.replace("<",""); strText = strText.replace(">","");  }  
    while(strText.indexOf("<",0) != -1) { strText = strText.replace("<","&lt;"); } while(strText.indexOf(">",0) != -1) 
    {  strText = strText.replace(">","&gt;"); } strText = strText.replace("/","");document.getElementById(txtID).value = strText; }catch(err) {}}
     
   //--------------------------------------------------------

    
    // -----------------------
    // Open popUp window
       function popUpWithAttributes(URL,attributes) {
            day = new Date();
            id = day.getTime();
            eval("page" + id + " = window.open(URL, '" + id + "','" +  attributes +  "');");
        }
        
    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=250,height=270,left = 401,top = 273');");
}

function popUpwindow(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=1,scrollbars=1,location=1,statusbar=1,menubar=1,resizable=1,width=" + (screen.width - 10) + ",height=" + ( screen.availHeight - 5)  +",left = 0,top = 0');");
}   
// ------------------------------------------
// check if the textBox have numeric data 
 function IsNumeric(txtID)
   //  check for valid numeric strings 
   {
   var strString = document.getElementById(txtID).value;
   var strValidChars = "0123456789.-";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         document.getElementById('lara').innerHTML = 'Please Enter numeric'
         }
      }
   return blnResult;
   }
 
//--------------------------------------------------------
//changeFontSize
 
 var intDefaultFontSize = 11;
 var intMaxFontSize = 18;
 var intMinFontSize = 10;     
     
function changeFontSize(inc,strIDs)
{
    var strCookeName = "ArticleFontSize";
       
    var strIDs_array=strIDs.split(",");
    for(intCount=0; intCount<strIDs_array.length; intCount++) 
    { 
        var p;
        try{
        p = document.getElementById( strIDs_array[intCount] );
        }
        catch(err)
        {
        p = strIDs_array[intCount];
        }

        var strTempResult =ReadCookie(strCookeName);
        
        var size = intDefaultFontSize;
        if ( strTempResult != '')
        {
             size =strTempResult
        }
        else
        {
            if(p.style.fontSize) 
            {       
                size = parseInt(p.style.fontSize.replace("px", ""));
            } 
            else 
            {
                size = intDefaultFontSize;
            }    
        }
      
      
        if (eval(size) == -1)
        {   
            size = intDefaultFontSize;
           
        }
        else
        if (intMaxFontSize >= (eval(size)+eval(inc)))
        {
             if (intMinFontSize <= (eval(size)+eval(inc)))
            {
                size = eval(size)+eval(inc);
            }
             else
            {
                size = intMinFontSize;
            }
        }
        else
        {
            size = intMaxFontSize;
        }
        
      
        p.style.fontSize =  size + 'px';   
        StoreCookie(strCookeName,size,30);
        
    }
}

function Start(page) 
{
OpenWin = this.open(page, "CTRLWindow", "toolbar=No,menubar=No,location=No,scrollbars=YES,resizable=NO,width=530,height=350");
}

 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";
        }
    }
    
    
    
    //------------------------------------------------
    // Using Cookies
  
 // VALUE="store_cookie" Store Cookie
 // VALUE="show_cookie"  Show Cookie
 // VALUE="expire_cookie" Expire Cookie
 // VALUE="show_all_cookies" Show All cookies
     
 
  // Global variables 
  var cv;                          // Value of my cookie
  var myCookie;                        // Name of my cookie
  var allCookies;                       // Gets all cookies 

  function expireDate( nDays ) {       //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     // nDays                          // No. of days in future to expire 
     var one_second = 1000 ;            // 1 sec = 1000 milliseconds
     var one_hour   = 3600 * one_second;
     var one_day    = 24 * one_hour;
     var expire     = new Date( (new Date()).getTime() + nDays*one_day) ;
     return           expire.toGMTString();    // Time to expire cookie
  }  

  // Extracts 1st substring in 'myString' bounded by 'delim1' and 'delim2'
  // It is OK if the 'delim2' is missing
  function extractSubstring( myString, delim1, delim2 ) {
      var substr1 = myString.split( delim1 );
          if ( substr1 == myString ) return -1 ;    // delim1 not found
      var substr2 = substr1[1].split( delim2 );
      var len1 = substr1[0].length + delim1.length;
      var len2 = substr2[0].length;
      return myString.substring( len1, len1+len2 );
  } 


  function StoreCookie( myCookie , cv,  nDays, strIFrameID) { 
    var cookie = myCookie + '=' + cv + '; expires=' + expireDate(nDays) ;
    
    if( strIFrameID == '' || strIFrameID == null  || strIFrameID == 'undefined' )
    {
        document.cookie = cookie;
    }
    else
    {
        self.parent.document.cookie = cookie;
    }
  }  

 function ReadCookie( myCookie, strIFrameID ) { 
    if( strIFrameID == '' || strIFrameID == null  || strIFrameID == 'undefined' )
    {
         allCookies = document.cookie;
    }
    else
    {
        allCookies = self.parent.document.cookie;
    }
    
    return extractSubstring( allCookies, myCookie+'=', ';' );
 } 
 
 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 AlertsSub(txtID,regxID,strURL)
{

    var objTxt = document.getElementById(txtID);
    if(objTxt.value=="")
    {
        showMessage("الرجاء إدخال البريد الإلكتروني",'',txtID);
        return false;
    }
   var txt_Reg = document.getElementById(regxID);
    var re = new RegExp(txt_Reg.value);
    if(!objTxt.value.match(re))
    {
        showMessage("الرجاء إدخال بريد إلكتروني صحيح",'',regxID );
        return false;
    }
   // checkInjection(txtID);
       
    /*  self.location.href= strURL + "/Alerts.htm?Email=" + objTxt.value; */

    return true;
} 



function CookingAlertsSub(txtID,regxID)
{
    var objTxt = document.getElementById(txtID);
    if(objTxt.value=="")
    {
        showMessage("الرجاء إدخال البريد الإلكتروني",'',txtID);
        return false;
    }
    var txt_Reg = document.getElementById(regxID)
    var re = new RegExp(txt_Reg.value);
    if(!objTxt.value.match(re))
    {
        showMessage("الرجاء إدخال بريد إلكتروني صحيح",'',regxID);
        return false;
    }
   
   /* var strSiteURL = window.location.href.substring(0,window.location.href.lastIndexOf('/'));
    self.location.href= strSiteURL + "/Alerts.htm?Email=" + objTxt.value; */

    return true;
} 

    function checkSelectedAlerts(){
        var items = document.getElementsByTagName('input');
        var i=0;
        for (i=0;i<items.length;i++)
        {
            if (items[i].type == "checkbox") 
                if (items[i].checked == true) 
                    return true;
        }
        showMessage('يجب ان تتختار قناة واحدة على الاقل');
        return false;
    }

  function LoginChat(QS_RoomName, defaultRoomName, ddlID, txtID, strChatURL){
    
         var Ctrl_txtID = document.getElementById(txtID);
         var Ctrl_ddlID = document.getElementById(ddlID);

         if (Ctrl_txtID.value  == ""){
             showMessage('يجب ان تملأ اسم الدخول ','',txtID);
             return false;
         }else{
	var strRoom ='';
	var strNeckName=Ctrl_txtID.value;
	
	if(QS_RoomName!='')
	{
		strRoom = QS_RoomName;
	}
	else if(Ctrl_ddlID.selectedIndex != -1)
	{
		strRoom = Ctrl_ddlID.options[Ctrl_ddlID.selectedIndex].value;
	}
	else
	{
		strRoom = defaultRoomName;
	}
	
           strChatURL += '?ChatRoom=' + strRoom + '&NeckName=' + strNeckName;
            viewLogin('','', strChatURL,strChatURL,'Chat');
            return false;        
         }
    }  


  function LoginChatCheck(txtID){
         var Ctrl_txtID = document.getElementById(txtID);
         if (Ctrl_txtID.value  == ""){
             showMessage('يجب ان تملأ اسم الدخول ','',txtID);
             return false;
         }else{
            
             return true;        
         }
    } 
    
    
//--------------------------------------------------------
function taLimit(link) {
	if (link.value.length==link.maxLength*1) return false;
}

function taCount(link, visCnt, intMaxLen) { 
    if (link.value.length > intMaxLen)
	{
	    link.value = link.value.substring(0, intMaxLen);
	}
	
	var mySpan =document.getElementById(visCnt);
	mySpan.innerHTML = intMaxLen - link.value.length;
	
}
//--------------------------------------------------------
function ReadOnlytxt(txtID,num)
{
if (num == 1)
{
document.getElementById(txtID).disabled=true;
}
else
{
document.getElementById(txtID).disabled=false;
}
}

function SearchShow(){
   document.getElementById('Sdiv').style.display ="block";       
   document.getElementById('adSdiv').style.display ="none";       
}
function AdvanceSearchShow(){
   document.getElementById('Sdiv').style.display ="none";       
   document.getElementById('adSdiv').style.display ="block";       
}

 function changeselect(txtID,num)
   {
   if ( num == 1 )
   {
   document.getElementById(txtID).disabled=true;
   document.getElementById(txtID).value='';
   }
   if ( num == 2 )
   {
   document.getElementById(txtID).disabled=false;
   }
   }
         
   function isNumeric(val){return(parseFloat(val,10)==(val*1));}
   
   function isBlank(val){
	if(val==null){return true;}
	for(var i=0;i<val.length;i++) {
		if ((val.charAt(i)!=' ')&&(val.charAt(i)!="\t")&&(val.charAt(i)!="\n")&&(val.charAt(i)!="\r")){return false;}
		}
	return true;
	}
	

  
   
   function ValidatePage(txt1ID,txt2ID,txt3ID,txt4ID,txt5ID,txt6ID,txt7ID)
   {
   var t1 = document.getElementById(txt1ID).value;
   var t2 = document.getElementById(txt2ID).value;
   var t3 = document.getElementById(txt3ID).value;
   var t4 = document.getElementById(txt4ID).value;
   var t5 = document.getElementById(txt5ID).value;
   var t6 = document.getElementById(txt6ID).value;
   var t7 = document.getElementById(txt7ID).value;
   var flag = true ;
  
   if ( isBlank(t1) == true )
   {
   showMessage(" * يرجى ادخال اسم المرشحة",'',txt1ID);
   return  false;
   }
   if  ( isBlank(t2) == true && document.getElementById(txt2ID).disabled == false )
   {
   showMessage("يرجى ادخال اسم المدخلة * ",'',txt2ID);
  return  false;
   }
   if  ( isBlank(t3) == true )
   {
   showMessage("* يرجى ادخال المهنة",'',txt3ID);
   return  false;
   }
   if  ( isBlank(t4) == true )
   {
   showMessage(" * يرجى ادخال رقم الهاتف",'',txt4ID);
      return  false;
   }
   if ( isNumeric(t4) == false )
   {
   showMessage(" * يرجى ادخال رقم للهاتف",'',txt4ID);
   return  false;
   }
   if ( isBlank(t5) == true )
   {
   showMessage("  * يرجى ادخال كود البلد",'',txt5ID);
   return  false;
   }
   if ( isNumeric(t5) == false )
   {
   showMessage(" * يرجى ادخال رقم لكود البلد",'',txt5ID);
   return  false;
   }
   if  ( isBlank(t6) == true )
   {
   showMessage("  * يرجى ادخال السيرة الذاتية ",'',txt6ID);
   return  false;
   }
   if  ( isBlank(t7) == true )
   {
   showMessage("  * يرجى ادخال الأرقام و الأحرف في الصورة ",'',txt7ID);
   return  false;
   }
  
   return true;
   
   }
   
   function checkStatus(txtID)
   {
   if ( document.getElementsByID('Radio1').checked == true )
   {
   document.getElementsByID(txtID).disabled = false ;
   }
   if (document.getElementsByID('Radio2').checked == true)
   {
   document.getElementsByID(txtID).disabled = true ;
   }
   
   }


  function Change(CtrID,id){
      for (var i = 1; i<=5;i++){
            var obj = new String(CtrID+i);
            document.getElementById(obj).style.backgroundColor = "#fff";
       } 
       for (var i = 1; i<=id;i++){
            var obj = new String(CtrID+i);
            document.getElementById(obj).style.backgroundColor = "Orange";
        }
    }
    function messageRated(){
        showMessage('لقد تم تقيم هذا المقال');
        return false;
    }

//-----------------------------------------------
function viewJsPanel(panID)
{
try{
   var divObj = document.getElementById(panID);
   if(divObj!=null)
   {
   divObj.style.width = eval(screen.width)  + "px"
   divObj.style.height = eval(screen.height) + "px"
   }
   }catch(err)
   {   }
   
  
}
//-----------------------------------------------
// used to validate Names and Meanings Search that the user inserts a name or chooses a letter
function validName(rID,txtID)
	{
	var txt = document.getElementById(txtID).value;
	var r = document.getElementById(rID);
	var x = r.selectedIndex;
		if (txt.length > 0)
	{
	return true;
	}
	else if ( x > 0)
	{
	return true;
	}
	else
	{
	document.getElementById('divMsg').innerHTML = 'أرجوا ادخال إسم او اختيار حرف';
	return false;
	}
	}
	//--------------------------------------------------------
	function checkChars(txtID)
{
 var strText = new String();  
 strText = document.getElementById(txtID).value; 
   
        while(strText.indexOf("*") > -1 || strText.indexOf("%") > -1 || strText.indexOf("/") > -1
        || strText.indexOf("\\") > -1 || strText.indexOf("#") > -1 || strText.indexOf("$") > -1
        || strText.indexOf("@") > -1 || strText.indexOf("!") > -1 || strText.indexOf("?") > -1
        || strText.indexOf("^") > -1 || strText.indexOf("(") > -1|| strText.indexOf(")") > -1
        || strText.indexOf("+") > -1 || strText.indexOf("=") > -1 || strText.indexOf("|") > -1
        || strText.indexOf(";") > -1 || strText.indexOf(":") > -1 || strText.indexOf("{") > -1
        || strText.indexOf("}") > -1 || strText.indexOf("[") > -1 || strText.indexOf("]") > -1
        || strText.indexOf(",") > -1 || strText.indexOf(".") > -1 || strText.indexOf("~") > -1
        || strText.indexOf("1") > -1 || strText.indexOf("2") > -1 || strText.indexOf("3") > -1 
        || strText.indexOf("4") > -1  || strText.indexOf("5") > -1 || strText.indexOf("6") > -1 
        || strText.indexOf("7") > -1  || strText.indexOf("8") > -1 || strText.indexOf("9") > -1  
        || strText.indexOf("0") > -1 )
        {
            strText = strText.replace("*","");
            strText = strText.replace("%","");
            strText = strText.replace("/","");
            strText = strText.replace("\\","");
            strText = strText.replace("#","");
            strText = strText.replace("$","");
            strText = strText.replace("^","");
            strText = strText.replace("&","");
            strText = strText.replace("!","");
            strText = strText.replace("(","");
            strText = strText.replace(")","");
            strText = strText.replace("{","");
            strText = strText.replace("}","");
            strText = strText.replace("[","");
            strText = strText.replace("]","");
            strText = strText.replace(";","");
            strText = strText.replace(":","");
            strText = strText.replace(",","");
            strText = strText.replace("'","");
            strText = strText.replace(".","");
            strText = strText.replace(" ","_");
            strText = strText.replace("-","");
            strText = strText.replace("~","");
            strText = strText.replace("?","");
            strText = strText.replace("=","");
            strText = strText.replace("+","");
            strText = strText.replace("@","");
            strText = strText.replace("0","");
            strText = strText.replace("1","");
            strText = strText.replace("2","");
            strText = strText.replace("3","");
            strText = strText.replace("4","");
            strText = strText.replace("5","");
            strText = strText.replace("6","");
            strText = strText.replace("7","");
            strText = strText.replace("8","");
            strText = strText.replace("9","");   
                     
        }
        document.getElementById(txtID).value = strText;
                
     }

/****************************************************************/


function validateLongText(txtCommentID)
{

    var strComment = new String(document.getElementById(txtCommentID).value);
    if(strComment.split(" ").length==1)
    {
        if(strComment.length<55)return true;
        document.getElementById("longTextValid").innerHTML = "النص غير صحيح";
        return false;
    }
    for(var i=0;i<strComment.split(" ").length;i++)
    {
        if(strComment.split(" ")[i].length>55)
        {
            document.getElementById("longTextValid").innerHTML = "النص غير صحيح";
            return false;
        }
    }
    return true;
    
}

/****************************************************************/
/*function whichButton(event,txtID,ddlID)
{
if(event.keyCode==13)
{
checkInjection(txtID);
checkChars(txtID);
validName(ddlID,txtID);
}
}*/

function clickNameSearch(e, buttonid){ 
    var bt = document.getElementById(buttonid); //buttonid); 
	if (typeof bt == 'object'){ 
			if(navigator.appName.indexOf("Netscape")>(-1)){ 
				if (e.keyCode == 13){ 
						bt.click(); 
						return false; 
				} 
			} 
			if (navigator.appName.indexOf("Microsoft Internet Explorer")>(-1)){ 
				if (event.keyCode == 13){ 
						bt.click(); 
						return false; 
				} 
			} 
	} 
}
   //------------------------------------------------------------
   
function uncheckAll(chkALID)
{
var checkAll =  document.getElementById(chkALID);
//alert(document.getElementsByTagName("input").length)
for (var i = 0; i < document.getElementsByTagName("input").length ; ++i)
{
//alert('in for');
if(document.getElementsByTagName("input")[i].type == "checkbox")
{
//alert('in if1');
//alert(document.getElementsByTagName("input")[i].checked)
if(document.getElementsByTagName("input")[i].checked == false)
{
//alert('in if2');
checkAll.checked = false;
}
}
}
}
function checkAll(chkID)
{
var chk = document.getElementById(chkID);
if ( chk.checked == true )
{
for (var i = 0; i < document.getElementsByTagName("input").length ; ++i)
{
//alert('in for');
if(document.getElementsByTagName("input")[i].type == "checkbox")
{
//alert('in if1');
//alert(document.getElementsByTagName("input")[i].checked)
document.getElementsByTagName("input")[i].checked = true;

}
}
}
if ( chk.checked == false )
{
for (var i = 0; i < document.getElementsByTagName("input").length ; ++i)
{
//alert('in for');
if(document.getElementsByTagName("input")[i].type == "checkbox")
{
//alert('in if1');
//alert(document.getElementsByTagName("input")[i].checked)
document.getElementsByTagName("input")[i].checked = false;

}
}
}
}

function messageRules(txt){
        showMessage(txt);
        return false;
    }
    ///////////////////////////////////////////////
 function showsearch()
 {
 document.getElementById('divSearching').style.display ="block";       
 document.getElementById('divbtn').style.display ="none";       
 }
 function Hidesearch()
 {
 document.getElementById('divSearching').style.display ="none";         
 }
 ////////////////////////////////////////////////////////////////
 function CookingSearch(txtID,SitePath,ddlName,ddlID)
     {
      try{       
        Ctrl_txtID = document.getElementById(txtID);
        var tempValueCtrl= Ctrl_txtID.value;
       }catch(err)
       {
        Ctrl_txtID = txtID;
       }
       
        if (Ctrl_txtID.value == "")
        {
            showMessage('يجب ان تملأ حقل البحث', '',txtID);
            return false;
        }else
        {
        var keyword = document.getElementById(txtID).value;
        var ddl = document.getElementById(ddlID);
        var Type = ddl.options[ddl.selectedIndex].value;
        window.location = SitePath + "Cooking/CookingSearch.htm?keyword=" + encodeURI(keyword) + "&Type=" + Type + "&ddlName=" + ddlName ;
        }
    
     }
     //////////////////////////////////////////////////////////////
     function changeBTNStyle(btnWsfatID ,btMediaID ,btnSearchID,btnMa2edahID,divnum)
     {
     var btnWsfat = document.getElementById(btnWsfatID);
     var btMediaID = document.getElementById(btMediaID);
     var btnSearchID = document.getElementById(btnSearchID);
     var btnMa2edahID = document.getElementById(btnMa2edahID);
     
     if(divnum == 1)
     {
     btnWsfat.className = "btn7 wite fnbld";
     btMediaID.className = "btn6 wite fnbld";
     btnSearchID.className = "btn6 wite fnbld";
     btnMa2edahID.className = "btn6 wite fnbld";
     } 
     if(divnum == 2)
     {
     btnWsfat.className = "btn6 wite fnbld";
     btMediaID.className = "btn7 wite fnbld";
     btnSearchID.className = "btn6 wite fnbld";
     btnMa2edahID.className = "btn6 wite fnbld";
     } 
     if(divnum == 3)
     {
     btnWsfat.className = "btn6 wite fnbld";
     btMediaID.className = "btn6 wite fnbld";
     btnSearchID.className = "btn7 wite fnbld";
     btnMa2edahID.className = "btn6 wite fnbld";
     } 
     if(divnum == 4)
     {
     btnWsfat.className = "btn6 wite fnbld";
     btMediaID.className = "btn6 wite fnbld";
     btnSearchID.className = "btn6 wite fnbld";
     btnMa2edahID.className = "btn7 wite fnbld";
     } 
     }
     //////////////////////////////
     function ShowCheckboxes(btnsID,RdID,num)
     {
     var divbtns = document.getElementById(btnsID);
     var divRadios = document.getElementById(RdID);
     
     if(num == 1)
     {
     divbtns.style.display ="none";
     divRadios.style.display ="block";
     }
      if(num == 2)
     {
     divbtns.style.display ="block";
     divRadios.style.display ="none";
     }
     
     }
///////////////////////////////////
function gotoComments(num)
{
if(num==1)
{
var txt1 = document.getElementById("ctl00_MidHolder_ctl00_Comments1_txtComment");
if(txt1!=null)
txt1.focus();
}
if(num==2)
{
var txt = document.getElementById("ctl00_ContentPlaceHolder1_ctl00_Comments1_txtComment");
if(txt!=null)
txt.focus();
}
}




/* --- validate date - start -------------------------------------------------------------------- */
var dID; var mID; var yID;
function checkCorrectDate(daysID,MonthsID,YearID, spanDateValidateID)
{
    dID=daysID;    mID=MonthsID;    yID=YearID;
    var ddlDays = document.getElementById(daysID);
    var ddlMonths = document.getElementById(MonthsID);
    var ddlYear = document.getElementById(YearID);
    var spanDateValidateValue = document.getElementById(spanDateValidateID);
    if (spanDateValidateValue != null)
     {spanDateValidateValue.innerHTML = "";}
    if(ddlDays.value==-1 || ddlMonths.value==-1 || ddlYear.value==-1)
    {
    if (spanDateValidateValue != null)
     {spanDateValidateValue.innerHTML="الرجاء إختيار تاريخ صحيح"; }
       showMessage("الرجاء إختيار تاريخ صحيح");
      return false;  }
    else
    {
        if( ValidateDate(ddlMonths.value,ddlDays.value,ddlYear.value) == false)
        { 
          if (spanDateValidateValue != null)
          {spanDateValidateValue.innerHTML="الرجاء إختيار تاريخ صحيح"; }
            showMessage("الرجاء إختيار تاريخ صحيح");
            return false; }
    }


	switch(ddlMonths.value)
	{
		case 2:
		    if(ddlYear.value%4!=0 && ddlDays.value>28)
			    { 
			    if (spanDateValidateValue != null)
			    {spanDateValidateValue.innerHTML="الرجاء إختيار تاريخ صحيح";}
			        showMessage("الرجاء إختيار تاريخ صحيح");
			     return false;	}
		    else
			    if(ddlDays.value>29)
				    { 
				      if (spanDateValidateValue != null)
				    {spanDateValidateValue.innerHTML="الرجاء إختيار تاريخ صحيح";}
				        showMessage("الرجاء إختيار تاريخ صحيح");
				    	return false; }
		break;
		case 4:	case 6:		case 9:		case 11:
			if(ddlDays.value==31)
			{	
			  if (spanDateValidateValue != null)
			{spanDateValidateValue.innerHTML="الرجاء إختيار تاريخ صحيح";}
			    showMessage("الرجاء إختيار تاريخ صحيح");
				return false;	}
		break;
	}
	return true;
}

var dtCh= "/";  var minYear=1900;   var maxYear=2100;
function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year)
{	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}

function DaysArray(n) 
{
	for (var i = 1; i <= n; i++) {
		this[i] = 31;
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30} if (i==2) {this[i] = 29}   } 
   return this;
}

function isDate(dtStr)
{
	var daysInMonth = DaysArray(12);
	var pos1=dtStr.indexOf(dtCh);
	var pos2=dtStr.indexOf(dtCh,pos1+1);
	var strMonth=dtStr.substring(0,pos1);
	var strDay=dtStr.substring(pos1+1,pos2);
	var strYear=dtStr.substring(pos2+1);
	strYr=strYear;
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1);
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1);
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1);
	}
	month=parseInt(strMonth);
	day=parseInt(strDay);
	year=parseInt(strYr);
	if (pos1==-1 || pos2==-1){
		//alert("The date format should be : mm/dd/yyyy")
		return false;
	}
	if (strMonth.length<1 || month<1 || month>12){
		//alert("Please enter a valid month")
		return false;
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		//alert("Please enter a valid day")
		return false;
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		//alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false;
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		//alert("Please enter a valid date")
		return false;
	}
return true
}

function ValidateDate(MM, DD, YYYY)
{
	var dt= MM + "/" + DD + "/" + YYYY;
	if (isDate(dt)==false)	{	return false;	}
    return true;
 }

/* --- validate date - end -------------------------------------------------------------------- */

function gotoo(strPageName)
{
   window.location = strHoroSiteUrl + strPageName;
}
/* ----------------------------------------------------------------------- */
function getYear(d) 
{ 
  return (d < 1000) ? d + 1900 : d;
}

function IsDate(year, month, day, avoidValue, strMsg) 
{

  if( year == avoidValue && month == avoidValue && day == avoidValue )
  {
    return true;
  }
  
  /* month argument must be in the range 1 - 12 */
  month = month - 1;  /* javascript month range : 0- 11 */
  var tempDate = new Date(year,month,day);
  if ( (getYear(tempDate.getYear()) == year) &&
     (month == tempDate.getMonth()) &&
     (day == tempDate.getDate()) )
      return true;
  else
   {
     showMessage(strMsg);
     return false;
   }
}

function selectDDl(ddlID,txt){ var ddl = document.getElementById(ddlID); if(ddl.selectedIndex == 0) { showMessage(txt); return false; } else { return true; } }

function GetLoveVal(ctrlYourName,ctrlLoveName)
{


        ctrl_YourName = document.getElementById(ctrlYourName);
        ctrl_LoveName = document.getElementById(ctrlLoveName);
       
        if(ctrl_YourName.value == "")
        { showMessage('يجب ان تملأ حقل اسمــــك','', ctrlYourName); return false; }
       
        if(ctrl_LoveName.value == "")
        { showMessage('يجب ان تملأ حقل اسـم من تحب','',  ctrlLoveName);  return false; }
		
         return true;  
}
function RTNLove(txtYourNameID,txtLoveNameID,LogicalRoot)
{
var txtYourName = document.getElementById(txtYourNameID).value;
var txtLoveName = document.getElementById(txtLoveNameID).value;
var flag = GetLoveVal(txtYourNameID,txtLoveNameID);
if(flag==true)
{
window.location = LogicalRoot + "حاسبة_الحب.htm" + "?YourName=" + encodeURI(txtYourName) + "&LoveName=" + encodeURI(txtLoveName);
}
else{return false;}
}
 
 function AlertBox(strIFrameID,txtNameID,txtEmailID,LogicalRoot)
 {
 var txtName = document.getElementById(txtNameID).value;
 var txtEmail = document.getElementById(txtEmailID).value;
 
 var flag = (Req(txtNameID,'يجب ان تملأ حقل اسمــــك',strIFrameID) && Req(txtEmailID,'يجب ان تملأ حقل بريدك الالكتروني',strIFrameID) && CheckEmailInput(txtEmailID,strIFrameID));
 
if(flag==true)
{
  strAlertBoxlocation = LogicalRoot + "حظك_مع_النجوم_على_بريدك.htm?utm_source=AbrajSite&utm_medium=Button&utm_campaign=Abraj+Button+footer&name=" + encodeURI(txtName) + "&UserEmail=" + encodeURI(txtEmail) ;
  if( strIFrameID == '' || strIFrameID == null  || strIFrameID == 'undefined' )
  {
    window.location = strAlertBoxlocation;
  }
  else
  {
    self.parent.window.location = strAlertBoxlocation;
  }
}
else{return false;}
}

function CheckCooki(strcooki,divID,strIFrameID)
{
var strCookiValue = ReadCookie(strcooki,strIFrameID) ;
if(strCookiValue!=-1) 
{
Hide(divID);
}
else
{
Show(divID);
}
}

function Req(txtID,txt,strIFrameID)
{

var inputtxt = document.getElementById(txtID);

if(inputtxt.value == '')
{
showMessage(txt,strIFrameID,txtID);
return false;
}
else
{
return true;
}
}



function CheckEmailInput(txtID, strIFrameID)
{
    var objTxt = document.getElementById(txtID)
    if(objTxt.value=="")
    {
        showMessage("الرجاء إدخال البريد الإلكتروني",strIFrameID,txtID);
        return false;
    }
   
    var re = new RegExp("\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*");
    if(!objTxt.value.match(re))
    {
        showMessage("الرجاء إدخال بريد إلكتروني صحيح",strIFrameID,txtID);
        return false;
    }
    checkInjection(txtID);
    
     return true;
}

function Hide(pass,strIFrameID)
{
    if( strIFrameID == '' || strIFrameID == null  || strIFrameID == 'undefined' )
    {
        document.getElementById(pass).style.display='none';
    }
    else
    {
        self.parent.document.getElementById(pass).style.display='none';
    }
}

function Show(pass,strIFrameID)
{
    if( strIFrameID == '' || strIFrameID == null  || strIFrameID == 'undefined' )
    {
        document.getElementById(pass).style.display='';
    }
    else
    {
        self.parent.document.getElementById(pass).style.display='';
    }
}