var Tout;

function Toggle(id1,id2,obj,color){
  setTimeout(function(){ChangeColor(obj,color);},0);
  document.getElementById(id1).style.display ="none";
  document.getElementById(id2).style.display ="block";  
}

function ChangeColor(obj,color){
  obj.style.backgroundColor ="#"+color;
}


function linkMouseOver(obj){
  obj.style.backgroundColor ="#A33905";
  obj.style.color  = "#fff";
}


function linkMouseOut(obj){
  obj.style.backgroundColor="#fff";
  obj.style.color="#000";
}


function _show(id,num){ 
   if(Tout!="") clearTimeout(Tout); 
   
   var subs = getElementsByClassName('mainmenu_sub');
   for(var i = 0; i < subs.length; i++) {
     subs[i].style.display="none";
     menuOutStyle(subs[i].id.substring(3));
   }
   menuOverStyle(id);
   $('div'+id).style.display="block";
}

function _hide(id){ 
   if(Tout!=""){
      clearTimeout(Tout); 
   }   
   Tout=setTimeout("$('div"+id+"').style.display='none';menuOutStyle("+id+")",200);
}


function getElementsByClassName(cl) {
 var retnode = [];
 var myclass = new RegExp('\\b'+cl+'\\b');
 var elem = document.getElementsByTagName("*");
 for (var i = 0; i < elem.length; i++) {
   var classes = elem[i].className;
   if (myclass.test(classes)) retnode.push(elem[i]);
 }
 return retnode;
}




function menuOverStyle(id){
   $('a'+id).style.color='#0066CC';
   $('i'+id).src  ='images/nav_up.gif';
   $('menu'+id).style.backgroundImage='url(images/menu_over.gif)';
}

function menuOutStyle(id){
   $('a'+id).style.color='#FFFFFF';
   $('i'+id).src  ='images/white_bullet_down.gif';
   $('menu'+id).style.backgroundImage='none';
}



function lng(lng) {
	var current=window.location.href;
	var new_loc;
	if(/lng=/.test(current))
		new_loc=current.replace(/lng=\w*/,"lng="+lng);
	else if(/\?/.test(current))
		new_loc=current+"&lng="+lng;
	else 
		new_loc=current+"?lng="+lng;  
	window.location.replace(new_loc);
}

function default_currency(objSelect) {
	var new_loc;
	var current=window.location.href;
	var value = objSelect.options[objSelect.selectedIndex].value;
	
	if(/default_currency=/.test(current))
		new_loc=current.replace(/default_currency=\w*/,"default_currency="+value);
	else if(/\?/.test(current))
		new_loc=current+"&default_currency="+value;
	else 
		new_loc=current+"?default_currency="+value;  
	window.location.replace(new_loc);
}

var send = function(link){
	var dataToSend = document.getElementById('calendar_y').value+"."+document.getElementById('calendar_m').value;
	var ajax = new httpAjaxRequest(); 
	var ajax_url = link.replace('index.php','ajax.php');
	if(ajax) {  
		ajax.prepareHash({date:dataToSend}); 
		ajax.open("GET", ajax_url);
		ajax.send();
		ajax.getData();
		ajax.onreadystatechange = function() { 
			data =ajax.getResult();
			document.getElementById("calendar_div").innerHTML =data.calendar; 
		}  
	}
	else window.location =link + document.getElementById('calendar_y').value+"."+document.getElementById('calendar_m').value; 
}

 
function showPic(pic,width,height) { 
  sDesrc = "width=" + width + ", height=" + height +
  		", status=no, toolbar=no, menubar=no, scrollbars=no";
  win=window.open("Gallery", "", sDesrc);
  win.document.write("<html><style>body{padding:0px;margin:0px;}</style><body>");
  win.document.write("<img src='uploads_script/gallery/"+pic+"' width='"+width+"' height='"+height+"'><br>");
  win.document.write("</body></html>");
  win.document.close();
} 

function showPic_(pic_src,width,height) { 
  sDesrc = "width=" + width + ", height=" + height + ", status=no, toolbar=no, menubar=no, scrollbars=no";
  win=window.open("Gallery", "", sDesrc);
  win.document.write("<html><style>body{padding:0px;margin:0px;}</style><body>");
  win.document.write("<img src='"+pic_src+"' width='"+width+"' height='"+height+"'><br>");
  win.document.write("</body></html>");
  win.document.close();
} 



