/* General module by Fredrik Schultz (c) 2006 */

function CustomEmail(source, args) {
  if(isValidEmail(args.Value))
    args.IsValid=true;
  else
    args.IsValid=false;
}

function isValidEmail(email) { if (email.length == 0) { return true; } if (email.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1) { return true; } else { return false; } }

function textCounter(field, countfield, maxlimit,StartCount) {
	len = field.value.length
	if ( len == 1 && field.value.substring(0,1) == " " ) {
		field.value = ""
		len = 0
	}

	if (field.value.length > maxlimit) // if too long...trim it!
		field.value = field.value.substring(0, maxlimit);
		// otherwise, update 'characters left' counter
	else 
		if ((maxlimit - field.value.length) <= StartCount) {
			countfield.innerHTML = maxlimit - field.value.length;
		}
		else {
			countfield.innerHTML = ""
		}
}

function getElement(myName) {
	try { 
		if(document.all[myName]) {
		  return document.all[myName];
		}
	} catch(e)  {
		try {
			if(document.getElementById) {
			  return document.getElementById(myName); 
			}
		}
		catch(e)  {}
	}
}

	
function expandTable(param1,param2, flag){
	if (flag == true){
		getElement(param1).style.display='none';
		getElement(param2).style.display='block';
		} 
	else{
		getElement(param1).style.display='block';
		getElement(param2).style.display='none';
	}
}

function expandAndResizeTable(param1,param2,param3, flag){
	if (flag == true)
	{
	   
		
		
		
		if(getElement(param1).offsetHeight > 80)
		{
		
		    var size = getElement(param1).offsetHeight*1.1;
		    getElement(param3).style.height =  size  +"px";
		    
		}
	
		getElement(param1).style.display='none';
		getElement(param2).style.display='block';
		
	} 
	else{
		getElement(param1).style.display='block';
		getElement(param2).style.display='none';
	}
}


function expandAndResizePolaroid(param1,param2,param3, flag){
	if (flag == true)
	{
	   
		
		
		
		if(getElement(param1).offsetHeight > 35)
		{
		
		    var size = getElement(param1).offsetHeight*1.1;
		    if(size > 200)
		        size = 190;
		    getElement(param3).style.height =  size  +"px";
		    
		}
	
		getElement(param1).style.display='none';
		getElement(param2).style.display='block';
		
	} 
	else{
		getElement(param1).style.display='block';
		getElement(param2).style.display='none';
	}
}


// Glitter specific code below:

    var langscroll;
    var langgoingup=false;
    var langheight=0;
		    
    function langup() {
      langheight-=2;
      getElement("langbox").style.height=langheight+"px";
      if(langheight==0) clearInterval(langscroll);
    }		    
    
    function langdown() {
      langheight+=2;
      getElement("langbox").style.height=langheight+"px";
      if(langheight==40) clearInterval(langscroll);
    }
    
    function langclick() {
      if(langgoingup)
        langscroll=setInterval('langup()',20);
      else
        langscroll=setInterval('langdown()',20);
        
       langgoingup=!langgoingup;
    }

    function closeTools()
    {
        hideToolBox();

    }
       
    function getWindowSize(){
        var de = document.documentElement;
        var w = window.innerWidth || self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
        var h = window.innerHeight || self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight;
        arrayPageSize = [w,h];
        return arrayPageSize;
    }
   
    function ShowEditPicture(heading){
        closeTools();
        jQuery(document.getElementById('handler')).css({display: 'block'});
     
        
        var WindowSize = getWindowSize();
        var width;
        var height;
        if  ((WindowSize[0]*0.95) < 730) {
            width = (WindowSize[0]*0.95);
         } else {
            width = 623; // min width to be able to crop a 800px wide pic (thickbox.js adds width)
        }
        width = width + 200;
        height = WindowSize[1]*0.92 - 40;
        
        tb_show('<h1>'+heading +'</h1>','#TB_inline?height=' + height + '&width=' + width +'&inlineId=EditPicture&cropHandler=true',false);
        getElement('TB_ajaxContent').style.overflow="hidden"; /* kill the scroll */
    }
    
    function ShowEditSizePicture(heading,width,height)
    {
        closeTools();
        jQuery(document.getElementById('handler')).css({display: 'block'});
     
        
        tb_show('<h1>'+heading +'</h1>','#TB_inline?height=' + height + '&width=' + width +'&inlineId=EditPicture&cropHandler=true',false);
        getElement('TB_ajaxContent').style.overflow="hidden"; /* kill the scroll */
    }
    
    
    function showLargePicture(picname, picurl)
    {
        tb_show('',picurl,'none');
    }
    

    function hiddenFloatingDiv()
    {
       tb_remove();
  
       
    }


