﻿// JScript File

function CheckSearchText()
 {
       
        if(document.getElementById(txtSearch1SiteSearch).value=="")
        {                
            //document.getElementById(lblSearchErrorMSG1).style.display = 'block';  
            return false;
        }
        else
        {
           //document.getElementById(lblSearchErrorMSG1).style.display = 'none';  
           return true;           
        }               
 }
 
//----showhide 'divPortalGroupList'-----------------
function ShowHide(divmenu)
{

//alert('dhf');
    var objYes = document.getElementById(divmenu);
    if(objYes != null && objYes.style.display =='none')
    {
        ShowHideDiv(1, divmenu)
    }
    else
    {
        ShowHideDiv(0, divmenu)
    }
}



//----showhide 'divPortalGroupList'-----------------

function ShowHideDiv(num, divmenu)
{

var objYes = document.getElementById(divmenu);
if(num == "0")
{
objYes.style.display="none";
}
else
{
if(screen.width==1024)
        {
        objYes.style.position="absolute";
        objYes.style.top="118px";
        objYes.style.left="692px";
        }
        if(screen.width==1280)
        {
        objYes.style.position="absolute";
        objYes.style.top="118px";
        objYes.style.left="820px";     
        }
objYes.style.display="block";
}
}





//-----------------------MasterDiv  Functions-----------------------------------------
function ShowHideMasterDiv()
{
  
    var objDiv= document.getElementById(MasterDivGray);
    if(objDiv != null)
    {
        if(objDiv.style.visibility=='visible')
        {
             objDiv.style.visibility = 'hidden';
        }
       else
       {
           objDiv.style.visibility ='visible';
       }
        SetMasterDivPosition(objDiv);
    }
    
}


function SetMasterDivPosition(objDiv)
{
    //Dhara:added for 
   if (window.innerHeight > 0 && window.scrollMaxY <= 0)
    { //firexox
       
         yWithScroll = window.innerHeight + "px"
         xWithScroll = window.innerWidth + "px";
        
    } 
    else if(window.scrollMaxY > 0)
    { //firexox
       
        yWithScroll = parseInt(window.innerHeight) + parseInt(window.scrollMaxY);
        yWithScroll = yWithScroll + "px";
        xWithScroll = window.innerWidth + "px";
    }
    else if (document.body.scrollHeight > document.documentElement.clientHeight)
    { // all but Explorer Mac  
       
        yWithScroll = document.body.scrollHeight;         
        xWithScroll = document.body.scrollWidth;   
        
    } 
    else 
    { // works in Explorer 6 Strict, Mozilla (not FF) and Safari     
        //alert(document.body.scrollHeight-document.documentElement.clientHeight);
          yWithScroll =  document.documentElement.clientHeight;
           xWithScroll = document.documentElement.clientWidth;     
         
    } 
    //alert(yWithScroll);   
   // alert(yWithScroll);
   // alert(xWithScroll);
    objDiv.style.position="absolute";
    objDiv.style.top="0px";
    objDiv.style.left="0px"; 
    objDiv.style.width=xWithScroll;
    objDiv.style.height=yWithScroll; 
    objDiv.style.overflow="hidden";
}


//-----------function to open new window-----------------//
function OpenNewWin(theUrl) 
{ 
var winOptions ="scrollbars=yes,resizable=yes,fullscreen=no,channel mode=no,status=no,toolbar=no,menubar=no,location=n o,directories=no,height=200,weight=700";
var target ="_blank";
window.open(theUrl,target,winOptions);
} 

// JScript File
function showAppropriateDiv(divToShow)
{
    
    
    objDivContainer=document.getElementById('DivContainer');
    
    var objregex = new RegExp("Home")
    var strIdName;
    if(objDivContainer != null)
    {
    
    
        for(var i=0;i<objDivContainer.getElementsByTagName("div").length;i++)
        {
        
            strIdName=objDivContainer.getElementsByTagName("div")[i].id;
    
            if(strIdName.match(objregex))
            {
            
                
            
               if(strIdName == divToShow)
               {
                    document.getElementById(strIdName).style.display='block';
                    setPosition(divToShow);
               }
                else
                    document.getElementById(strIdName).style.display='none';
        
            }
        }
      }  
    
    
}
function hideDiv(divToHide)
{
    if(document.getElementById(divToHide) != null)
    {
        document.getElementById(divToHide).style.display='none';
    }
}


