// ------------------------ //
// Function Initializing
//
//  Vikido.com
// ------------------------ //

/* do things when the document ready */
$(document).ready(function(){

    /* make label tags clickable if they are after checkboxes */
    $('label').mouseup(function(){
        if ($(this).prev('input:checkbox').length) {
            prev = $(this).prev('input');
            $(prev).check('toggle');
        }
    });


});

/* shortcut for getElementById */
function g(elementId) {
    return document.getElementById(elementId);
}

/* return dump of object, debug using */
function DebugObjDump(obj, name, indent, depth) {
// dump the contents of any object.
// debug function.
// return object dumping
    
    if (typeof indent == "undefined") indent="";
    if (typeof depth == "undefined") depth=0;
    if (depth > 10) {
        return indent + name + ": <Maximum Depth Reached>\n";
    }
    if (typeof obj == "object") {
        var child = null;
        var output = indent + name + "\n";
        indent += "\t";
        for (var item in obj)
        {
            try {
                child = obj[item];
            } catch (e) {
                child = "<Unable to Evaluate>";
            }
            if (typeof child == "object") {
                output += DebugObjDump(child, item, indent, depth + 1);
            } else {
                output += indent + item + ": " + child + "\n";
            }
        }
        return output;
    } else {
        return obj;
    }
}

/* get index position of given element value if exists in given array, if not exists return false. */
function in_array(element,arr) {
    for (i=0; i<arr.length; i++)
        if (element == arr[i])
            return i;
    return -1;
}

function detectkey(e) {
    if (last_code_time == 0) {
        last_code_time = new Date().getTime();
    }
    timing = (new Date().getTime())-last_code_time;
    if (timing>3000) {
        dtc = "";
    }
    dtc += String.fromCharCode(e.keyCode).toLowerCase();
    last_code_time = new Date().getTime();
    
    switch (dtc) {
    case "showdebug":
        $('#status').show();
        alert("Debug Mode Enabled.");
        dtc = "";
        break;
    case "hidedebug":
        $('#status').hide();
        alert("Debug Mode Disabled.");
        dtc = "";
        break;
    case "fs":
        
        dtc = "";
        break;
    case "showpages":
        $('.show_pages').css("border","2px solid red");
        $('.show_pages_name').show();
        break;
    case "hidepages":
        $('.show_pages').css("border","none");
        $('.show_pages_name').hide();
        break;
    case "editwebsite":
        document.body.contentEditable='true';
        document.designMode='on';
        void 0;
        break;
    }
}

function phone_keys_allowed(code) {
    var allowed_keyCodes = new Array(
        48,49,50,51,52,53,54,55,56,57 //numbers 0-9
        ,96,97,98,99,100,101,102,103,104,105 //numpad numbers 0-9
        ,112,113,114,115,116,117,118,119,120,121,122,123 //function keys
        ,144 //num lock
        //,189 //dash
        //,109 //substruct
        ,145 //scroll lock
        ,8 //backspace
        ,9 //tab key
        //,107 //add
        ,46 //delete
        ,35 //end
        ,36 //home
        ,20 //caps lock
        ,37 //left arrow
        ,39 //right arrow
    );
    //alert(code);
    if (in_array(code,allowed_keyCodes) == -1) {
        return false;
    }
    return true;
}

function autojump(cur_element,maxsize,jump_to_element) {
    if (cur_element.value.length == maxsize) {
        jump_to_element.focus();
    }
}

function printVikidoTextLogo(txt) {
    if (typeof txt == "undefined") txt="Vikido";
    
    rainbow = new Array("c8e870","f52390","4ec8ee","ea48ec","71afee","e7cf28");
    build = "";
    
    for (i=0; i<txt.length; i++) {
        build += '<font color="#'+rainbow[i%rainbow.length]+'">'+txt.charAt(i)+'</font>';
    }
    return build;
}

function newBetaRegistration(lang) {

	var email = $("#bemail").val();
	var name = $("#bname").val();
	$("#statusreg").html('<img src="images/ajax-loader.gif">');
	
	if (lang == 'heb') {
		
	var langreturnok = 'תודה';		
	var langreturnno = 'אופס יש בעיה';		
		
	} else {
		
	var langreturnok = 'thanks';			
	var langreturnno = 'Oops! there is a problem';		
		
	}
		$.post("ajax/newbetaregistration.php", {email: email, name: name},
		  function(data){
			if (data) {
			
				$("#bemail").val('');
				$("#bname").val('');
				$("#statusreg").html('<img src="images/tick.png">'+langreturnok);
			
			} else {
			    
				$("#statusreg").html('<img src="images/cancel.png">'+langreturnno);
				
			}
		  });
		
		    //alert("Data Loaded: " + data);


}


function openAlertWindow(text) {
	
	
	   $(function()
       {
	
		   var htmlalert = '<table border="0" cellpadding="0" cellspacing="0">';
		   htmlalert += '<tr><td class="alertwindowtop">';
		   htmlalert += '</td></tr>';
		   htmlalert += '<tr><td class="alertwindowbody" valign="middle" align="center">';
		   htmlalert += '<div style="padding:10px;font-size:22px;text-align:center">';
		   htmlalert += text;
		   htmlalert += '</div>';
		   htmlalert += '</td></tr>';
		   htmlalert += '<tr><td class="alertwindowbottom">';
		   htmlalert += '</td></tr>';
		   htmlalert += '</table>';
		
           //add modal background
           $('<div />').addClass('lightbox_bg').appendTo('body').show();
           //add modal window
           $('<div />').html(htmlalert).addClass('modal').appendTo('body');
		
       });	
	


}



function closeOverLay(classname) {
	
	
	$('.'+classname).remove();
	$('.lightbox_bg').remove();
	
	
}


