var realPrice=0;
var priceSelected = 0;
 
var isIE = (navigator.appName.indexOf("Microsoft") != -1) ? true : false;

function gogo(){};

// =================   Digital clock made by: Nicolas - http://www.javascript-page.com and re-made by Natal =============
var clockID = 0;

function UpdateClock() {
   if(clockID) {
      clearTimeout(clockID);
      clockID  = 0;
   }

   var tDate = new Date();
	var timer = document.getElementById("digitClock");
	
	tHour = tDate.getHours()
	tMin = tDate.getMinutes()
	tSec = tDate.getSeconds()
	
   timer.textContent = timer.innerText = "" 
   					   + (tHour < 10 ? '0' + tHour : tHour) + ":"
                       + (tMin < 10 ? '0' + tMin : tMin) + ":" 
                       + (tSec < 10 ? '0' + tSec : tSec);
   
   clockID = setTimeout("UpdateClock()", 1000);
}
function StartClock() {
   clockID = setTimeout("UpdateClock()", 500);
}

function KillClock() {
   if(clockID) {
      clearTimeout(clockID);
      clockID  = 0;
   }
}
// =================== DIGITAL CLOCK ================================


// show || hide issue's info parts (about, adverts, team) - class.Ictmedia.php
function blockSelected(type, container, index, all, ofIssue){
	type2show = document.getElementById(type + index);
	div2block = document.getElementById(container + index);
	
	for(i=1; i <= all; i++){
		document.getElementById(container+i).style.display = "none";
		document.getElementById(type + i).className = "issueTypeOff";
	}
	
	type2show.className = "issueTypeOn";
	div2block.style.display = "block";
}

// calculates price for chosen period in subscription
function recalculate(id_copiesBox, id_priceBox){
	var copies_obj = document.getElementById(id_copiesBox)
	var price_obj = document.getElementById(id_priceBox)
	
	var re = /\d{1,2}/
	
	if(!re.test(copies_obj.value)){
		alert("Моля, въведете число в полето за количество.");
		copies_obj.focus(); return false;
	} else {
		price_obj.value = (copies_obj.value * priceSelected) + ".00";
	}
}

//updates price in priceBox - class.Subscribe.php
function setPrice(price, id_copiesBox, id_priceBox){
	priceSelected = price;
	recalculate(id_copiesBox, id_priceBox);
}

function setPriceSimple(price, id_priceBox){
	document.getElementById(id_priceBox).value = price;
}

// shows || hides subscription process' parts - class.Subscribe.php
function showNextStep(priceDiv, contactsDiv, paymentDiv, nextStep, formID, step, online, inSes, isReg){
	//priceDiv - holds info about issue price, period &copies
	//contacstDiv - ... user contacts && company contacts
	//paymentDiv  - ... way of payment (post, ePay, trancsard, banking)
	//nextStep - defines what to show and hide
	//step  -  what part of the form to validate 
	//online - validates only username & mail from contactsDiv
	//inSes - true on "issues in session", false on "empty session"
	
	var prObj = document.getElementById(priceDiv);
	var cnObj = document.getElementById(contactsDiv);
	var pmObj = document.getElementById(paymentDiv);
	var submitB = document.getElementById('total');
	var nextB1 =   document.getElementById('next1');
	var nextB2 =   document.getElementById('next2');
	var form = document.getElementById(formID);
	
	var subsInSes = document.getElementById('inSess');

	if(step == 	"contacts"){
		if(!contactsVal(form,online, isReg)){ return; sbOK = false;}
	}
	else if(step == "payments"){
		if(!paymentsVal(form)){ return; sbOK = false;}
	}
	
	prObj.style.display = "none";
	cnObj.style.display = "none";
	pmObj.style.display = "none";
	nextB1.style.display = "none";
	nextB2.style.display = "none";
	submitB.style.display = "none";
	
	if(inSes == 1) subsInSes.style.display = "none";
	
	switch(nextStep){
		case 'ToPayments':
			pmObj.style.display = "block";
			nextB2.style.display = "block";
		break;
		case 'SkipPayments':
			if(inSes == 1) subsInSes.style.display = "block";
			prObj.style.display = "block";
			cnObj.style.display = "block";
			pmObj.style.display = "block";
			submitB.style.display = "block";
		break;
	}
	
	sbOK = true
}

// shows FakturaBox if checked, hides if unchecked - class.Subscribe.php
function showFbox(id, chbox, sessMail){
	var obj = document.getElementById(id);
	if(chbox.checked == true){
		obj.style.display = "block";
		chbox.value = 1;
		
	}else{
		obj.style.display = "none";
	}
}

//make style for quiestions in FAQ part - class.Ictmedia.php
function faq_numb(id, mode){
	var obj = document.getElementById(id)
	
	if(mode == "on"){
		obj.style.color = "#AA0000"
		obj.style.fontWeight = "bold"
	}
	else {
		obj.style.color = "#424242";
		obj.style.fontWeight = "";
	}
}

//shows || hides 3extra fields in bgict market menu - free reg, change mail and unsubscribe - class.Itcatalogs.php
function bgict_over(obj,id1, flag){
	var showobj = document.getElementById(id1);
	
	if(flag){
		obj.className = "menu_topics_over";
		showobj.style.display = "block";
	
	}else{
		obj.className = "menu_topics";
	}
}

//swich tabs in bg it catalogue - BG companies && products&services - class.Itcatalogs.php
function make_selection(show, hide1, hide2){
	var obj2show = document.getElementById(show);
	var obj2hide = document.getElementById(hide1);
	var obj2hide2 = document.getElementById(hide2);
	
	obj2show.className = "itcatTabOn";
	obj2hide.className = "issueTypeOff";
	obj2hide2.className = "issueTypeOff";

	location = "?mode=itcat&type=" + show;
}

//shows || hides products divs in Products&services tab - class.Itcatalogs.php
function show_products(id, index, num){
	var currObj = document.getElementById(id + index);
	
	if(currObj.style.display == "block")
		currObj.style.display = "none";
	else currObj.style.display = "block";
	
	
	for(i=0; i < num; i++){
		if(i == index) continue;
		document.getElementById(id + i).style.display = "none";
	}
}