/* standart functions */
function getClientWidth(){
  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth:document.body.clientWidth;
}

function getClientHeight(){
  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:document.body.clientHeight;
}
function getDocumentHeight(){
	return (document.body.scrollHeight > document.body.offsetHeight)?document.body.scrollHeight:document.body.offsetHeight;
}
function getDocumentWidth(){
	return (document.body.scrollWidth > document.body.offsetWidth)?document.body.scrollWidth:document.body.offsetWidth;
}
function getElementPosition(elemId){
    var elem = document.getElementById(elemId);
	
    var w = elem.offsetWidth;
    var h = elem.offsetHeight;
	
    var l = 0;
    var t = 0;
	
    while (elem)
    {
        l += elem.offsetLeft;
        t += elem.offsetTop;
        elem = elem.offsetParent;
    }

    return {"left":l, "top":t, "width": w, "height":h};
}
function getElementPosition2(elem){
    var elem = elem;
	
    var w = elem.offsetWidth;
    var h = elem.offsetHeight;
	
    var l = 0;
    var t = 0;
	
    while (elem)
    {
        l += elem.offsetLeft;
        t += elem.offsetTop;
        elem = elem.offsetParent;
    }

    return {"left":l, "top":t, "width": w, "height":h};
}
document.getElementsByClassName = function(cl) {
	var retnode = [];
	var myclass = new RegExp('\\b'+cl+'\\b');
	var elem = this.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 getElementComputedStyle(elem, prop)
{
  if (typeof elem!="object") elem = document.getElementById(elem);
  
  // external stylesheet for Mozilla, Opera 7+ and Safari 1.3+
  if (document.defaultView && document.defaultView.getComputedStyle)
  {
    if (prop.match(/[A-Z]/)) prop = prop.replace(/([A-Z])/g, "-$j1").toLowerCase();
    return document.defaultView.getComputedStyle(elem, "").getPropertyValue(prop);
  }
  
  // external stylesheet for Explorer and Opera 9
  if (elem.currentStyle)
  {
    var i;
    while ((i=prop.indexOf("-"))!=-1) prop = prop.substr(0, i) + prop.substr(i+1,1).toUpperCase() + prop.substr(i+2);
    return elem.currentStyle[prop];
  }
  
  return "";
}
/* end of standart functions */

function numbersonly(e, decimal) {
var key;
var keychar;

if (window.event) {
   key = window.event.keyCode;
}
else if (e) {
   key = e.which;
}
else {
   return true;
}
keychar = String.fromCharCode(key);

if ((key==null) || (key==0) || (key==8) ||  (key==9) || (key==13) || (key==27) ) {
   return true;
}
else if ((("0123456789").indexOf(keychar) > -1)) {
   return true;
}
else if (decimal && (keychar == ".")) { 
  return true;
}
else
   return false;
}


// VALIDATION START
function show_alert_message(text){
	var hei = getElementPosition2(document.getElementsByClassName("footerBlock")[0]).top + 250;
	
	if(hei < getDocumentHeight()){
		hei = getDocumentHeight();
	}
	if(hei < getClientHeight()){
		hei = getClientHeight();
	}
	
	scrollY = getScrollH();
	show_hide_select("hidden");
	show_hide_video("hidden");
	document.getElementById("blackBg").style.display = 'block';
	document.getElementById("blackBg").style.width = document.body.clientWidth + "px";
	document.getElementById("blackBg").style.height = hei + "px";
	var popupBlock = document.getElementById("form_alert_message");
	popupBlock.style.top = scrollY + 100 + "px"; 
	popupBlock.style.display = "block";
	document.getElementById("alert_getstarted").innerHTML = text;
}

function hide_alert_message(){
	show_hide_select("visible");
	show_hide_video("visible");
	document.getElementById("blackBg").style.display = 'none';
	var popupBlock = document.getElementById("form_alert_message");
	popupBlock.style.display = "none";	
}

function show_hide_select(types)
{
	
	for(i=0;i<document.getElementsByTagName("select").length;i++){
		document.getElementsByTagName("select")[i].style.visibility = types;
	}
	
}
function show_hide_video(type){
	if(document.getElementById("contents")){
		document.getElementById("contents").style.visibility = type;
	}
}

function getScrollH()
{
	
	var scrollY = 0;
	if ( document.documentElement && document.documentElement.scrollTop ){
		scrollY = document.documentElement.scrollTop;
	}else if ( document.body && document.body.scrollTop ){
		scrollY = document.body.scrollTop;
	}else if ( window.pageYOffset ){
		scrollY = window.pageYOffset;
	}else if ( window.scrollY ){
		scrollY = window.scrollY;
	}
	return scrollY;
}
function validateEmail(email)
{
    if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(email))
        return true
    else
        return false;
}
function Show_Submenu(li){
	$j(li).next("ul").slideToggle("500");
}


