﻿
// cache images
if (document.images) //check for browser support
{
    var imImagesArray = new Array();
    var iImArray = 0;
    
    cacheImage('images/sendBtn_mouseover.png');
    cacheImage('images/sendBtn.png');
    cacheImage('images/newsAndSales_mouseover.png');
    cacheImage('images/newsAndSales.png');
    cacheImage('images/aboutUs_mouseover.png');
    cacheImage('images/aboutUs.png');
    cacheImage('images/howToGet_mouseover.png');
    cacheImage('images/howToGet.png');
    cacheImage('images/clients_mouseover.png');
    cacheImage('images/clients.png');
    cacheImage('images/newBranches_mouseover.png');
    cacheImage('images/newBranches.png');
    cacheImage('images/otherBrands_mouseover.png');
    cacheImage('images/otherBrands.png');
    cacheImage('images/clarks_mouseover.png');
    cacheImage('images/clarks.png');
    cacheImage('images/accessories_mouseover.png');
    cacheImage('images/accessories.png');

    cacheImage('images/step1.png');
    cacheImage('images/step1_mouseover.png');
    cacheImage('images/step1_selected.png');
    cacheImage('images/step2.png');
    cacheImage('images/step2_mouseover.png');
    cacheImage('images/step2_selected.png');
}


function cacheImage(strImgSrc)
{
    if (!document.images)
        return;
        
    imImagesArray[iImArray] = new Image();
    imImagesArray[iImArray].src = strImgSrc;
    iImArray ++;
}

//changes image to create rollover effect
function DisplayMouseover(image_id)
{
	// get img source
	var img_src = document.getElementById(image_id).src;
	
	//cache image
	cacheImage(img_src);
	
	var RegExpObject = new RegExp('_mouseover');

	//tests for selected string in image
	if (RegExpObject.test(img_src)== true)	 //already selected, change from "_mouseover.png" to ".png"
	{
		var result = img_src.replace(/_mouseover.png/gi, ".png");
	}
	else	//change to selected, change from ".png" to "_mouseover.png"
	{
		var result = img_src.replace(/.png/gi, "_mouseover.png");
	}
	
	//cache image
	cacheImage(result);
	
	img_src = result;
	document.getElementById(image_id).src = img_src;
}


// changes menu img
function DisplayMouseover_NavigationMenu(img_path)
{
    document.getElementById('navigation_menu_img').src = img_path;
}

function DisplayDiv2(id, state)
{
	if (state == 0)
	{
		document.getElementById(id).style.display='block';
	}
	else
	{
		document.getElementById(id).style.display='none';
	}
}

function MouseoverThis(id, state)
{
	//alert(id);
	if (state == 0)
	{
		document.getElementById(id).style.background='#ef853f';
		document.getElementById(id).style.color='#ffffff';
	}
	else
	{
		document.getElementById(id).style.background='transparent';
		document.getElementById(id).style.color='#00356c';
	}
}

function MouseoverThis2(id, id2, state)
{
	if (state == 0)
	{
		document.getElementById(id).style.background='#ccd7e2';
		document.getElementById(id2).style.color='#00356c';
	}
	else
	{
		document.getElementById(id).style.background='transparent';
		document.getElementById(id2).style.color='#f8f9f9';
	}
}

function DisplayDiv(id)
{
	//alert(id);
	
	var state = document.getElementById(id).style.display;
	
	/*var imgid="img" + id;
	if (lastdisplayed != null)
	{
		//lastimgid = "img" + lastdisplayed;
		document.getElementById(lastdisplayed).style.display='none';
		//document.getElementById(lastspan).style.display='none';
		//document.getElementById(lastimgid).src='images/ques.jpg';
		//document.getElementById(lastimgid).alt='לחץ כאן להסבר';
	}
	*/
	
	if (state != 'block')
	{
		document.getElementById(id).style.display='block';
		//lastdisplayed = id;
		//document.getElementById(spanid).style.display='block';
		//lastspan= spanid;
		//document.getElementById(imgid).src='images/x.png';
		//document.getElementById(imgid).alt='לחץ כאן לסגור הסבר';
	}
	else
	{
		document.getElementById(id).style.display='none';
		//document.getElementById(spanid).style.display='none';
		//document.getElementById(imgid).src='images/ques.jpg';
		//document.getElementById(imgid).alt='לחץ כאן להסבר';
	}
}

 function DisplayPopUpDiv(counter, drug_counter, popup_txt, drug_stage)
{
	var state = document.getElementById('popup_div' + counter).style.display;

	if (state != 'block')
	{
		document.getElementById('popup_div' + counter).style.display='block';
		document.getElementById('popup_div' + counter).style.top= drug_counter*30 - 27 + 'px';	
		document.getElementById('TXTpopup_div' + counter).innerHTML = popup_txt;
		document.getElementById('IMGpopup_div' + counter).style.background= "url('images/popup" + drug_stage + ".png')";
	}
	else
	{
		document.getElementById('popup_div' + counter).style.display='none';
	}
}

