
function IsDec(e, objname)
{
  var keynum;
  var keychar;
  var numcheck;
  var obj = document.getElementById (objname);

  keynum = e.keyCode;

  keychar = String.fromCharCode(keynum);
  numcheck = /\d/
  if (keychar=='.')
  {
	if (obj.value.indexOf(".")>-1)
	return false;
  }
  else
	if (!numcheck.test(keychar))  return false;
	
  return true;		
}

function IsInt(e, objname)
{
  var keynum;
  var keychar;
  var numcheck;
  var obj = document.getElementById (objname);

  keynum = e.keyCode;

  keychar = String.fromCharCode(keynum);
  numcheck = /\d/
	
  return numcheck.test(keychar);		
}

function GetCookie(sName)
{
  // cookies are separated by semicolons
  var aCookie = document.cookie.split("; ");
  for (var i=0; i < aCookie.length; i++)
  {
    // a name/value pair (a crumb) is separated by an equal sign
    var aCrumb = aCookie[i].split("=");
    
    if (sName == aCrumb[0]) 
      return unescape(aCrumb[1]);      
  }

  // a cookie with the requested name does not exist
  return null;
}

function openme(url2open)
{
	leftVal = screen.width / 2 - 350;
	topVal = 30;

	var WinSettings = "left="+leftVal+",top="+topVal+",width=700,height=500,status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes";
	
	window.open(url2open,null,WinSettings);	
}

	var short_alert = 0;
	function ShortDescCheck()
  {
    val = document.getElementById("tbEO_PropShortDesc").value; 
    
    if (val.length > 110) 
    {
    	if(short_alert == 0)
    	{
        alert('You are over the limit of 110 characters. Please, edit.');
        short_alert = 1;
      }
      //document.getElementById("tbEO_PropShortDesc").value = val.substring(0,110);
      document.getElementById("tbEO_PropShortDesc").focus()
    }
    if((110-parseInt(document.getElementById("tbEO_PropShortDesc").value.length)) >= 0)
    	document.getElementById("tbEO_ShortDescCount").value=110-parseInt(document.getElementById("tbEO_PropShortDesc").value.length);          
    else
    	document.getElementById("tbEO_ShortDescCount").value = "EDIT!";
  }

	var long_alert = 0;  
  function LongDescCheck()
  {
    val = document.getElementById("tbEO_PropLongDesc").value; 
    if (val.length > 800) 
    {
    	if(long_alert == 0)
    	{
        alert('You are over the limit of 800 characters. Please, edit.');
        long_alert = 1;
      }
      //document.getElementById("tbEO_PropLongDesc").value = val.substring(0,800);
      document.getElementById("tbEO_PropLongDesc").focus()
    }
    if(800-parseInt(document.getElementById("tbEO_PropLongDesc").value.length) >= 0)
    	document.getElementById("tbEO_LongDescCount").value=800-parseInt(document.getElementById("tbEO_PropLongDesc").value.length);          
    else
    	document.getElementById("tbEO_LongDescCount").value = "EDIT!";
  }
  
  function CheckDescOnSubmit()
  {
  	if(document.getElementById('tbEO_PropShortDesc').value.length > 110)	
  	{
  		
  	  alert('Your short description field is over the limit of characters you have.');	
  	  return false;
  	}
  	
  	if(document.getElementById('tbEO_PropLongDesc').value.length > 800)	
  	{
  		
  	  alert('Your long description field is over the limit of characters you have.');	
  	  return false;
  	}
  	
  	return true;
  }
  
  var nextHiddenIndex = 3;
  function AddUploadPic()
  {    
    var new_pic = document.createElement("<input name=\"tbUploadPics[]\" type=\"file\" class=\"textbox\" style=\"width:280px\">");       
    var br = document.createElement("BR");
    document.getElementById("tdPics").appendChild(new_pic);
    document.getElementById("tdPics").appendChild(br);
    
    nextHiddenIndex++;
    if(nextHiddenIndex == 10)
    {
      document.getElementById("aAddPic").style.visibility = "hidden";
    }
  }
  
function OpenPic(href)
{
  window.open(href,'_blank','directories=no,fullscreen=no,location=no,menubar=no,resizable=no,scrollbars=no,status=no,titlebar=no,toolbar=no,width=600,height=600,top=50,left=100');        
}

function DisableCtrl(ctrl)
{
	document.getElementById(ctrl).disable = true;	
}

function del_item($to_url)
{
	if(confirm('Потвърдете изтриването?'))	
		return true;	
	else	
		return false;
}

/*
var nextHiddenIndex = 3;
  function AddUploadPic()
  {    
    var new_pic = document.createElement("<input name=\"tbUploadPics[]\" type=\"file\" class=\"text\" style=\"width:340px\">");       
    var br = document.createElement("BR");
    document.getElementById("tdPics").appendChild(new_pic);
    document.getElementById("tdPics").appendChild(br);
    
    nextHiddenIndex++;
    if(nextHiddenIndex == 10)
    {
      document.getElementById("aAddPic").style.visibility = "hidden";
    }
  }
*/

function OpenBigPic(to_url,orig_url)
{
	document.getElementById("aImg").onclick = function () {window.open(orig_url);return false;};
	document.getElementById("imgBig").src = to_url;	
	return false;
}

function OpenPopup(tourl)
{
	
	var wnd = window.open(tourl,'popupWindow','toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=yes, copyhistory=no, width=300, height=200, screenX=75, screenY=50, top=25, left=75');
  wnd.focus();	
}

function customSubmit(hdnInput,name,value,frm_name)
	{						
		for(i=0;i < document.forms.length;i++)
		{
			if(document.forms[i].name == frm_name)
			{								
				var hd = document.getElementById(hdnInput);
				
				hd.name = name;
				hd.value = value;				
				document.forms[i].submit();
			}
		}
	}
	
function SubmitForm(e,hdnInput,name,value,frm_name)
{	
	if ((e.which && e.which == 13) ||  
		(e.keyCode && e.keyCode == 13))  
	{
		e.returnValue = false;
		e.cancel = true;
		
		customSubmit(hdnInput,name,value,frm_name); 			
				
		return false;
	}  
	else 
		return true;
}	


