var Imgurl;
var globalGalleryIndx = 0;
var globalGalleryIndxPopUp = 0;
/////////////////////////////////////////////
//this function create the pictures gallery
function InitGallery(lang)
{
   var htmlSTR = ''
   
   htmlSTR += '<table align="center" border="0" cellpadding="0" cellspacing="0" style="width:90%;" class="tableBox">'
   htmlSTR +=     '<tr><td style="height:12px;"></td></tr>'
   htmlSTR +=     '<tr>'
   for (i = 0; i < 2 ; i++)
        {
		   if(parseInt(picArrayWidth[i]) > parseInt(picArrayHeight[i]))
           {
                if(parseInt(picArrayWidth[i])>200)
                {
                htmlSTR +=     '<td id="imgID'+i+'">'
    		    htmlSTR +=          '<table cellpadding="0" cellspacing="0" width="290" height="290" style="border: 1px solid #484359;">'
                htmlSTR +=                         '<tr>'
                htmlSTR +=                                  '<td align="center">'
                htmlSTR +=                                        '<img src="'+Imgurl+picArray[i]+'" width="200" border="0" onclick="openPic('+i+','+lang+')" style="cursor:pointer;"><br>'    
                htmlSTR +=                                  '</td>'
                htmlSTR +=                         '</tr>'
                htmlSTR +=             '</table>'
    		    htmlSTR +=     '</td>'
               }
               else
               {
                htmlSTR +=     '<td id="imgID'+i+'">'
    		    htmlSTR +=         '<table cellpadding="0" cellspacing="0" width="290" height="290">'
                htmlSTR +=                  '<tr>'
                htmlSTR +=                        '<td align="center" style="border: 1px solid #484359;">'
                htmlSTR +=                              '<img src="'+Imgurl+picArray[i]+'" border="0" onclick="openPic('+i+','+lang+')" style="cursor:pointer;"><br>'    
                htmlSTR +=                        '</td><td width="10"></td>'
                htmlSTR +=                  '</tr>'
                htmlSTR +=          '</table>'  
    		    htmlSTR +=     '</td>'
               }
           }
           else
           {
            if(parseInt(picArrayHeight[i])>200)
                {
                htmlSTR +=     '<td id="imgID'+i+'">'
    		    htmlSTR +=         '<table cellpadding="0" cellspacing="0" width="290" height="290">'
                htmlSTR +=                  '<tr>'
                htmlSTR +=                        '<td align="center" style="border: 1px solid #484359;">'
                htmlSTR +=                              '<img src="'+Imgurl+picArray[i]+'" height="200" border="0" onclick="openPic('+i+','+lang+')" style="cursor:pointer;"><br>'
                htmlSTR +=                        '</td><td width="10"></td>'
                htmlSTR +=                  '</tr>'
                htmlSTR +=          '</table>'  
                htmlSTR +=     '</td>'
               }
               else
               {
                htmlSTR +=     '<td id="imgID'+i+'">'
    		    htmlSTR +=         '<table cellpadding="0" cellspacing="0" width="290" height="290">'
                htmlSTR +=                  '<tr>'
                htmlSTR +=                        '<td align="center" style="border: 1px solid #484359;">'
                htmlSTR +=                              '<img src="'+Imgurl+picArray[i]+'" border="0" onclick="openPic('+i+','+lang+')" style="cursor:pointer;"><br>'
    		    htmlSTR +=                        '</td><td width="10"></td>'
                htmlSTR +=                  '</tr>'
                htmlSTR +=          '</table>' 
                htmlSTR +=     '</td>'
               }
           }
           
           
		}
   htmlSTR +=     '</tr>'
   htmlSTR +=     '<tr><td style="height:12px;"></td></tr>'
   htmlSTR +=     '<tr>'
   htmlSTR +=          '<td dir="rtl" id="picTtlTD">'+picArrayTitle[0]+'</td>'
   htmlSTR +=     '</tr>'
   htmlSTR +=     '<tr><td style="height:12px;"></td></tr>'
   htmlSTR += '</table>'
   document.getElementById("galleryTD").innerHTML = htmlSTR;
}
////////////////////////////////////////////////
//browse to the next picture
function goNextGallery(lang)
{  
        for (i=0; i < picArray.length ; i++)
	        {
			   if (parseInt(i) == parseInt(globalGalleryIndx) && parseInt(i+4) < picArray.length)
			        {
                       if(picArrayWidth[i+2] > picArrayHeight[i+2])
                          document.getElementById("imgID0").innerHTML = '<table cellpadding="0" cellspacing="0" width="290" height="290"><tr><td style="border: 1px solid #484359;"  align="center"><img src="'+Imgurl+picArray[i+2]+'" width="200" border="0" onclick="openPic('+(i+2)+','+lang+')" style="cursor:pointer;"><br></td></td><td width="10"><td></tr></table></td>';
                       else
                          document.getElementById("imgID0").innerHTML = '<table cellpadding="0" cellspacing="0" width="290" height="290"><tr><td style="border: 1px solid #484359;"  align="center"><img src="'+Imgurl+picArray[i+2]+'" height="200" border="0" onclick="openPic('+(i+2)+','+lang+')" style="cursor:pointer;"><br></td></td><td width="10"><td></tr></table></td>';
                       
                       if(picArrayWidth[i+3] > picArrayHeight[i+3])
                          document.getElementById("imgID1").innerHTML = '<table cellpadding="0" cellspacing="0" width="290" height="290"><tr><td style="border: 1px solid #484359;"  align="center"><img src="'+Imgurl+picArray[i+3]+'" width="200" border="0" onclick="openPic('+(i+3)+','+lang+')" style="cursor:pointer;"><br></td></td><td width="10"><td></tr></table></td>';
                       else
                          document.getElementById("imgID1").innerHTML = '<table cellpadding="0" cellspacing="0" width="290" height="290"><tr><td style="border: 1px solid #484359;"  align="center"><img src="'+Imgurl+picArray[i+3]+'" height="200" border="0" onclick="openPic('+(i+3)+','+lang+')" style="cursor:pointer;"><br></td></td><td width="10"><td></tr></table></td>';
                       
					   globalGalleryIndx = globalGalleryIndx+2;
					   i = picArray.length
					   document.getElementById("picTtlTD").innerHTML = picArrayTitle[globalGalleryIndx]
					}
			}
}
////////////////////////////////////////////////
//browse to the previous picture
function goPrevGallery(lang)
{
	    for (i=0; i < picArray.length ; i++)
	        {
               if (parseInt(i) == parseInt(globalGalleryIndx) && parseInt(i-2) >= 0)
			        {
                       if(picArrayWidth[i-2] > picArrayHeight[i-2])
                          document.getElementById("imgID0").innerHTML = '<table cellpadding="0" cellspacing="0" width="290" height="290"><tr><td style="border: 1px solid #484359;"  align="center"><img src="'+Imgurl+picArray[i-2]+'" width="200" border="0" onclick="openPic('+(i-2)+','+lang+')" style="cursor:pointer;"><br></td></td><td width="10"><td></tr></table></td>';
                       else
                          document.getElementById("imgID0").innerHTML = '<table cellpadding="0" cellspacing="0" width="290" height="290"><tr><td style="border: 1px solid #484359;"  align="center"><img src="'+Imgurl+picArray[i-2]+'" height="200" border="0" onclick="openPic('+(i-2)+','+lang+')" style="cursor:pointer;"><br></td></td><td width="10"><td></tr></table></td>';
                       
                       if(picArrayWidth[i-1] > picArrayHeight[i-1])
                          document.getElementById("imgID1").innerHTML = '<table cellpadding="0" cellspacing="0" width="290" height="290"><tr><td style="border: 1px solid #484359;"  align="center"><img src="'+Imgurl+picArray[i-1]+'" width="200" border="0" onclick="openPic('+(i-1)+','+lang+')" style="cursor:pointer;"><br></td></td><td width="10"><td></tr></table></td>';
                       else
                          document.getElementById("imgID1").innerHTML = '<table cellpadding="0" cellspacing="0" width="290" height="290"><tr><td style="border: 1px solid #484359;"  align="center"><img src="'+Imgurl+picArray[i-1]+'" height="200" border="0" onclick="openPic('+(i-1)+','+lang+')" style="cursor:pointer;"><br></td></td><td width="10"><td></tr></table></td>';
                          
					   globalGalleryIndx = globalGalleryIndx-2;
					   i = picArray.length					   
					   document.getElementById("picTtlTD").innerHTML = picArrayTitle[globalGalleryIndx]
					}
			}
}
////////////////////////////////////////////////
//open the pop up in the default page
function openPic(indx,lang)
{
       window.open("popUpGallery.asp?indx="+indx+"&lang="+lang,'pic','height=615,width=700')  
}
/////////////////////////////////////////////////
//create the pop up galerry in the default page
function InitGalleryPopUp(indx)
{
  globalGalleryIndxPopUp = indx;
  document.getElementById("mainPicturePOP").innerHTML = '<img src="'+Imgurl+picArray[indx]+'" border="0"><br>'
  document.getElementById("mainTitltePOP").innerHTML = '<b>'+picArrayTitle[indx]+'</b>';
}
///////////////////////////////////////////////////
//create the pop up galerry in the pictures gallery page page
function InitPicGalleryPopUp(indx)
{
  globalGalleryIndxPopUp = indx;
  document.getElementById("mainPicturePOP").innerHTML = '<img src="'+Imgurl+picArray[indx]+'" border="0"><br>'
  document.getElementById("mainTitltePOP").innerHTML = '<b>'+picArrayTitle[indx]+'</b>';
  document.getElementById("mainSubTitltePOP").innerHTML = '<b>'+picArraySubTitle[indx]+'</b>';
}
///////////////////////////////////////////////////
//browse to the previous picture in default page
function goPrevGalleryPopUp()
{
    for (i=0; i < picArray.length ; i++)
	     {
		    if (parseInt(i) == parseInt(globalGalleryIndxPopUp) && parseInt(i-1) >= 0)
			    {
				   InitGalleryPopUp(globalGalleryIndxPopUp-1);
				   i = picArray.length;
				}
		 }
}
///////////////////////////////////////////////////
//browse to the next picture in default page
function goNextGalleryPopUp()
{
     for (i=0; i < picArray.length ; i++)
	     {
		    if (parseInt(i) == parseInt(globalGalleryIndxPopUp) && parseInt(i+1) < picArray.length)
			    {
				   InitGalleryPopUp(globalGalleryIndxPopUp+1);
				   i = picArray.length;
				}
		 }
} 
////////////////////////////////
 function openPoll(pollId,ansId)
 {
	if(ansId != 0)
	{
	 	window.open("ShowPollResults.asp?pollid=" + pollId + "&AnswerID=" + ansId,'poll','width=438,height=510')
	}
	else
	{
		alert('יש לבחור תשובה')
	}
 }
 ///////////////////////////////////////////////////
//browse to the previous picture in picture Gallery pop up page
function goPrevPicGalleryPopUp()
{
    for (i=0; i < picArray.length ; i++)
	     {
		    if (parseInt(i) == parseInt(globalGalleryIndxPopUp) && parseInt(i-1) >= 0)
			    {
				   InitPicGalleryPopUp(globalGalleryIndxPopUp-1);
				   i = picArray.length;
				}
		 }
}
///////////////////////////////////////////////////
//browse to the next picture in picture Gallery pop up page
function goNextPicGalleryPopUp()
{
     for (i=0; i < picArray.length ; i++)
	     {
		    if (parseInt(i) == parseInt(globalGalleryIndxPopUp) && parseInt(i+1) < picArray.length)
			    {
				   InitPicGalleryPopUp(globalGalleryIndxPopUp+1);
				   i = picArray.length;
				}
		 }
}