//function prints received content
function printContent(id1, window_width){

     // str= '<b>' + document.getElementById(title).innerHTML + '</b><br><br>' + document.getElementById(id1).innerHTML + '<br><br>' + document.getElementById(id2).innerHTML

	  str=  document.getElementById(id1).innerHTML 
      
      newwin=window.open('','printwin','left=300,top=100,width=' + window_width + ',height=700')

      newwin.document.write('<HTML>\n<HEAD>\n')
      
      newwin.document.write('<LINK REL="Stylesheet" HREF="CSS/css.css" TYPE="text/css">')

      newwin.document.write('<TITLE>הדפסת מתכון</TITLE>\n')

      newwin.document.write('<script>\n')

      newwin.document.write('function chkstate(){\n')

      newwin.document.write('if(document.readyState=="complete"){\n')

      newwin.document.write('window.close()\n')

      newwin.document.write('}\n')

      newwin.document.write('else{\n')

      newwin.document.write('setTimeout("chkstate()",3000)\n')

      newwin.document.write('}\n')

      newwin.document.write('}\n')

      newwin.document.write('function print_win(){\n')

      newwin.document.write('window.print();\n')

      newwin.document.write('chkstate();\n')

      newwin.document.write('}\n')

      newwin.document.write('<\/script>\n')

      newwin.document.write('</HEAD>\n')

      newwin.document.write('<BODY onload="print_win()">\n')

      newwin.document.write('<div style="margin:0 auto; text-align:center; width:100%;"><div id="PrintContent" style="text-align:right; padding:10px;">' + str + '</div></div>')

      newwin.document.write('</BODY>\n')

      newwin.document.write('</HTML>\n')

      newwin.document.close()

}



// Bookmark page to favorites
function AddToFavorites()
{
	title = "MarketWinners - לימודי שוק הון, מערכות מסחר באינטרנט, עבודה מהבית - מרקט ווינרז";
	url = "http://marketwinners.co.il/";

	if (window.sidebar) { // Mozilla Firefox Bookmark
	window.sidebar.addPanel(title, url,"");
	} else if( window.external ) { // IE Favorite
	window.external.AddFavorite( url, title); }
	else if(window.opera && window.print) { // Opera Hotlist
	return true; }
}

function OpenForgotPassWordWin(inputEmailID)
{
    URL = "forgotPass.aspx?email=" + document.getElementById(inputEmailID).value;
	popUpWindow  = window.open(URL,"","menubar=0,scrollbars=0,directories=0,location=0,top=110,left=200%,toolbar=0,status=0,titlebar=0,width=250,height=150");
	popUpWindow.focus();
}


// initialize img
//var facebox_img = new Image;
//facebox_img.src = 'images/pixel.gif';

function OpenFacebox(file_name)
{
	facebox_img.src = file_name;
	screen_height_left = screen.height-facebox_img.height;
	
	// if img too large for screen, display smaller
	if (screen_height_left < 340)
	{
		facebox_img.height = screen.height - 340;
	}
	
	document.getElementById('facebox_popup').style.top=0;
	jQuery.facebox('<img height=\' ' + facebox_img.height + ' \' src=\' ' + facebox_img.src + ' \'>');
}