function add_item_to_card(codes, q)
{
	
	
	document.getElementById("but_add_cart").disabled = true;
	qty = document.getElementById("qty").value;
	qtys = qty * q;
		
	var url = '../products/act.php?act=add_item_to_card&code='+codes+'&qty='+qtys;
	$j.get(url, function(data) {
		$j('#total_items').html(data);
		document.getElementById("but_add_cart").disabled = false;
	});
	
	
}

function add_item_to_card_impration(codes)
{
	var size = ""
	q = document.getElementById("purchasing_units1").innerHTML;

	if(document.getElementById("size")){
		size = document.getElementById("size").value;
	}
		
	document.getElementById("but_add_cart").disabled = true;

	qty = document.getElementById("qty").value;
	qtys = qty * parseInt(q);
	
	if(size != '')
		codes_out = codes+"_"+size;
	else 	
		codes_out = codes;

	var url = '../products/act.php?act=add_item_to_card&code='+codes_out+'&qty='+qtys;
	$j.get(url, function(data) {
		$j('#total_items').html(data); 
		document.getElementById("but_add_cart").disabled = false;
	});
	
}

function update_price()
{
	
			
	var url = '../products/act.php?act=update_price';
	$j.get(url, function(data) {
	$j('#total_sum').html(data);  
	});
	
}


function update_pack(vars)
{
	
	var_out = vars.split("|");
	in_pac = var_out[0];
	mas_pac = var_out[1];
	pac_name = var_out[2];
	pac_price = var_out[3];
	
	document.getElementById("inner_pack").innerHTML = in_pac;
	document.getElementById("master_pack").innerHTML = mas_pac;
	document.getElementById("purchasing_units").innerHTML = in_pac;
	document.getElementById("purchasing_units1").innerHTML = in_pac + "&nbsp;X&nbsp;";
	document.getElementById("size").value = pac_name;
	document.getElementById("price").innerHTML = pac_price;
	
}

function show_sub_menu_top(act)
{
	
	//$("#subTopMenu").slideToggle("500");
	document.getElementById("subTopMenu").style.display = act;
	if(act == "block"){
		document.getElementById("loginFormBlock").style.zIndex = 1099;
	}
	else{
		document.getElementById("loginFormBlock").style.zIndex = 1101;
	}
}



function initFadingImages(){	
	for(var i=0;i<$j(".bannerItem").size();i++){
		startAnimation($j(".bannerItem").eq(i), i);
	}
}
function startAnimation(obj, num){
	var cur = 0;
	var idInterval;
	
	function doBannerFading(){				
		clearInterval(idInterval);
		for(var i=0; i<$j(obj).find("a").size(); i++){
			if(i == cur){				
				$j(obj).find("a").eq(i).animate({
					opacity: 1
				  }, 1000, function() {
					if(cur < $j(obj).find("a").size() - 1){
						cur++;	
					}
					else{
						cur=0;
					}
					setTimeout(doBannerFading, 2000);
				  });
			}
			else{
				$j(obj).find("a").eq(i).animate({
					opacity: 0
				  }, 1000, function() {

				  });					
			}	
		}		
	}
	doBannerFading();
}