//function to set positon of the div resolution wise
function setPosition(divName)
{ 
   
    var objYes = document.getElementById(divName);
   
       
        if(screen.width==1024)
        {
        objYes.style.position="absolute";
        objYes.style.top="200px";
        objYes.style.left="350px";
        objYes.style.width="600px";
        objYes.style.height="450px";
        }
        if(screen.width==1280)
        {
        
        objYes.style.position="absolute";
        objYes.style.top="200px";
        objYes.style.left="350px";
        objYes.style.width="600px";
        objYes.style.height="450px";
        }
   
   
 }
 
 
//function MatchSearchOnFocusBanner(thisField)
//{

//    if(thisField.value == (LocalizeMsgSiteSearch))
//        thisField.value = '';
//    thisField.style.color = '#000000';
//}

// var matchStringEditedSiteSearch = false;
//var IsTextEnteredSiteSearch = false;
//function MatchStringOnFocusBanner(thisField)
//{
//  
//    if(!matchStringEditedSiteSearch && !IsTextEnteredSiteSearch)
//    {
//        thisField.value = '';
//        //thisField.style.color = '#000000';
//        matchStringEditedSiteSearch = true;
//    }
//    thisField.style.color = '#000000';
//}

//function MatchStringOnBlurBanner(thisField)
//{

//    if(thisField.value == "")
//    {
//        thisField.value = URLDecode(LocalizeMsgSiteSearch);//"Enter part no. or description";
//        //thisField.style.color = "#C0C0C0";
//        matchStringEditedSiteSearch = false;
//        IsTextEnteredSiteSearch = false;
//    }
//    thisField.style.color = "#C0C0C0";
//}

//function MatchStringOnKeyPressBanner(thisField, oEvent)
//{
// 
//    var keyCode = oEvent.keyCode ? oEvent.keyCode : oEvent.which ? oEvent.which : oEvent.charCode;
//    if (keyCode == 13)
//    {
//        oEvent.returnValue = false;
//        return false;

//    }
//    else return true;
//}

function MatchSearchOnFocusBanner(thisField)
{
    if(thisField.value == URLDecode(LocalizeMsgSiteSearch))
        thisField.value = '';
    thisField.style.color = '#000000';
}

var matchStringEdited = false;
var IsTextEntered = false;
function MatchStringOnFocusBanner(thisField)
{
   // debugger;

    if(!matchStringEdited && !IsTextEntered)
    {
        thisField.value = '';
        //thisField.style.color = '#000000';
        matchStringEdited = true;
    }
    
    thisField.style.color = '#000000';
}

function MatchStringOnBlurBanner(thisField)
{

    //debugger;
    if(thisField.value == "")
    {
        thisField.value = URLDecode(LocalizeMsgSiteSearch);//"Enter part no. or description";
        //thisField.style.color = "#C0C0C0";
        matchStringEdited = false;
        IsTextEntered = false;
        thisField.style.color = "#C0C0C0"; // "#C0C0C0"
    }
    
}

function MatchStringOnKeyPressBanner(thisField, oEvent)
{

    var keyCode = oEvent.keyCode ? oEvent.keyCode : oEvent.which ? oEvent.which : oEvent.charCode;
    if (keyCode == 13)
    {
        oEvent.returnValue = false;
        return false;
    }
    else return true;
}

