﻿//*** this file for common methods 
//function AdjustScreen()
//{
//    if(screen.width>=800 && screen.width<1042)
//    {  
//        document.body.className="BodyClass";

//    }

//    if(screen.width>=1024 && screen.width<1152)
//    {  
//        document.body.className="BodyClass1";
//    }
//    if(screen.width>=1152 && screen.width<1280)
//    {
//        document.body.className="BodyClass2";
//    }
//    if(screen.width>=1280)
//    {
//        document.body.className="BodyClass3";
//    }
//}
    
// removes the target values for the bread crumb links
function RemoveBreadCrumbLinks(crumnContainerID) 
{
     var crumbContainer = document.getElementById('BreadCrumbContainer');

     // if bread crumb control exists on the current page
     if (crumbContainer != null) {
         // get all the bread crumb links
        var links = crumbContainer.getElementsByTagName('a')

         if (links != null) {

             // reset the target for each link
             for (var i = 0; i < links.length; i++) {
                 links[i].href = "#";
                 links[i].style.textDecoration = "none";
                 links[i].style.cursor = 'text';

             }
         }
     }
} 
     
function LanguageLinkAdjust() 
{   
	var englishVal = "/english/";
	var arabicVal = "/arabic/";                  
    if(document.location.href.toLowerCase().indexOf(englishVal) != -1)
	{
        //convert link to arabic 
        if(document.location.href.indexOf("resultadvancedsearch.aspx")!=-1)
        {
			document.getElementById('LanguageLink').href = "/arabic/";       	
        }
        else
        {
			//document.getElementById('LanguageLink').innerHTML='عربى';
			document.getElementById('LanguageLink').href = document.location.href.toLowerCase().replace(englishVal,arabicVal);
			//document.getElementById('LanguageLink').style.display="block";

			// if the corresponding url doesnt exist redirect to the listing page
			var correspondingURL = document.getElementById('LanguageLink').href;
			if (isThere(correspondingURL) == false) {

			    correspondingURL = correspondingURL.substring(0, LastIndexOf(correspondingURL, "/pages/"));
			    document.getElementById('LanguageLink').href = correspondingURL;
			}			                        
		}
	}
	else if(document.location.href.toLowerCase().indexOf(arabicVal) != -1)
    {
        if(document.location.href.indexOf("resultadvancedsearch.aspx")!=-1)
        {
			document.getElementById('LanguageLink').href = "/english/";       	
        }
        else
        {
	        //convert link to English
	        //document.getElementById('LanguageLink').innerHTML="English";
	        document.getElementById('LanguageLink').href = document.location.href.toLowerCase().replace(arabicVal,englishVal)
	        //document.getElementById('LanguageLink').style.display="block";

	        // if the corresponding url doesnt exist redirect to the listing page
	        var correspondingURL = document.getElementById('LanguageLink').href;
	        if (isThere(correspondingURL) == false) {

	            correspondingURL = correspondingURL.substring(0, LastIndexOf(correspondingURL, "/pages/"));
	            document.getElementById('LanguageLink').href = correspondingURL;
             }
                                  			                       
        }
    }
    else
    {
        //hide the link.
        document.getElementById('LanguageLink').style.display="none";
    }
}

function DeSelectTd(currentTD)
{
     currentTD.className="TopMenuBg";
     SelectedFn();
}
   
function SelectedFn(currenttd)
{
    // when on mouse out
   if(currenttd!=null)
   {
     currenttd.className="TopMenuBgSelected";
     return;
   }

    // selecting current
    if(document.getElementById('TopMenuID') != null)
    {
       var riyadh = document.URL.toLowerCase().indexOf('/alriyadh/');
       var jeddah = document.URL.toLowerCase().indexOf('/jeddah/');
       var dammam = document.URL.toLowerCase().indexOf('/dammam/');
       var alahasa = document.URL.toLowerCase().indexOf('/alahasa/');
       
       var tr = document.getElementById('TopMenuID');
         var Anchors = tr.getElementsByTagName('A');
         var Tds = tr.getElementsByTagName('td');
         
      
            if(riyadh!=-1)
            {
             document.getElementById("RiyadhTD").className= "TopMenuBgSelected";
            }
             if(jeddah!=-1)
            {
             document.getElementById("JeddahTD").className= "TopMenuBgSelected";
            }
             if(dammam!=-1)
            {
             document.getElementById("DammamTD").className= "TopMenuBgSelected";
            }
             if(alahasa!=-1)
            {
             document.getElementById("AhsaTD").className= "TopMenuBgSelected";
            }       
       }
}

 //**** This function is used to Adjust Site Menu