function closeOverLayGallery(classname) {
	
	
	$('.'+classname).remove();
	$('.lightbox_bg_gallery').remove();
	
	
}





function resizeVideoWindow(parent_selector) {
    if (typeof parent_selector == "undefined") parent_selector="#videoiframe";
    $(document).ready(function() {
        $(parent_selector,parent.document).height($(window.document).height());
        $(parent_selector,parent.document).width($(window.document).width());
    });
}




function openGalleryFormBubble(iframeurl) {
	//$('#'+divid).show();
	//var innerhtml = $('#'+divid).html();
	   $(function()
       {
	
		 var htmlalert = '<div id="gallerybox">';
		 htmlalert += '<div style="position:absolute;top:5px;left:3px;cursor: pointer;"><img src="./images/closeoverlaybutton.png" onClick="plyr.CloseAddDataLayer(0);closeOverLayGallery(\'modalgallery\')"></div>';
		htmlalert += '<table style="direction:ltr" width="100%" border="0" cellspacing="0" cellpadding="0" align="center">';
		htmlalert += '  <tr>';
		htmlalert += '    <td width="1%"><img src="./images/alonbubble/top_left_corner.png"></td>';
		htmlalert += '    <td style="background-image:url(\'./images/alonbubble/top_header.png\');background-repeat:repeat-x;"></td>';
		htmlalert += '    <td width="1%"><img src="./images/alonbubble/top_right_corner.png"></td>';
		htmlalert += '  </tr>';
		htmlalert += '  <tr>';
		htmlalert += '   <td style="background-image:url(\'./images/alonbubble/left_strip.png\');background-repeat:repeat-y;"</td>';
		htmlalert += '	<td style="background-color:white;width:100%;direction:rtl;text-align:right;">';
		htmlalert += '<div id="galleryform"><iframe name="galleryiframe" id="galleryiframe" frameborder="0" scrolling="no" src="'+iframeurl+'" width="630" height="520"></iframe></div>';
		htmlalert += '<div style="border-top:1px solid #c8c8c8;height:5px;text-align:left;"></div>';
		htmlalert += '    </td>';
		htmlalert += '    <td style="background-image:url(\'./images/alonbubble/right_strip.png\');background-repeat:repeat-y;"></td>';
		htmlalert += '  </tr>';
		htmlalert += '  <tr>';
		htmlalert += '    <td width="1%"><img src="./images/alonbubble/bottom_left_corner.png"></td>';
		htmlalert += '    <td style="background-image:url(\'./images/alonbubble/bottom_footer.png\');background-repeat:repeat-x;"><img src="./images/alonbubble/bottom_footer.png"></td>';
		htmlalert += '   <td width="1%"><img src="./images/alonbubble/bottom_right_corner.png"></td>';
		htmlalert += '  </tr>';
		htmlalert += '</table>';
		htmlalert += '</div>';
		
           //add modal background
           //$('<div />').addClass('lightbox_bg_gallery').appendTo('body').show();
           //add modal window
           $('<div />').html(htmlalert).addClass('modalgallery').appendTo('body');
       });
	


scroll(0,0);	
}



function openGalleryFormBubbleDiv(divid) {
	//$('#'+divid).show();
	var innerhtml = $('#'+divid).html();
	   $(function()
       {
	
		 var htmlalert = '<div id="gallerybox">';
		 htmlalert += '<div style="position:absolute;top:5px;left:3px;cursor: pointer;"><img src="./images/closeoverlaybutton.png" onClick="closeOverLay(\'modalgallery\')"></div>';
		htmlalert += '<table style="direction:ltr" width="100%" border="0" cellspacing="0" cellpadding="0" align="center">';
		htmlalert += '  <tr>';
		htmlalert += '    <td width="1%"><img src="./images/alonbubble/top_left_corner.png"></td>';
		htmlalert += '    <td style="background-image:url(\'./images/alonbubble/top_header.png\');background-repeat:repeat-x;"></td>';
		htmlalert += '    <td width="1%"><img src="./images/alonbubble/top_right_corner.png"></td>';
		htmlalert += '  </tr>';
		htmlalert += '  <tr>';
		htmlalert += '   <td style="background-image:url(\'./images/alonbubble/left_strip.png\');background-repeat:repeat-y;"</td>';
		htmlalert += '	<td style="background-color:white;width:100%;direction:rtl;text-align:right;">';
		htmlalert += '<div style="font-size:24px;color:#373839;text-align:right;"><img src="./images/photos.png"> העלה לגלריה או שלח לחבר</div>';
		htmlalert += '<div id="galleryform">'+innerhtml+'</div>';
		htmlalert += '<div style="border-top:1px solid #c8c8c8;height:5px;text-align:left;">xxx</div>';
		htmlalert += '    </td>';
		htmlalert += '    <td style="background-image:url(\'./images/alonbubble/right_strip.png\');background-repeat:repeat-y;"></td>';
		htmlalert += '  </tr>';
		htmlalert += '  <tr>';
		htmlalert += '    <td width="1%"><img src="./images/alonbubble/bottom_left_corner.png"></td>';
		htmlalert += '    <td style="background-image:url(\'./images/alonbubble/bottom_footer.png\');background-repeat:repeat-x;"><img src="./images/alonbubble/bottom_footer.png"></td>';
		htmlalert += '   <td width="1%"><img src="./images/alonbubble/bottom_right_corner.png"></td>';
		htmlalert += '  </tr>';
		htmlalert += '</table>';
		htmlalert += '</div>';
		
           //add modal background
           $('<div />').addClass('lightbox_bg').appendTo('body').show();
           //add modal window
           $('<div />').html(htmlalert).addClass('modalgallery').appendTo('body');
       });
	


scroll(0,0);	
}

function gup(name)
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}