﻿function breakLongWords(str){ /* This function takes a long word and adds a space every 30 chars */

    var tempArray ;
    var temp = "" ;
    var strArray = str.split(" ");
    for (x in strArray)
    {   
        if (strArray[x].length > 25){
            tempArray = strArray[x].split("");
            temp = "" ;
            for (y in tempArray){
                if( ((y % 25) == 0) && (y > 1)){
                    temp += tempArray[y]+" ";
                }
                else{
                    temp += tempArray[y];
                }
            }
            strArray[x] = temp ;
        }
    }
    temp = strArray.join(" ") ;
    return temp;
}
/***************************************************************/
function deleteBook(id,bookName,isForSale){
    
    if ( confirm(" : למחוק את הספר    \n\n ? " + bookName.replace("`","'")) ) {
        if(isForSale){
            window.location = "deleteBook.asp?id=" + id ;
        }
        else{
            window.location = "deleteWantedBook.asp?id=" + id ;
        }
    }
}
/***************************************************************/
function deleteBookReview(id,bookName){
    
    if ( confirm(" : למחוק את הביקורת על הספר    \n\n ? " + bookName.replace("`","'")) ) {
            window.location = "deleteBookReview.asp?id=" + id ;
        }
}
/***************************************************************/
function openDescription(str){

	if (document.getElementById(str).style.display == "none"){
		document.getElementById(str).style.display="block";
		document.getElementById(str).style.position = "relative";
	}
	else{
		document.getElementById(str).style.display="none";
	}
     
}
/***************************************************************/
function closeDescription(str){

		document.getElementById(str).style.display="none";
}
/***************************************************************/

