/*

*/function lightON() {
	var eSrc = window.event.srcElement;
	eSrc.style.background='#647D92';
	eSrc.style.color='#fff'; 
}
function lightOFF() {
	var eSrc = window.event.srcElement;
	eSrc.style.background='#e5e5e5';
	eSrc.style.color='#000';
}

function areAnyDirectEdits(){
		var tags = document.getElementsByTagName("div");
		var counter = 0;
		for (var j=0; j<tags.length;j++) {
			if(tags[j].className == "ocms_de_bt") {
				counter++;
			}	
		}
		if (counter > 0) return true;
		else return false;
}


function loadPlus(id) {

if (areAnyDirectEdits()){	
	var container = document.getElementById(id);
	if (container != null){
		var tags = container.getElementsByTagName("td");
		var counter = 0;
		for (var j=0; j<tags.length;j++) {
			if(tags[j].className == "ocms_de") {
				counter++;
				if (counter < 3){
					tags[j].style.visibility = "hidden";
				}
				else break;
			}	
		}
	}
	showButtonsOcms();
}

}

function showImg(URL,imgPath) {
		var content = '<html><head>' + '\<\style>'+'BODY { overflow: hidden }'+'<\/style>'
		    +'<script>' + 'function selfResizer(obj) {' +
		    'var w = obj.width;iWidth='+self.innerWidth+';' +
		    'var h = obj.height;iHeight='+document.body.clientHeight  +';' +
		    'var left = (self.opera?iWidth:screen.availWidth)/2 - w/2;' +
		    'var top = (self.opera?iHeight:screen.availHeight)/2 - h/2;' +
		    '  window.resizeTo(w+10, h+36);' +
		    '  ' +
		    '}' +    '<\/script>' +'</head><body>' +
		'<img onLoad="selfResizer(this)" style="position: absolute; left: 0px; top: 0px" src="'+imgPath+'">' +
		'</body></html>';
		var wnd = window.open(URL, 'newWnd', 'status=0,width=50,height=50,left=100,top=100,screenX=100,screenY=100,resizable,scrollbars=0');
		    wnd.document.write(content);
		    wnd.document.title = "Image Preview";
		    wnd.document.close();
		}

/* Functions for check availability on the product page */

function checkAvailabilityPopup(artNum) {
	var urlParameters = '?locale=en&amount=' + document.getElementById('amountForAvailabilityCheck').value + '&artNum=' + artNum;
	var url = '/system/modules/com.gridnine.opencms.modules.ms/elements/check_availability_popup.jsp';
	popupWin = window.open(url + urlParameters, 'check_avalability', 'location=0,width=300,height=160,top=0,resizable,toolbar=0,scrollbars=0,menubar=0'); 
	popupWin.focus(); 
	return false;
}

function getMyPricePopup(artNum) {
	var urlParameters = '?thisLocale=en&artNum=' + artNum;
	var url = '/system/modules/com.gridnine.opencms.modules.ms/elements/myprice_popup.jsp';
	popupWin = window.open(url + urlParameters, 'check_avalability', 'location=1,width=300,height=160,top=0,resizable,toolbar=0,scrollbars=0,menubar=0'); 
	popupWin.focus(); 
	return false;
}

function validateDate(dateString) {
	var regexDate = new RegExp("(19|20)[0-9]{2}[-](0[1-9]|1[012])[-](0[1-9]|[12][0-9]|3[01])");
	if (dateString.match(regexDate)) {
		return true;
	} else {
		var resultBox = document.getElementById('dateValidationResult');
		if(resultBox) {
			resultBox.innerHTML = '<br><span style="color:red">Invalid date format</span>';
			return false;
		}
	}
}

function goTo(url)
{
 location.href = "/Czech/en/campaignpages/" + url + "/index.html";
}

// for print preview

function printPreviewFinal() {
	document.getElementById('popupWait').style.display = 'none';
	document.getElementById('totalWrapper').style.visibility = 'visible';
}

function extractPrintContent() {
	var box = document.getElementById("productPage");
	var content = box.innerHTML;
	document.getElementById("totalWrapper").innerHTML = content;
	try {
		window.setTimeout("printPreviewFinal()", 1);
		window.setTimeout("window.print();", 500);
	} catch (e) {}
}

function loadMainBanners() 
{
 var requestBody = false;
 requestBody = "";

	    
 var onLoadMainBannersSuccess = function(oXmlDoc) 
 {
  try 
  {
   document.getElementById("mainBanners").innerHTML = oXmlDoc;  
   var numBanners = 1;
   if (document.getElementById("numBanners") != null)
   {
    numBanners = document.getElementById("numBanners").value;
   }
   var rnd = Math.floor(Math.random() * numBanners);
   document.getElementById("banner_" + rnd).style.display="block";
  } 
  catch (e) 
  {
   throw e;
  } 
 };
	
 doHtmlRequest('/system/modules/com.gridnine.opencms.modules.ms/pages/mainbanners.html?locale=en&current_market=Czech',
		onLoadMainBannersSuccess,
		null,
		//onShoppingCartUpdateStart,
		function(e) {alert(e);},
		requestBody
 );
}

function loadNewsEvents() 
{
 var requestBody = false;
 requestBody = "";
	    
 var onLoadNewsEventsSuccess = function(oXmlDoc) 
 {
  try 
  {
   document.getElementById("newsEvents").innerHTML = oXmlDoc;   
  } 
  catch (e) 
  {
   throw e;
  } 
 };
	
 doHtmlRequest('/system/modules/com.gridnine.opencms.modules.ms/pages/news_events.html?locale=en&current_market=Czech',
		onLoadNewsEventsSuccess,
		null,
		//onShoppingCartUpdateStart,
		function(e) {alert(e);},
		requestBody
 );
}

function getFlashMovieObject(movieName)
{
  if (document.embeds && document.embeds[movieName])
  {
   return document.embeds[movieName];  
  }
  
  if (window.document[movieName]) 
  {
      return window.document[movieName];
  }
  return document.getElementById(movieName);
}

function initCountDown() 
{
 var movie = getFlashMovieObject("banner");
 if (!movie) return;
 
 movie.SetVariable("balanceQtyMin",-200188);
 movie.SetVariable("linkURL","/Czech/en/new-modul-system/index.html");
 movie.Play();
}