function writeCookie(cookieName, cookieContent, cookieExpireTime){
	var cookiePath = '/';
	if(cookieExpireTime>0){
		var expDate=new Date()
		expDate.setTime(expDate.getTime()+cookieExpireTime*1000*60*60)
		var expires=expDate.toGMTString()
		document.cookie=cookieName+"="+escape(cookieContent)+";path="+escape(cookiePath)+";expires="+expires+";";
	}
    else
		document.cookie=cookieName+"="+escape(cookieContent)+";path="+escape(cookiePath)+";";
}

function readCookie(cookieName){
	var ourCookie=document.cookie;
	if(!ourCookie || ourCookie=="")return "";
	ourCookie=ourCookie.split(";")
	var i=0;
	var Cookie;
	while(i<ourCookie.length){
		Cookie=ourCookie[i].split("=")[0];
		if(Cookie.charAt(0)==" ")
		Cookie=Cookie.substring(1);
		if(Cookie==cookieName){
			return unescape(ourCookie[i].split("=")[1]);
		}
		i++;
	}
	return "";
}

function deleteCookie(cookieName){
	var cookiePath = '/';
	document.cookie=cookieName+"="+readCookie(cookieName)+";path="+escape(cookiePath)+";expires=Thu, 01-Jan-1970 00:00:01 GMT;";
}


// GR
function previewPic(table_id,pic){
	document.getElementById(table_id).innerHTML = '<img src="'+pic+'">';
}

function CheckAll(formname,groupname) {
	for(i=0;i<document.forms[formname].elements.length;i++) {
		if(document.forms[formname].elements[i].name == groupname+"[]") {
			document.forms[formname].elements[i].checked = document.forms[formname].elements[i].checked?false:true;
		}
    }
}

function showHide(elmID,param) {
	var obj = document.getElementById(elmID);
	if (param == 'show' || param == 'block') {
		obj.style.display = 'block';
	}
	else if (param == 'hide' || param == 'none') {
		obj.style.display = 'none';
	}
	else {
		obj.style.display = (obj.style.display == 'none')?'block':'none';
	}
}

function CheckIsIE() {
	if (navigator.appName.toUpperCase() == 'MICROSOFT INTERNET EXPLORER') 
		return true;
	else
		return false;
}

// For printing iframes
function print_innerHTML(parseFrom,iframeTo,css_src) {
	document.getElementById(iframeTo).contentWindow.document.body.innerHTML = document.getElementById(parseFrom).innerHTML;
	if (CheckIsIE()==true) {
		iframe = eval ('document.'+iframeTo);
		iframe.close();
		importCSS(get_DOC(document.getElementById(iframeTo)),css_src);
		iframe.focus();
		iframe.print();
	}
	else {
		importCSS(get_DOC(document.getElementById(iframeTo)),css_src);
		document.getElementById(iframeTo).contentWindow.print();
	}
}

function importCSS(doc, css) {
	var css_ary = css.replace(/\s+/, '').split(',');
	var csslen, elm, headArr, x, css_file;

	for (x = 0, csslen = css_ary.length; x<csslen; x++) {
		css_file = css_ary[x];

		if (css_file != null && css_file != 'null' && css_file.length > 0) {
			// Is relative, make absolute
			if (css_file.indexOf('://') == -1 && css_file.charAt(0) != '/')
				css_file = this.documentBasePath + "/" + css_file;

			if (typeof(doc.createStyleSheet) == "undefined") {
				elm = doc.createElement("link");

				elm.rel = "stylesheet";
				elm.href = css_file;

				if ((headArr = doc.getElementsByTagName("head")) != null && headArr.length > 0)
					headArr[0].appendChild(elm);
			} else
				doc.createStyleSheet(css_file);
		}
	}
}

function get_DOC(iframe) {
	if(iframe.contentWindow) 
		return iframe.contentWindow.document;
	else if (iframe.contentDocument) 
		return iframe.contentDocument; 
	else 
		return iframe.document;
}





