// JavaScript Document
//funciton for draging the elemtn
// {{{ implode
function implode( glue, pieces ) {
    // Join array elements with a string
    // 
    // +    discuss at: http://kevin.vanzonneveld.net/techblog/article/javascript_equivalent_for_phps_implode/
    // +       version: 801.3120
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: _argos
    // *     example 1: implode(' ', ['Kevin', 'van', 'Zonneveld']);
    // *     returns 1: 'Kevin van Zonneveld'

    return ( ( pieces instanceof Array ) ? pieces.join ( glue ) : pieces );
}// }}}


// {{{ in_array
function in_array(needle, haystack, strict) {
    // Checks if a value exists in an array
    // 
    // +    discuss at: http://kevin.vanzonneveld.net/techblog/article/javascript_equivalent_for_phps_in_array/
    // +       version: 801.3120
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: in_array('van', ['Kevin', 'van', 'Zonneveld']);
    // *     returns 1: true

    var found = false, key, strict = !!strict;

    for (key in haystack) {
        if ((strict && haystack[key] === needle) || (!strict && haystack[key] == needle)) {
            found = true;
            break;
        }
    }

    return found;
}// }}}


//navigation menu
function mainmenu(){
$("#nav ul ").css({display: "none"}); // Opera Fix
$("#nav li").hover(function(){
		$(this).find('ul:first').css({visibility: "visible",display: "none"}).show(400);
		},function(){
		$(this).find('ul:first').css({visibility: "hidden"});
		});
}

function sidemenu(){
$(".product_ul ul ").css({display: "none"}); // Opera Fix
$(".product_ul li").hover(function(){
		$(this).find('ul:first').css({visibility: "visible",display: "none","top":$(this).offset().top,"left":($(this).offset().left)+85}).show(400);
		
		},function(){
		$(this).find('ul:first').css({visibility: "hidden"});
		});
}



function UploadError(a, b, c, d)
{
         if (d.status == 404)
            alert('Could not find upload script. Use a path relative to: '+'<?= getcwd() ?>');
         else if (d.type === "HTTP")
            alert('error '+d.type+": "+d.status);
         else if (d.type ==="File Size")
            alert(c.name+' '+d.type+' Limit: '+Math.round(d.sizeLimit/1024)+'KB');
         else
            alert('error '+d.type+": "+d.text);
}

function UploadCompleted(evt,data) 
{
 
  $('#upload_response').html('Batch upload has been finished succesfully.').css('display','');
  
}

function isNumberKey(evt)
      {
         var charCode = (evt.which) ? evt.which : event.keyCode
         if (charCode > 31 && (charCode < 48 || charCode > 57))
            return false;

         return true;
      }
function isDecimalKey(evt)
      {
         var charCode = (evt.which) ? evt.which : event.keyCode
         if (charCode > 31 && (charCode < 48 || charCode > 57) && charCode!=46 )
            return false;

         return true;
      }	 
	
function unblockme()
{
  $.unblockUI();
}

function closeFancy()
{
  $.fancybox.close();  
}

function setupLabel() 
{
  if ($('.label_check input').length) 
   {
      $('.label_check').each(function(){
      $(this).removeClass('c_on');
     });
  $('.label_check input:checked').each(function(){
     $(this).parent('label').addClass('c_on');
     });
   };
 if ($('.label_radio input').length) {
    $('.label_radio').each(function(){
    $(this).removeClass('r_on');
 });
 $('.label_radio input:checked').each(function(){
    $(this).parent('label').addClass('r_on');
    });
   };
 }

function showHide(id1,id2)
{
   	 $('#'+id2).hide();
	 $('#'+id1).show();
}




function updateDefaultTest(obj,val)
{
  if(obj.value=="Start typing the file's name or product name" && val==1)
  obj.value='';
  
  if(obj.value=='' && val==0)
  obj.value="Start typing the file's name or product name";
}

function updateDefaulUser(obj,val)
{
  if(obj.value=="Start typing the user's name or company" && val==1)
  obj.value='';
  
  if(obj.value=='' && val==0)
  obj.value="Start typing the user's name or company";
}

function updateDefaultQuote(obj,val)
{
  if(obj.value=="Start typing the quote" && val==1)
  obj.value='';
  
  if(obj.value=='' && val==0)
  obj.value="Start typing the quote";
}
function updateDefaultTeam(obj,val)
{
  if(obj.value=="Start typing the name or title" && val==1)
  obj.value='';
  
  if(obj.value=='' && val==0)
  obj.value="Start typing the name or title";
}

function updateDefaultForm(obj,val)
{
  if(obj.value=="Start typing the form's title" && val==1)
  obj.value='';
  
  if(obj.value=='' && val==0)
  obj.value="Start typing the form's title";
}

function updateDefaultCategory(obj,val)
{
  if(obj.value=="Start typing the category name" && val==1)
  obj.value='';
  
  if(obj.value=='' && val==0)
  obj.value="Start typing the category name";
}

function updateDefaultFormCategory(obj,val)
{
  if(obj.value=="Start typing the category name" && val==1)
  obj.value='';
  
  if(obj.value=='' && val==0)
  obj.value="Start typing the category name";
}

function updateDefaultProduct(obj,val)
{
  if(obj.value=="Start typing product name" && val==1)
  obj.value='';
  
  if(obj.value=='' && val==0)
  obj.value="Start typing product name";
}

function updateDefaultNews(obj,val)
{
  if(obj.value=="Start typing the news title" && val==1)
  obj.value='';
  
  if(obj.value=='' && val==0)
  obj.value="Start typing the news title";
}

function updateDefaultFeature(obj,val)
{
  if(obj.value=="Start typing the name" && val==1)
  obj.value='';
  
  if(obj.value=='' && val==0)
  obj.value="Start typing the name";
}


function updateDefaultLink(obj,val)
{
  if(obj.value=="Start typing the link name" && val==1)
  obj.value='';
  
  if(obj.value=='' && val==0)
  obj.value="Start typing the link name";
}







function hideMsg()
{
  $("#form_resp").css("display","none");
}



function getImgExt(file){
	    file=file.toLowerCase();
        return (-1 !== file.indexOf('.')) ? file.replace(/.*[.]/, '') : '';
    }
	
	
	

function searchSite()
{
  if(document.getElementById('skeyword').value=='') {alert('Please enter a keyword');return false;}
  
  document.getElementById('searchForm').submit();
  
}

$(document).ready(function(){				
	mainmenu();
	//sidemenu();
	$('.label_check, .label_radio').click(function(){
        setupLabel();
    });
   setupLabel(); 
	//$.pseudoFocus();
});


