var DOM = (typeof(document.getElementById) != 'undefined');

function GetObj(objId){
	if(!DOM) return false;	
	return document.getElementById(objId);
}

function Trim(str){
	if(str == undefined) return;
	
	str=str.replace(/ +$/, "");
	str=str.replace(/^ +/, "");	
	return str;
}

function ShowImg(path, width, height){
	margin_left = GetScreenMargin(self.screen.width, width);
	margin_top = GetScreenMargin(self.screen.height, height);

	window.open(path, 'fullimg', 'left=' + margin_left + ',top=' + margin_top + ',width='+width+',height='+height+',menubar=no,scrollbars=no,status=no');
}

function GetScreenMargin(screen, popup){
	if(popup > screen) return 0;
	margin = screen - popup;
	margin = margin/2;
	margin = Math.round(margin);
	return margin;
}

function ShowPopup(path, width, height, name, scroll, add_param){
	if(scroll == 'undefined') scroll = 'no';
	margin_left = GetScreenMargin(self.screen.width, width);
	margin_top = GetScreenMargin(self.screen.height, height);
	param = 'left=' + margin_left + ',top=' + margin_top + ',width=' + width + ',height=' + height + ',menubar=no,scrollbars=' + scroll + ',status=no';
	if(add_param != 'undefined') param += add_param;
	window.open(path, name, param);
}

function GetAbsoluteTop(obj){
   var result = 0;
   while(obj.tagName != 'BODY'){
     result += obj.offsetTop;
     obj = obj.offsetParent;
   }
   
   return result;
}

function GetAbsoluteLeft(obj){
   var result = 0;
   while(obj.tagName != 'BODY'){
     result += obj.offsetLeft;
     obj = obj.offsetParent;
   }
   
   return result;
}

function CheckOrderMode(obj){
	if(obj.value != -1){
		GetObj('o_mode').disabled = false;
	}
	else{
		GetObj('o_mode').disabled = true;
	}
}

function DisplHideAF(id_name){
	obj = GetObj(id_name);

	if(!obj) return;
	if(obj.style.display == 'none'){
		obj.style.display = '';
	}
	else{
		obj.style.display = 'none';
	}
	
}

function GetFlash(path, width, height, link, parametr){
	if(link){
		if(parametr != ''){parametr += '&';}
		parametr += 'link='+link;
	}	
	document.open();
	document.write('<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version="6,0,0,0" WIDTH="'+width+'" HEIGHT="'+height+'">');
	document.write('<PARAM NAME="wmode" VALUE="transparent">');	
	document.write('<PARAM NAME="movie" VALUE="' + path + '">');
	document.write('<PARAM NAME="quality" VALUE="high">');
	document.write('<PARAM NAME="FlashVars" VALUE="' + parametr + '">');
	document.write('<EMBED src="' + path + '" wmode="transparent" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" WIDTH="' + width + '" HEIGHT="' + height + '" FlashVars="' + parametr + '" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></EMBED>');
	document.write('</OBJECT>');
	document.close();
}

function RefreshAntispam(path, objId){
	if(!DOM) return false;
	antispam = GetObj(objId);
	path = path + '?rnd='+Math.random();
	antispam.src=path;
}

function toggleSub(id)
{
    $('#' + id).toggle('medium');
}

(function(){
    $(document).ready(function(){
        if ($('#contactClock').length != 0) {
//            yseDateContacts();
            setInterval("yseDateContacts()",1000);
        }        
    });
}());
   var correction = 0;
   var request_made = 0;

function yseDateContacts()
{
       var localTime = new Date();
       if (!correction) {
           correction = 1;
           request_made = localTime.getTime();

           try {
               req = new XMLHttpRequest();
           } catch (e) {
               req = new ActiveXObject("Microsoft.XMLHTTP");
           }
           req.onreadystatechange = function () {
               if (req.readyState != 4)
                   return;
               var f = req.responseText.split('&');
               var ts = f[0].split('=')[1];
               var tz = f[1].split('=')[1];
               var local_ts = localTime.getTime();
               var travel_time = (local_ts - request_made) / 2;
               var server_raped_ts = (parseInt(ts, 10) + parseInt(tz,
10))*1000;
               correction = (server_raped_ts - travel_time) - local_ts;
               jsClockTimeZone();
           }

           req.open("GET", '/ts.php', true);
           req.send("");
           return;
       }
       var TimezoneOffset = 0;
       var ms = localTime.getTime() + (localTime.getTimezoneOffset()
* 60000) + TimezoneOffset * 3600000 + correction;
       var time = new Date(ms);
       var hour = time.getHours();
       var minute = time.getMinutes();
       var second = time.getSeconds();
       var temp = "" + ((hour > 12) ? hour - 12 : hour);
       if (hour==0) temp = "12";
       if (temp.length==1) temp = " " + temp;
       temp += ((minute < 10) ? ":0" : ":") + minute;
       temp += ((second < 10) ? ":0" : ":") + second;
       temp += (hour >= 12) ? " PM" : " AM";
	$('#contactClock').attr('value', temp);
       setTimeout(yseDateContacts, 1000);
}
window.onload = yseDateContacts;