// function iterates through form fields and disables them
function DisableFormFields()
{
	var form_elements = new Array();
	form_elements = document.search_coll_form.elements;

	for(i=1; i<form_elements.length; i++)
	{
		//document.writeln(form_elements[i].name + "<br>");
		
		//if category is selected, enable subcategory selection
		if (form_elements[0].value!=-1)
		{
			form_elements[1].style.backgroundColor = '';
			form_elements[1].disabled = false;
		}
		
		// if user has selected main category and subcategory
		if (form_elements[0].value!=-1 && form_elements[1].value!=-1)
		{
			form_elements[i].style.backgroundColor = '';
			form_elements[i].disabled = false;
		}
		else
		{
			// disable form element
			form_elements[i].style.backgroundColor = '#CCCCCC';
			form_elements[i].disabled = true;
		}
	}
}


// receives form name, iterates through elements and clears value
function ClearForm(str_form_name)
{
	form_name = eval(str_form_name);
	
	var form_elements = new Array();
	form_elements = form_name.elements;
	
	for(i=0; i<form_elements.length; i++)
	{
		//alert(form_elements[i].name + " = " + form_elements[i].value);
		//alert(form_elements[i].type);
		
		// don't clear button and submit values
		if (form_elements[i].type != "button" && form_elements[i].type != "submit")
		{
			form_elements[i].value = "";
		}
	}
}


// receives form name, and search box, iterates through elements and clears value
function ClearForm(str_form_name, strSearchInputName)
{
	form_name = eval(str_form_name);
	
	var form_elements = new Array();
	form_elements = form_name.elements;
	
	for(i=0; i<form_elements.length; i++)
	{
		//alert(form_elements[i].name + " = " + form_elements[i].value);
		//alert(form_elements[i].type);
		
		// don't clear button and submit values
		if (form_elements[i].type != "button" && form_elements[i].type != "submit" && 
		    form_elements[i].name != strSearchInputName && form_elements[i].value != "חודש" && form_elements[i].value != "שנה")
		{
			form_elements[i].value = "";
		}
	}
}




// populates subcategory droplist, filters by category id
function PopulateSubcategoryListBox(category_value, subcategory_value)
{
	var sub_listbox = document.search_coll_form.group_select;
	
	//clear listbox options
	sub_listbox.options.length = 0;
	
	// add empty option
	var NewOpt = document.createElement('option');
	NewOpt.text = "";
	NewOpt.value = "-1";
	sub_listbox.options.add(NewOpt);
	
	// category id is at 0 position
	for (i=0; i<subcategories_array[0].length;i++)
	{
		if(subcategories_array[0][i]==category_value)	
		{
			// new option
			var NewOpt = document.createElement('option');
			
			//append option to subcategory droplist
			NewOpt.text = subcategories_array[2][i];
			NewOpt.value = subcategories_array[1][i];
			
			// if request.form(subcat) draw selected
			if (NewOpt.value==subcategory_value)
			{
				NewOpt.selected = true;
			}
			
			sub_listbox.options.add(NewOpt);
		}
	}
}




function ForgotPassword(email)
{
	Window  = window.open("forgotpass.asp?email=" + email,"","menubar=0,scrollbars=0,directories=0,location=0,top=200,left=500,toolbar=0,status=0,titlebar=0,width=400,height=230");
	Window  .focus();
}

// receives string, checks for actual value
// return false for "", null and empty spaces " "
function isStringEmpty(strValue)
{
    var _strValue = strValue;
    var bool_isEmpty = true;

    switch (_strValue)
    {
        case "":
            break;
        case null:
            break;
        default:
            _strValue = (escape(_strValue))
            _strValue = _strValue.replace(/%20/g,''); //replaces all " "
            if (_strValue != "")
                bool_isEmpty = false;
            break;
    }

    return bool_isEmpty;
}

// validates form by form name, if valid submits.
// modify by tag attributes