function AdjustSiteMenu()
{  
    var obj1 = document.body;
       
    //**** 1. Get All Tables & check of that include Navigations
    if(document.getElementsByTagName('table')!=null)
    {    
        var length=document.getElementsByTagName('table').length; 
        
        //*** Loop on Tables        
        for(index=0;index<length;index++)
        {   
            obj=document.getElementsByTagName('table')[index];  
            
            //**** 2. Get navigation TRs and check that it have subitems            
            var trsLength=obj.getElementsByTagName('tr').length;          
               
            for(loop=0;loop<trsLength;loop++)
            {                                  
                //**** Check If Tr has Divs with same name + 'Items' 
                if(document.getElementById(obj.getElementsByTagName('tr')[loop].id+'Items')!=null)
                {     
                    //*** shady & Basim code for making parent Menu is hovering while child is selected                              
                    document.getElementById(obj.getElementsByTagName('tr')[loop].id+'Items').onmouseover = new Function("if(document.getElementById(this.id.replace('Items', '')).className!='topNavSelected1'){document.getElementById(this.id.replace('Items', '')).className='topNavSelected';}");
                    document.getElementById(obj.getElementsByTagName('tr')[loop].id+'Items').onmouseout = new Function("if(document.getElementById(this.id.replace('Items', '')).className!='topNavSelected1'){document.getElementById(this.id.replace('Items', '')).className='topNavParentHover';}");	                                     								//alert(document.getElementById(obj.getElementsByTagName('tr')[loop].id+'Items').id + '##' + document.getElementById(obj.getElementsByTagName('tr')[loop].id+'Items').style.display);
              
                    //**** Get All its Child objects and disable them
                    ALength = obj.getElementsByTagName('tr')[loop].getElementsByTagName('A').length;                     
                   
                    for(j=0;j<ALength;j++)
                    {   
                        if(obj.getElementsByTagName('tr')[loop].getElementsByTagName('A')[j]!=null)
                        {   
                        
                            //**** Top Nav Item        
                            if(obj.getElementsByTagName('tr')[loop].getElementsByTagName('A')[j].className.indexOf('topNav')!=-1)
                            {                 
                                //shady updates started//                                
                                  var brURL = document.URL;
                                  pos = brURL.toLowerCase().indexOf('/pages');
                                  
                                  if(pos>=0)
                                    brURL = brURL.toLowerCase().substring(0,pos);
                                  
                                  
                                  var linkvalue= obj.getElementsByTagName('tr')[loop].getElementsByTagName('A')[j].href.replace('/Pages/default.aspx','');
                                  linkvalue = linkvalue.toLowerCase();                                        
                                 
                                  if (brURL.indexOf(linkvalue)>=0)                                          
                                  {                                       
                                        obj.getElementsByTagName('tr')[loop].className = "topNavSelected1";
                                  }
                                  
                                    obj.getElementsByTagName('tr')[loop].getElementsByTagName('A')[j].href='javascript:void(0)';                                    
                               //shady updates ended//
                            }
                        }
                    }
                }
                else
                {
                      //**** Get All its Child objects and disable them
                    ALength = obj.getElementsByTagName('tr')[loop].getElementsByTagName('A').length;                     
                   
                    for(j=0;j<ALength;j++)
                    {   
                        if(obj.getElementsByTagName('tr')[loop].getElementsByTagName('A')[j]!=null)
                        {   
                        
                            //**** Top Nav Item        
                            if(obj.getElementsByTagName('tr')[loop].getElementsByTagName('A')[j].className.indexOf('topNav')!=-1)
                            {
                                  var brURL = document.URL;
                                                                           
                                  var linkvalue= obj.getElementsByTagName('tr')[loop].getElementsByTagName('A')[j].href.toLowerCase();
                                                                                                                  
                                  if (brURL.toLowerCase().indexOf(linkvalue)>=0)                                          
                                  {                                       
                                        obj.getElementsByTagName('tr')[loop].className = "topNavSelected1";
                                  } 
                            }
                        }
                    }       
                }
            }        
        }
    }
}