function URLEncode(hdnSiteSearch)
{
    //debugger;
	// The Javascript escape and unescape functions do not correspond
	// with what browsers actually do...
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";

    if(document.getElementById(hdnSiteSearch) == null) return '';
    var plaintext  = document.getElementById(hdnSiteSearch).value;	
    //return plaintext;
	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
	    if (ch == " ") {
		    encoded += "+";				// x-www-urlencoded, rather than %20
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
			    alert( "Unicode Character '" 
                        + ch 
                        + "' cannot be encoded using standard URL encoding.\n" +
				          "(URL encoding only supports 8-bit characters.)\n" +
						  "A space (+) will be substituted." );
				encoded += "+";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	} // for

	return encoded;  	
};

function URLDecode(LocalizeSiteSearch)
{
    //return LocalizeSiteSearch;
   // Replace + with ' '
   // Replace %xx with equivalent character
   // Put [ERROR] in output if %xx is invalid.
   var HEXCHARS = "0123456789ABCDEFabcdef"; 
   var encoded = LocalizeSiteSearch;
   var plaintext = "";
   var i = 0;
   while (i < encoded.length) {
       var ch = encoded.charAt(i);
	   if (ch == "+") {
	       plaintext += " ";
		   i++;
	   } else if (ch == "%") {
			if (i < (encoded.length-2) 
					&& HEXCHARS.indexOf(encoded.charAt(i+1)) != -1 
					&& HEXCHARS.indexOf(encoded.charAt(i+2)) != -1 ) {
				plaintext += unescape( encoded.substr(i,3) );
				i += 3;
			} else {
				alert( 'Bad escape combination near ...' + encoded.substr(i) );
				plaintext += "%[ERROR]";
				i++;
			}
		} else {
		   plaintext += ch;
		   i++;
		}
	} // while
   return plaintext;   
};

function ShowHideBanner(divtoShow)
{
    document.getElementById("divHome").style.display = "none";
    document.getElementById("divBuy").style.display = "none";
    document.getElementById("divSell").style.display = "none";
    document.getElementById("divContact").style.display = "none";
    document.getElementById("divMessage").style.display = "none";
    document.getElementById("divEvent").style.display = "none";
    document.getElementById("divForum").style.display = "none";
    document.getElementById("divProfile").style.display = "none";
    
    document.getElementById(divtoShow).style.display = "inline";    
    return false;
}

function MenuClick(sender, args)   
{
    var menuItem = sender.Text;
    try   
    {     
        if(menuItem == "Start")
        {
            ShowHideBanner("divHome")
            //ShowHideMasterDiv();
            //showAppropriateDiv('divHomePageIntro1'); 
            return false;
        }           
       if(menuItem == "Buy" || menuItem == "Einkauf")
        {
            ShowHideBanner("divBuy")
            //ShowHideMasterDiv();
            //showAppropriateDiv('divHomePageIntro2'); 
            return false;
        }
        if(menuItem == "Sell" || menuItem=="Vertrieb")
        {
            ShowHideBanner("divSell")
            //ShowHideMasterDiv();
            //showAppropriateDiv('divHomePageIntro3'); 
            return false;
        }
        if(menuItem == "Contacts" || menuItem =="Kontakte")
        {
            ShowHideBanner("divContact")
            //ShowHideMasterDiv();
            //showAppropriateDiv('divHomePageIntro4'); 
            return false;
        }
        if(menuItem == "Message" || menuItem=="Nachrichten")
        {
            ShowHideBanner("divMessage")
            //ShowHideMasterDiv();
            //showAppropriateDiv('divHomePageIntro5'); 
            return false;
        }
        if(menuItem == "Events" || menuItem == "Veranstaltung")
        {
            ShowHideBanner("divEvent")
            //ShowHideMasterDiv();
            //showAppropriateDiv('divHomePageIntro6'); 
            return false;
        }
        if(menuItem == "Forums" || menuItem =="Forum")
        {
            ShowHideBanner("divForum")
            //ShowHideMasterDiv();
            //showAppropriateDiv('divHomePageIntro7'); 
            return false;
        }
        if(menuItem == "Profile" || menuItem == "Profil")
        {
            ShowHideBanner("divProfile")
            //ShowHideMasterDiv();
            //showAppropriateDiv('divHomePageIntro8'); 
            return false;
        }
    }   
    catch(e)   
    {   
    }   
} 