function ValidateForm2(strFormName)
{
    var form_name = document.getElementById(strFormName);
    var form_elements = new Array();
    form_elements = form_name.elements;
	var form_field; 
	// iterates through form elements
    for(i=0; i<form_elements.length; i++)
    {
	    alert(form_elements[i].name + " = " + form_elements[i].value);


	    // ignore clear button and submit values
	    if (form_elements[i].type == "button" || form_elements[i].type == "submit")
	    {
	        break;
	    }
	   
        // alert(form_elements[i].name + " = " + form_elements[i].value);
        form_field = form_elements[i];
	    
	    // if mandatory field
	    if (form_elements[i].getAttribute( "mandatory_field" )=="1")
	    {
            // if textbox or textarea empty
	        if (isStringEmpty(form_elements[i].value) || form_elements[i].type =="checkbox" && form_elements[i].checked ==false) 
	        {
	            alert_msg = form_elements[i].getAttribute( "mandatory_msg" );
                if (alert_msg==undefined){
                    alert_msg = "Mandatory field"
                }
                alert ( alert_msg ); 
                form_field.focus();
                return false; 	
	        }
	     }
	    
	    // if numeric
	    
	    // if email - test format
	    if (form_elements[i].getAttribute( "email_field" )=="1")
	    {
	         if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(form_elements[i].value))
	         {
	            //proper format -  do nothing      
	         }
	         else
	         {
	             alert_msg = form_elements[i].getAttribute( "email_msg" );
                 if (alert_msg==undefined){
                    alert_msg = "Invalid email";
                 }
                 alert ( alert_msg );
                 form_field.focus();
                 return false; 	
	         }
	    }
    }

    
    // if reached here successfully, submit
    form_name.submit();
}

  // submits search
    function SearchSubmit(inputId, strAlertMsg, strSearchDefaultValue, iSearchPageID)
    {
        var strSearchValue = document.getElementById(inputId).value;
        if (isStringEmpty(strSearchValue) || strSearchValue==strSearchDefaultValue)
        {
            alert(strAlertMsg);
            return false;
        }
            
        //return false;
            
        var strUrl = "default.aspx?pageid=" + iSearchPageID + "&q=" + escape(strSearchValue);
        window.location.href = strUrl;           
        return false;
    }
    
    
    // toggles input text display
    function hideInputText(divId, inputId)
    {
		document.getElementById(divId).style.display = 'none';
		document.getElementById(inputId).focus();
    }
    
    function onblurDisplayLbl(divId, inputId)
    {
		var inputText = document.getElementById(inputId).value;
		if (isStringEmpty(inputText))
		{
			//alert(document.getElementById(divId).style.display);
			document.getElementById(divId).style.display = 'block';
			//alert(document.getElementById(divId).style.display);
		}
    }
    
    
    function focusInput(inputId)
    {
		document.getElementById(inputId).style.border = 'solid #d3d3d3 1px';
    }
    
    function blurInput(inputId)
    {
		document.getElementById(inputId).style.border = 'solid transparent 1px';
    }
    
     function OpenMenu(imgId, divId, file_name)
    {
        var navImg = new Image();
        var navImgMouseover = new Image();
        navImgMouseover.src = file_name;
        
       // alert(divId);
        //return;
        
        navImg.src = document.getElementById(imgId).src;
        document.getElementById(imgId).src = navImgMouseover.src; // change to mouseover image	
        
        document.getElementById(divId).style.top = document.getElementById(imgId).offsetHeight + 'px';  // position div below menu
        document.getElementById(divId).style.width = document.getElementById(imgId).offsetWidth + 41 + 'px';
        document.getElementById(divId).style.display = 'block'; // open menu div
    }
    
    function CloseMenu(imgId, divId, file_name)
    {
        document.getElementById(imgId).src = file_name; // change to regular image	
        document.getElementById(divId).style.display = 'none'; // open menu div
    }
    
     function DisplayPopUpBannerDiv(divId)
    {
        //document.getElementById(divId).style.top = document.getElementById(imgId).offsetHeight + 'px';  // position div below menu
        //document.getElementById(divId).style.width = document.getElementById(imgId).offsetWidth + 41 + 'px';
        document.getElementById(divId).style.visibility = 'visible'; // open menu div
    }
    
    function HidePopUpBannerDiv(divId)
    {
        document.getElementById(divId).style.visibility = 'hidden'; // close menu div
    }
    
    function ToggleMainImg(imgSrc)
    {
        document.getElementById('FullImgDisplay').src = imgSrc;
    }
    
    function selectSize(sizeId, hiddenId)
    {
        getElementByClass("selectedSize");
        document.getElementById("size" + sizeId).className = 'selectedSize';
        document.getElementById(hiddenId).value = sizeId;
        // change button display
        document.getElementById('imgAdd2Cart').setAttribute("src", "images/add2Cart_mouseover.png");
    }
    
    function getElementByClass(theClass) {
       
        //Create Array of All HTML Tags
        var allHTMLTags=document.getElementsByTagName('div');

        //Loop through all tags using a for loop
        for (i=0; i<allHTMLTags.length; i++) {
            //Get all tags with the specified class name.
            if (allHTMLTags[i].className==theClass) 
                allHTMLTags[i].className = "size";
        }
        
    }