function CheckEmail(src) {
        if( src.indexOf(" ") > 0 ){
            return false;
        }
		var emailReg = "^[\\w-_\.]*[\\w-_\.]\@[\\w]\.+[\\w]+[\\w]$";
		var regex = new RegExp(emailReg);
		return regex.test(src);
}
/***************************************************************/
function Send_Mail(){

    var f=document.forgotten;
    var email = f.SendMail.value;
	
	if(!CheckEmail(email) || (email == "myMail@mail.com") ){
		alert('אימייל לא חוקי')
		f.SendMail.focus();
		f.SendMail.value = email;
		return false;
	}else{
		f.action="re-sendPassword.asp"
		//f.submit();
		f.btnSubmit.parentNode.parentNode.className='sending';
	}
}
/***************************************************************/
function Send_Reg_Mail(sSrc){

	var f=document.register;
    var email = f.SendRegMail.value;

	if(!f.terms.checked){
		alert('!חובה להסכים לתנאי השימוש')
		f.terms.focus();
		return false;
	}	
	if(!CheckEmail(email) || (email == "myMail@mail.com") ){
		alert('אימייל לא חוקי')
		f.SendRegMail.focus();
		f.SendRegMail.value = email;
		return false;
	}else{
	
		f.action="registration.asp?src=" + sSrc

		f.btnSubmit.parentNode.parentNode.className='sending';

	}
}
/***************************************************************/
function IsNumeric(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

  /*  if (sText.length == 0){
        IsNumber = false;
    }*/
   for (j = 0; j < sText.length && IsNumber == true; j++) 
      { 
      Char = sText.charAt(j); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
}
/***************************************************************/   
function CheckForm(formName){

    var formName = eval("document."+formName);

    for(i=0;i<formName.elements.length;i++){
    /* cancel adding spaces in long words.
        if( (formName.name=="profile") || (formName.name=="addBook") || (formName.name=="editBook") ){
                if ( ( (formName.elements[i].name != "BookImage") || (formName.elements[i].name != "email") ) && (formName.elements[i].value.length > 25) ){
                
                    formName.elements[i].value = breakLongWords(formName.elements[i].value);
                }
        }
    */
 	    if(formName.elements[i].title == "שדה חובה" && formName.elements[i].value.length < 1 ){
		    alert(" !!! שדה חובה");
		    formName.elements[i].focus();
		    //if(formName.elements[i].name == "category"){
		    //    formName.elements[i].style.backgroundColor='pink';    
		    //}
		    return false;
	    }  
	    if(formName.elements[i].title == "מספר" && !IsNumeric(formName.elements[i].value)){
		    alert(" !!! מספר לא חוקי");
		    formName.elements[i].focus();
		    return false;	
	    }
    }

    if(formName.name=="profile"){
        if(formName.password.value != formName.rePassword.value){
       	    alert(" !!! סיסמה לא זהה");
 		        formName.password.value = "";
		        formName.rePassword.value = "";
		        formName.password.focus();
		        //formName.elements[i].style.backgroundColor='Tomato';
		        return false;	
        }
        if(formName.password.value.length > 10 || formName.password.value.length < 4){
       	    alert(" !!! סיסמה צריכה להיות בין 4 ל 10 תווים");
 		        formName.password.value = "";
		        formName.rePassword.value = "";
		        formName.password.focus();
		        //formName.elements[i].style.backgroundColor='Tomato';
		        return false;	
        }  
        if( formName.showMail.checked && ( formName.phoneNumber1.value == "" && formName.phoneNumber2.value == "" ) ){
       	    alert("\n\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r!לא השארת פרטי התקשרות" + 
 		        "\n.סימנת את כתובת הדואר האלקטרוני שלך כחסוי ולא השארת מספר טלפון" +
 		        "\n\r\r\r\r\r\r\r\r\r.יש להשאיר לפחות אמצעי התקשרות אחד, דואר אלקטרוני או טלפון");
		        formName.showMail.focus();
		        
		        return false;	
        }              
    }
  
    //formName.submit();
    formName.btnSubmit.parentNode.parentNode.className='sending';


}
/***************************************************************/
function changeAction(formName){
     var formName = eval("document."+formName);
     formName.action = formName.whereToSearch.value;

}
/***************************************************************/
function textCounter(field, countfield, maxlimit) {
    if (field.value.length > maxlimit) { // if too long...trim it!
        field.value = field.value.substring(0, maxlimit);
        }
    else {
        countfield.value = maxlimit - field.value.length;
        }
    }
/***************************************************************/
function OpenNewWindow(WindowPicture)
	{
	var NewWindow ;
	var objImage = new Image();
	objImage.src = WindowPicture;
	
	var width = parseInt(objImage.width);
	var height = parseInt(objImage.height) + 35;
    var WindowParameters = 'resizable=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,toolbar=no,titlebar=no';	
	
	NewWindow=window.open("","pictureWindow","width=1,height=1"); // these two lines make sure a new window will be opened
	NewWindow.close();
	
	NewWindow=window.open("","pictureWindow", WindowParameters+",width="+width+",height="+height);
	NewWindow.document.write ('<html><head>');
	NewWindow.document.write ("</head>");
	NewWindow.document.write ("<body bgcolor='white' topmargin='0' leftmargin='0'>");
	NewWindow.document.write ("<center>");
	NewWindow.document.write ("<img src='");
	NewWindow.document.write (WindowPicture);
    NewWindow.document.write ("'><br />");
    NewWindow.document.write ("<a href='JavaScript:this.close()' style='color: #696969; text-decoration: none; font-size: 12pt; font-family: arial, david;'><b>סגור חלון</b></a>");
	NewWindow.document.write ("</center>");
	NewWindow.document.write ("</body></html>");
	NewWindow.document.close();
	
	return ;
	}
/***************************************************************/	
	function show_me(URL, id, h)
	{		
		if( document.getElementById("Info" + id).className=="TdInfo" )
	   {	
            document.getElementById("TxtID"  + id).innerHTML='<A class="search" style="hand: pointer;" HREF="javascript:show_me(\''+URL+'\','+ id+', 300);" onfocus="this.blur();">סגור</A>&nbsp;&nbsp;';
	   
			//str='<TABLE WIDTH="100%" BORDER="0" align="right" CELLPADDING="0" CELLSPACING="0" dir="rtl" BGColor="#FFFFFF">';
			//str+='<TR>';
			//str+='	<TD style="border-right: solid 1px #FD9A57; background-color: #F8EFEA"><IMG SRC="../imageInsidePage/hidden-spacer.gif" WIDTH="1" HEIGHT="1" BORDER="0"></TD>';
			//str+='	<TD align="right"><iframe  src="' + URL + '" width="100%" height="' + h + '" frameborder="0" scrolling="auto" BGColor="#FFFFFF"></iframe></TD>';
			str='	<iframe  src="' + URL + '" width="100%" height="' + h + '" frameborder="0" scrolling="auto" BGColor="#FFFFFF"></iframe>';
			//str+='	<TD style="border-left: solid 1px #FD9A57; background-color: #F8EFEA"><IMG SRC="../imageInsidePage/hidden-spacer.gif" WIDTH="1" HEIGHT="1" BORDER="0"></TD>';
			//str+='</TR>';
			//str+='<TR>';
			//str+='	<td width="5" height="5"><img src="../imageInsidePage/Bottom_right_corner_details.jpg" width="5" height="5" alt=""></td>';
			//str+='	<td  background="../imageInsidePage/Bottom_BG_details_Bottom.jpg"><img src="../imageInsidePage/Bottom_BG_details_Bottom.jpg" width="5" height="5" alt=""></td>';
			//str+='	<td width="5" height="5"><img src="../imageInsidePage/Bottom_left_corner_details_.jpg" width="5" height="5" alt=""></td>';
			//str+='</TR>';			
			//str+='</TABLE>';
			document.getElementById("Info" + id).innerHTML=str;
			document.getElementById("Info" + id).className="";
	   } 
		else
	   {
			//document.getElementById("Info" + id).innerHTML="<IMG SRC='../imageInsidePage/spacer.gif' WIDTH='1' HEIGHT='1' BORDER='0'>";
    		document.getElementById("TxtID"  + id).innerHTML='<A class="search" style="hand: pointer;" HREF="javascript:show_me(\''+URL+'\','+ id+', 300);" onfocus="this.blur();">פרטים</A>&nbsp;&nbsp;';
			document.getElementById("Info" + id).innerHTML="";
			document.getElementById("Info" + id).className="TdInfo";
	   }			
	}
/***************************************************************/	
	function cpanle_show_me(URL, id, h)
	{		
		if( document.getElementById("Info" + id).className=="TdInfo" )
	   {	
			str = '<iframe  src="' + URL + '" width="100%" height="' + h + '" frameborder="0" scrolling="auto" BGColor="white"></iframe>';
			
			document.getElementById("Info" + id).innerHTML=str;
			document.getElementById("Info" + id).className="";
	   } 
		else
	   {
			document.getElementById("Info" + id).innerHTML="";
			document.getElementById("Info" + id).className="TdInfo";
	   }			
	}
/***************************************************************/		
function sendToAFriend(sURL){
    window.open("sendToAFriend.asp?sURL="+sURL,"sendTo","width=400,height=280,resizable=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,toolbar=no,titlebar=no")
}	
/***************************************************************/	
function bookmarksite(title, url){
    try{
        if (document.all) {
            window.external.AddFavorite(url, title);
            }
        else if (window.sidebar){
            window.sidebar.addPanel(title, url, "")
        }
    }
    catch(e){}
}
/***************************************************************/	
function preLoadImages(){
  
  var img1 = new Image();
  img1.src = "images/inputScreen/search_homepage-wait.jpg";
  
  var img2 = new Image();
  img2.src = "images/inputScreen/updateWait.gif";
  
  var img3 = new Image();
  img3.src = "images/inputScreen/wait.gif";
  
  var img4 = new Image();
  img4.src = "images/inputScreen/sendWait.gif";
  
  var img5 = new Image();
  img5.src = "images/menu/button_02-over.gif";

  var img6 = new Image();
  img6.src = "images/menu/button_02.gif";

  var img7 = new Image();
  img7.src = "images/menu/menuBottomBorder.jpg";

  var img8 = new Image();
  img8.src = "images/menu/topLeftCorner.gif";
        
  var img9 = new Image();
  img9.src = "images/background.jpg";
  
  var img10 = new Image();
  img10.src = "images/inputScreen/search_homepage-wait.jpg";
  
  var img11 = new Image();
  img11.src = "images/inputScreen/search_homepage-wait.jpg";
  
  
}	
/***************************************************************/	
//This function prevents opening an iframe directly without it's parent.
function chekForParent(sPage){
    if(top.location == this.location){
        top.location = sPage
    }
}
/***************************************************************/

//This function prevents opening an HTML page in a frame.
function openAsParent(){
    if(top.location != this.location){
        top.location = this.location
    }
}
/***************************************************************/
	function changecss(theClass,element,value) {
	//documentation for this script at http://www.shawnolson.net/a/503/
	 var cssRules;
	 if (document.all) {
	  cssRules = 'rules';
	 }
	 else if (document.getElementById) {
	  cssRules = 'cssRules';
	 }
	 
	 for (var S = 0; S < document.styleSheets.length; S++){
	  for (var R = 0; R < document.styleSheets[S][cssRules].length; R++) {
	   if (document.styleSheets[S][cssRules][R].selectorText == theClass) {
	    document.styleSheets[S][cssRules][R].style[element] = value;
	   }
	  }
	 }	
	}
	
/***************************************************************/	

function testImage() {
    try{
        if(ImgTester.width > 28){
             var sImageSize = 'height="100" width="70"';
             if( bIsEditMode ){
                sImageSize = 'height="80" width="60"';
             }
            oImageDiv.innerHTML = '<img src="' + sImageSrc + '" ' + sImageSize + ' />';        
        }
        else{
            oImageDiv.innerHTML = '<span class="bodyText">לא<br />נמצאה<br />תמונה</span>';                
        }
    } catch(e){}    
}

var ImgTester, oImageDiv, sImageSrc, bIsEditMode;

function showImage(sImgSrc, bInputIsEditMode){
    try{
        sImageSrc = sImgSrc;
        if (sImageSrc){ 
            ImgTester = new Image();
            ImgTester.src = sImageSrc;
            bIsEditMode = bInputIsEditMode;
            oImageDiv = document.getElementById("previewImageSpan");
            oImageDiv.innerHTML = '<img src="images/loading.gif" />'; 
            setTimeout("testImage()",1000);
            setTimeout("testImage()",2000);
        }
    }
    catch(e){}
}
/***************************************************************/