function AjaxSubmit_form(url,div_parseInto,httpmethod,formname,onComplete_function) {
	httpmethod = (httpmethod=='POST')?'POST':'GET';
	onComplete_function = onComplete_function||'';
    var Param = Form.serialize(formname);
    var myAjax = new Ajax.Updater (div_parseInto,url,{method: httpmethod, parameters: Param, evalScripts: true, onComplete: onComplete_function});//, onComplete: showResult
    //alert(myAjax.Responders);
}

function AjaxSubmit_noform(url,div_parseInto) {
	var myAjax = new Ajax.PeriodicUpdater (div_parseInto,url,{
						method: "GET",
						evalScripts: true,
						onFailure: function() {alert('Failure');}
					}
				); 
}

function AjaxSubmit_noform_periodical(url,div_parseInto,refresh_time) {
	refresh_time = refresh_time || 3;
	var myAjax = new Ajax.PeriodicalUpdater(div_parseInto,url,{
						method: "GET",
						frequency: refresh_time, 
						evalScripts: true,
						onFailure: function() {alert('Failure');}
					}
				); 
}


function ajax_subscribe(div_id,url,elId_email) {
	if (document.getElementById('subscribe_me').checked) {
		var subscribe = 'subscribe';
	}
	else {
		var subscribe = 'unsubscribe';
	}
	url = url + '&email=' + document.getElementById(elId_email).value + '&action=' + subscribe;
	
	var myAjax = new Ajax.Updater	(div_id,url,{
													method: 'GET',
													evalScripts: true,
													onComplete:   function() {  },
													onException:  function() { alert('unexpected error'); }
												}
							);
}


function expand(id){
   element = document.getElementById(id);
   element.style.display =(element.style.display=="block")?"none":"block";
}

function showActiveMenu(id){
 if(document.getElementById(id))
   document.getElementById(id).style.display="block"; 
}

function registration_chek(frm){
	if( document.getElementById('private_num').value=='' || document.getElementById('passport_num').value==''|| 
	   document.getElementById('phone').value==''|| document.getElementById('mobilephone').value=='' || document.getElementById('captcha').value==''){
			document.getElementById('mail_sub').disabled = 'disabled';
	}
	else{
	document.getElementById('mail_sub').disabled = '';
	}
}










function show_agreement() {
				try {
					obj = document.getElementById('div_agreement_content');
					if ( (obj.offsetHeight+obj.scrollTop) >= obj.scrollHeight-2)
						document.getElementById("usr_agreement").disabled = false;
				}
				catch(e) {
					a=1;
				}
			}
			
			
function showOverlay(){
  resizeOverlay();
  hideSelects();
  $('transparent').style.display = 'block';
}

function hideOverlay(){
  $('transparent').style.display = 'none';
  showSelects();
}
			
function resizeOverlay(){
  var windowSize = WindowScrollSize();
  $('transparent').style.width  = windowSize.scrollWidth + "px";
  $('transparent').style.height = windowSize.scrollHeight + "px";
}

function WindowScrollSize(pDoc){
  var width, height;
  if (!pDoc)
    pDoc = document;

if((pDoc.compatMode && pDoc.compatMode == "CSS1Compat")){
width = pDoc.documentElement.scrollWidth;
height = pDoc.documentElement.scrollHeight;
}
else{
if(pDoc.body.scrollHeight > pDoc.body.offsetHeight)
height = pDoc.body.scrollHeight;
else
height = pDoc.body.offsetHeight;

if(pDoc.body.scrollWidth > pDoc.body.offsetWidth ||
(pDoc.compatMode && pDoc.compatMode == "BackCompat") ||
(pDoc.documentElement && !pDoc.documentElement.clientWidth)
)
width = pDoc.body.scrollWidth;
else
width = pDoc.body.offsetWidth;
}
return {scrollWidth : width, scrollHeight : height};
}

selects = [];

function hideSelects(){
   var s = document.getElementsByTagName('select');
   var len = s.length; 
   var style;
   selects = [];
   for(var i = 0; i < len; i++){
       style = s[i].style.display;
       selects[i] = [s[i],style]; 
       s[i].style.display = 'none'; 
   }
}
 
function showSelects(){
   var len = selects.length; 
   for(var i=0;i<len;i++){
      selects[i][0].style.display = selects[i][1];
   }
}						
			
			
			
			
			
			
document.onLoad = setTimeout ( function () {show_agreement();}, 0);