function ValidateForm(strFormName)
{
    var form_name = document.getElementById(strFormName);
    var form_elements = new Array();
    form_elements = form_name.elements;
	var form_field 
	// iterates through form elements
    for(i=0; i<form_elements.length; i++)
    {
	    //alert(form_elements[i].name + " = " + form_elements[i].value);
	    // ignore clear button and submit values
	    if (form_elements[i].type == "button" || form_elements[i].type == "submit")
	    {
	        //break;
	    }
	    else
	    {
	        // alert(form_elements[i].name + " = " + form_elements[i].value);
            form_field = form_elements[i];
    	    
	        // if mandatory field
	        if (form_elements[i].getAttribute( "mandatory_field" )=="1")
	        {
                // if textbox or textarea empty
	            if (isStringEmpty(form_elements[i].value) || form_elements[i].type =="checkbox" && form_elements[i].checked ==false) 
	            {
	                alert_msg = form_elements[i].getAttribute( "mandatory_msg" );
                    if (alert_msg==undefined){
                        alert_msg = "Mandatory field"
                    }
                    alert ( alert_msg ); 
                    form_field.focus();
                    return false; 	
	            }
	         }
    	    
	        // if password
	        if (form_elements[i].getAttribute( "password_field" )=="1")
	        {
	            if (!confirmPassword())
	            {
	                alert_msg = form_elements[i].getAttribute( "confirm_msg" );
	                alert ( alert_msg ); 
                    form_field.focus();
	                return false;
	             }
	             
	             if (!validatePassword())
	            {
	                alert_msg = form_elements[i].getAttribute( "password_msg" );
	                alert ( alert_msg ); 
                    form_field.focus();
	                return false;
	             }
	        }
	        
	        // if numeric
    	    
	        // if email - test format
	        if (form_elements[i].getAttribute( "email_field" )=="1")
	        {
	             if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(form_elements[i].value))
	             {
	                //proper format -  do nothing      
	             }
	             else
	             {
	                 alert_msg = form_elements[i].getAttribute( "email_msg" );
                     if (alert_msg==undefined){
                        alert_msg = "Invalid email";
                     }
                     alert ( alert_msg );
                     form_field.focus();
                     return false; 	
	             }
	        }
	    } // end if buttons
    }

    
    // if reached here successfully, submit
    form_name.submit();
}

function confirmPassword()
{
    var strPassword = document.getElementById('password').value;
    var strConfirmPassword = document.getElementById('confirmPassword').value;

    if (strPassword != strConfirmPassword)
        return false;
        
    return true;

}

function validatePassword()
{
    var strPassword = document.getElementById('password').value;
    var strConfirmPassword = document.getElementById('confirmPassword').value;

    // count 6 chars
    if(strPassword.length < 6)
        return false;
    
    return true;
}

function ClearLoginForm(id1, id2)
{
    document.getElementById(id1).value = "";
    document.getElementById(id2).value = "";
}

function deleteFromCart(itemId, hiddenInputId, sizeInputId, size)
{
   if (confirm("האם ברצונך למחוק את הפריט הנבחר?")) 
    {
        document.getElementById(hiddenInputId).value = itemId;
        document.getElementById(sizeInputId).value = size;
        return true;
    }
    
    return false;
}

function DisplayBigDiv(id)
{
    document.getElementById(id).style.display = 'block';
}

function HideBigDiv(id)
{
    document.getElementById(id).style.display = 'none';
}

function MultiDimensionalArray(iRows, iCols) {
    var i;
    var j;
    var a = new Array(iRows);
    for (i = 0; i < iRows; i++) {
        a[i] = new Array(iCols);
        for (j = 0; j < iCols; j++) {
            a[i][j] = "";
        }
    }
    return (a);
}
            
