var winresult;
var tmp_img = null;
var isSearchDateEnb = false;

var img = new Array();

var cm = 0;
var selMenu = 0;
var eTime;


function manParseToDateObj(inStr)
{
	sdateA = inStr.split("/");
	var tmpDate = new Date();
	tmp = parseInt(1*sdateA[0])-1;
	if(tmp < 0) tmp = 11;
	tmpDate.setMonth(tmp);
	tmpDate.setDate(parseInt(1*sdateA[1]));
	if(parseInt(1*sdateA[2])<1000) tmpDate.setYear(2000+parseInt(1*sdateA[2]));
	else tmpDate.setYear(parseInt(1*sdateA[2]));
	
	return tmpDate;
}



function CheckCharacterUP()
{
  if (String.fromCharCode(event.keyCode) >= "A" && 
      String.fromCharCode(event.keyCode) <= "Z" ) {
    return true; }
  else {
    return false;
  }
}

function isNumericKey(e)
{
	var k = document.all ? e.keyCode : e.which;
	return ((k > 47 && k < 58) || k == 8 || k == 0);
}

function extractNumeric(str)
{
	return str.replace(/\D/g,"");
}

function CheckNumber()
{
  if (String.fromCharCode(event.keyCode) >= "0" && 
      String.fromCharCode(event.keyCode) <= "9" ) {
    return true; }
  else {
    return false;
  }
}


function stripHTML(oldString)
{

   var newString = "";
   var inTag = false;
   for(var i = 0; i < oldString.length; i++) {
   
        if(oldString.charAt(i) == '<') inTag = true;
        if(oldString.charAt(i) == '>') {
              inTag = false;
              i++;
        }
   
        if(!inTag) newString += oldString.charAt(i);

   }

   return newString;
}

function html_edit_popup(fname,field)
{
	if(!is_ie5_5up)
	{
		alert("Editor is working with IE 5.5 or hight.");
		return;
	}
	try{if (winresult) winresult.close();}
	catch(Exception){}
	win_h = 470;
	win_w = 780;
	left_pos = (screen.width - (1*win_w))/2;
	top_pos = (screen.height - (1*win_h))/2;
	win_add_w = 0;
	if(left_pos<40)
	{
		left_pos = 40;
		win_w = screen.width-80;
	}
	tt_win_w = 1*win_w;
	if(top_pos<40)
	{
		top_pos = 20;
		win_h = screen.height-80;
	}
	winresult = open("/htmleditor/?fname="+fname+"&field="+field, "displayWindow","width="+tt_win_w+",height="+win_h+",left="+left_pos+",top="+top_pos+",resizable=yes,status=no,toolbar=no,menubar=no,scrollbars=auto");
	winresult.focus();
}

function m_close(time)
{
	if(time > eTime || time == 0)
	{		
		try
		{
			document.getElementById('m'+cm).style.backgroundColor="#cfcfcf";
			document.images['i'+cm].src = img[0].src;
			document.getElementById('sub'+cm).style.visibility = 'hidden';
			
		}catch(Exception){}
		cm = 0;
		
		if(time > 0 && selMenu > 0)
		{
			document.getElementById('m'+selMenu).style.backgroundColor="#eeeeee";
			//document.images['i'+selMenu].src = img[1].src;
			//document.getElementById('sub'+selMenu).style.visibility = 'visible';	
		}	
	}
}

function openSelMenu()
{
	if(selMenu>0) 
	{
		document.getElementById('sub'+selMenu).style.visibility = 'visible';	
		if(cm > 0)
		{
			m_close(0);
		}
	}	
}

function go(path)
{
	document.location.href = path;
}


function winopen(path,ind)
{
  window.open(path,'img'+ind,'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no');
}

function form_submit(name)
{
	document.forms[name].submit();
}



var ie=document.all;
var nn6=document.getElementById&&!document.all;
var isdrag=false;
var x,y;
var dobj;

function movemouse(e)
{
  if (isdrag)
  {
    dobj.style.left = nn6 ? tx + e.clientX - x : tx + event.clientX - x;
    dobj.style.top  = nn6 ? ty + e.clientY - y : ty + event.clientY - y;
    return false;
  }
}
/*
function selectmouse(e)
{
  var fobj       = nn6 ? e.target : event.srcElement;
  var topelement = nn6 ? "HTML" : "BODY";
  while (fobj.tagName != topelement && fobj.className != "dragme")
  {
    fobj = nn6 ? fobj.parentNode : fobj.parentElement;
  }
  if (fobj.className=="dragme")
  {
    isdrag = true;
    dobj = fobj;
    tx = parseInt(dobj.style.left+0,10);
    ty = parseInt(dobj.style.top+0,10);
    x = nn6 ? e.clientX : event.clientX;
    y = nn6 ? e.clientY : event.clientY;
    document.onmousemove=movemouse;
    return false;
  }
}
document.onmousedown=selectmouse;
document.onmouseup=new Function("isdrag=false");
*/
function savePageURL()
{
	d = document;
	iTime = new Date();
	var a = '<img style="position:absolute" src="/index/?savepageurl=1&f=';
	a += escape(d.location.href);
	a += "&time=";
	a += iTime.getMilliseconds();
	a += '" width="1" height="1" border="0" />';
	document.write(a);
}

function objOn(obj)
{
	obj.style.display = "block";
	obj.style.visibility = "visible";
}	

function objOff(obj)
{
	obj.style.visibility = "hidden";
	obj.style.display = "none";
}
    
   
var tmpCashImg = new Array();

function cashImage(img)
{	
	tmpCashImg[tmpCashImg.length] = new Image();
	tmpCashImg[tmpCashImg.length-1].src = img;
}

var nextSelBool = true;

function selAll(form,el_name)
{
	var form = document.forms[form];
	
	for(var i=0; i<form.length; i++)
	{
		if(form[i].name.substring(0,el_name.length) == el_name) form[i].checked = nextSelBool;
	}
	nextSelBool = nextSelBool == true ? false : true;
}

function recalc()
{
	var f = document.forms['cart'];
	f.action.value = "is_recalculate";
	f.submit();
}

function del()
{
	var f = document.forms['cart'];
	f.action.value = "is_delete";
	f.submit();
}

function setSort(type)
{
	var type = type ? parseInt(1*type) : 0;
	var o = document.forms['sort'].sort;
	if(type > 0)
	{
		for(i=0;i<=o.length;i++)
			if(o[i].value == type)
			{
				o[i].selected = true;
				break;
			}
	}
}


function runJsScript(inStr)
{
	var re = /<script[^>]*>([^<]+)<\/script>/ig;
	var ar = re.exec(inStr);
	
	if(ar == null) ar = re.exec(inStr); // For Mozilla
	
	if(ar != null) eval(ar[1]);
	else updateMap(new Array());		
}

function show_wndw(n,t)
{
	if ( document.getElementById(n).style.display == 'block' )
	{
		document.getElementById(n).style.display='none';
	}
	else
	{
		//document.getElementById('form_login').style.display='none';
		//document.getElementById('form_register').style.display='none';
		document.getElementById(n).style.display='block';
	}
} 
function close_wndw(n,t)
{
	document.getElementById(n).style.display='none';
}


