var m;
var n;
var NewCoordinates;

function ShowNews() {
    var newElement = document.getElementById("new");
    var newElement1 = document.getElementById("new1");
    var newElement2 = document.getElementById("new2");

    var newWidth = newElement.offsetWidth;
    var new1Width = newElement1.offsetWidth;
    var BeginContent = newElement1.innerHTML;

    if ((new1Width - 7) < newWidth) {
      while ((newElement1.offsetWidth - 7) < newWidth)
	    {
	      newElement1.innerHTML = newElement1.innerHTML + BeginContent;
	    }
    }

    NewCoordinates = newElement1.offsetLeft + newElement1.offsetWidth;

    newElement2.style.left = NewCoordinates + 'px';
    newElement2.innerHTML = newElement1.innerHTML;

    m = -7;
    n = NewCoordinates;

    scrollNews();
}

function scrollNews() {
	document.getElementById('new1').style.left=m+'px';
	document.getElementById('new2').style.left=n+'px';
	m = m - 1;
	n = n - 1;

	if(m ==(-1 * (NewCoordinates + 7))) {
	   m = NewCoordinates + 7;
	}

	if(n ==(-1 * (NewCoordinates + 7))) {
	   n = NewCoordinates + 7;
	}
	
	setTimeout("scrollNews()",30);
} 

sNews = function() {
	try {
	  ShowNews();
	} catch(err)
	{}
}

if (window.addEventListener)
window.addEventListener("load", sNews, false)
else if (window.attachEvent)
window.attachEvent("onload", sNews)
else if (document.getElementById)
window.onload=sNews

function bookmarksite(title, url)
{
    if (window.sidebar) // firefox
        window.sidebar.addPanel(title, url, "");
    else if(window.opera && window.print){ // opera
     var a = document.createElement("a");
         a.rel = "sidebar";
         a.target = "_search";
         a.title = title;
         a.href = url;
         a.click();    
    }
    else if(document.all)// ie
        window.external.AddFavorite(url, title);
}

function OnDescription( url, width, height )
{
    var w = (width != null) ? width : 700;
    var h = (height != null) ? height : 580;
    if (screen) {
    leftPos = screen.width/2-w/2;
    topPos = screen.height/2-h/2;
    }
    photoWin = window.open(url, null, "width="+w+",height="+h+",top="+topPos+",left="+leftPos+",location=no,menubar=no,scrollbars=yes,toolbar=no,resizable=yes", "true");
    photoWin.focus();
} 

function ClearFields(v)
{
    var o;
    var i = 0;
    var s = v.split(",")
    while (i < s.length)
    {
        o=document.getElementById(s[i]);
        o.value='';
        /*
        if (o != null){
            o.value='';
        }else{
            document.getElementsByName(s[i]).value='';
        }
        */
        i+=1;
    }    
    //return false;
}

function CheckVal(e){
    IsValidate(e,'0123456789qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM@.-',false);
}

function CheckVal2(e){
    IsValidate(e,'0123456789qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM@.-',true);
}

function CheckNum(e){
    IsValidate(e,'0123456789',false);
}

function CheckNum2(e){
    IsValidate(e,'0123456789.,-+',false);
}

function CheckNum3(e) {
    IsValidate(e, '0123456789+', true);
}

function IsValidate(e,pattern,bspacebar){
	var keynum;
	if(window.event){
		keynum = e.keyCode;
	}else{
		if(e.which){
			keynum = e.which;
		}
	}
	var key=String.fromCharCode(keynum);
	if (keynum == 13){
		e.returnValue=keynum;
		return true;
	}else if (keynum == 32){
	    if (bspacebar == false){
		    if(e.stopPropagation){
			    e.stopPropagation();
		    }
		    e.cancelBubble=true;
		    if(e.preventDefault){
			    e.preventDefault();
		    }
		    e.returnValue=false;
		    return false;
		}else{
            e.returnValue=keynum;
			return true;
		}
    }else if((e.keyCode > 7 && e.keyCode < 10) || (e.keyCode > 27 && e.keyCode < 30) || (e.keyCode == 46) || e.keyCode > 47 && e.keyCode < 58) {
		window.status = '';
		return true;
	}else{
		if(pattern.indexOf(key)== -1){
			if(e.stopPropagation){
				e.stopPropagation();
			}
			e.cancelBubble=true;
			if(e.preventDefault){
				e.preventDefault();
			}
			e.returnValue=false;
			return false;
		}else{
			e.returnValue=keynum;
			return true;
		}
	}
}

function onprodinfo(n){
    var o = document.getElementById('det1');
    var o1 = document.getElementById('prodinfo1');
    var o2 = document.getElementById('prodinfo2');
    var o3 = document.getElementById('prodinfo3');
    var a1 = document.getElementById('liseldet1');
    var a2 = document.getElementById('liseldet2');
    var a3 = document.getElementById('liseldet3');
    switch(n)
    {
    case 1:
      o.innerHTML=o1.innerHTML;
      if (a1 != null){a1.className='act';}
      if (a2 != null){a2.className='';}
      if (a3 != null){a3.className='';}
      break;
    case 2:
      o.innerHTML=o2.innerHTML;
      if (a1 != null){a1.className='';}
      if (a2 != null){a2.className='act';}
      if (a3 != null){a3.className='';}
      break;
    case 3:
      o.innerHTML=o3.innerHTML;
      if (a1 != null){a1.className='';}
      if (a2 != null){a2.className='';}
      if (a3 != null){a3.className='act';}
      break;
    default:
      o.innerHTML=o1.innerHTML;
      if (a1 != null){a1.className='act';}
      if (a2 != null){a2.className='';}
      if (a3 != null){a3.className='';}
    }
}

function GetSelectValues(sName, sTotal)
{
    var s = "";  
    var o = document.getElementById(sTotal);
    if (o != null){
        var iTotal=o.value;
        if (iTotal==0)
        {
            return s;
        }else{
            for (var i = 1; i <= iTotal; i++) {
                s += document.getElementById(sName+i).value + ",";
            }
        }
    }
    return s
}

function lpass(v, v2)
{
    var s2 = document.getElementById(v).value;
    document.getElementById(v2).value = lgg(trim(s2));
    document.getElementById(v).value='';
    return false;
}

function lsecure(v, v2)
{
    var s2 = document.getElementById(v).value;
    
        
    if (s2.length < 7)
    {
        document.getElementById(v2).value = 0;
    }
    else
    {
        if (IsNumericChar(s2))
        {
            document.getElementById(v2).value = 1;
        }
        else
        {
            document.getElementById(v2).value = 0;
        }
    }   
    return false;
}


function IsNumericChar(sText)
{
    var ValidChars = "0123456789";
    var IsNumber=false;
    var Char;

    for (i = 0; i < sText.length && IsNumber == false; i++) 
    { 
        Char = sText.charAt(i); 
        if (ValidChars.indexOf(Char) > -1) 
        {
            IsNumber = true;
        }
    }
      
    return IsNumber;
}

var __nonMSDOMBrowser = (window.navigator.appName.toLowerCase().indexOf('explorer') == -1);
function WebForm_FireDefaultButton(event, target) {
        if (event.keyCode == 13 && !(event.srcElement && (event.srcElement.tagName.toLowerCase() == "textarea"))) {
        var defaultButton;
        if (__nonMSDOMBrowser) {
            defaultButton = document.getElementById(target);
        }
        else {
            defaultButton = document.all[target];
        }
        if (defaultButton && typeof(defaultButton.click) != "undefined") {
            defaultButton.click();
            event.cancelBubble = true;
            if (event.stopPropagation) event.stopPropagation();
            return false;
        }
    }
    return true;
}
function CheckNum(e){
    IsValidate(e,'0123456789',false);
}
function IsValidate(e,pattern,bspacebar){
	var keynum;
	if(window.event){
		keynum = e.keyCode;
	}else{
		if(e.which){
			keynum = e.which;
		}
	}
	var key=String.fromCharCode(keynum);
	if (keynum == 13){
		e.returnValue=keynum;
		return true;
	}else if (keynum == 32){
	    if (bspacebar == false){
		    if(e.stopPropagation){
			    e.stopPropagation();
		    }
		    e.cancelBubble=true;
		    if(e.preventDefault){
			    e.preventDefault();
		    }
		    e.returnValue=false;
		    return false;
		}else{
            e.returnValue=keynum;
			return true;
		}
    }else if((e.keyCode > 7 && e.keyCode < 10) || (e.keyCode > 27 && e.keyCode < 30) || (e.keyCode == 46) || e.keyCode > 47 && e.keyCode < 58) {
		window.status = '';
		return true;
	}else{
		if(pattern.indexOf(key)== -1){
			if(e.stopPropagation){
				e.stopPropagation();
			}
			e.cancelBubble=true;
			if(e.preventDefault){
				e.preventDefault();
			}
			e.returnValue=false;
			return false;
		}else{
			e.returnValue=keynum;
			return true;
		}
	}
}
function trim(str)
{
    while (str.substring(0,1) == ' '){
        str = str.substring(1, str.length);
    }
    while (str.substring(str.length-1, str.length) == ' '){
        str = str.substring(0, str.length-1);
    }
    return str;
}

function lgg(msg){function d(n,s){var t4=(n<<s)|(n>>>(32-s));return t4;};function g(val){var str="";var i;var vh;var vl;for(i=0;i<=6;i+=2){vh=(val>>>(i*4+4))&0x0f;vl=(val>>>(i*4))&0x0f;str+=vh.toString(16)+vl.toString(16);}return str;};function e(val){var str="";var i;var v;for(i=7;i>=0;i--){v=(val>>>(i*4))&0x0f;str+=v.toString(16);}return str;};function f(string){string=string.replace(/\r\n/g,"\n");var utftext="";for(var n=0;n<string.length;n++){var c=string.charCodeAt(n);if(c<128){utftext+=String.fromCharCode(c);}else if((c>127)&&(c<2048)){utftext+=String.fromCharCode((c>>6)|192);utftext+=String.fromCharCode((c&63)|128);}else{utftext+=String.fromCharCode((c>>12)|224);utftext+=String.fromCharCode(((c>>6)&63)|128);utftext+=String.fromCharCode((c&63)|128);}}return utftext;};var blockstart;var i,j;var W=new Array(80);var H0=0x67452301;var H1=0xEFCDAB89;var H2=0x98BADCFE;var H3=0x10325476;var H4=0xC3D2E1F0;var A,B,C,D,E;var temp;msg=f(msg);var msg_len=msg.length;var word_array=new Array();for(i=0;i<msg_len-3;i+=4){j=msg.charCodeAt(i)<<24|msg.charCodeAt(i+1)<<16|msg.charCodeAt(i+2)<<8|msg.charCodeAt(i+3);word_array.push(j);}switch(msg_len%4){case 0:i=0x080000000;break;case 1:i=msg.charCodeAt(msg_len-1)<<24|0x0800000;break;case 2:i=msg.charCodeAt(msg_len-2)<<24|msg.charCodeAt(msg_len-1)<<16|0x08000;break;case 3:i=msg.charCodeAt(msg_len-3)<<24|msg.charCodeAt(msg_len-2)<<16|msg.charCodeAt(msg_len-1)<<8|0x80;break;}word_array.push(i);while((word_array.length%16)!=14)word_array.push(0);word_array.push(msg_len>>>29);word_array.push((msg_len<<3)&0x0ffffffff);for(blockstart=0;blockstart<word_array.length;blockstart+=16){for(i=0;i<16;i++)W[i]=word_array[blockstart+i];for(i=16;i<=79;i++)W[i]=d(W[i-3]^W[i-8]^W[i-14]^W[i-16],1);A=H0;B=H1;C=H2;D=H3;E=H4;for(i=0;i<=19;i++){temp=(d(A,5)+((B&C)|(~B&D))+E+W[i]+0x5A827999)&0x0ffffffff;E=D;D=C;C=d(B,30);B=A;A=temp;}for(i=20;i<=39;i++){temp=(d(A,5)+(B^C^D)+E+W[i]+0x6ED9EBA1)&0x0ffffffff;E=D;D=C;C=d(B,30);B=A;A=temp;}for(i=40;i<=59;i++){temp=(d(A,5)+((B&C)|(B&D)|(C&D))+E+W[i]+0x8F1BBCDC)&0x0ffffffff;E=D;D=C;C=d(B,30);B=A;A=temp;}for(i=60;i<=79;i++){temp=(d(A,5)+(B^C^D)+E+W[i]+0xCA62C1D6)&0x0ffffffff;E=D;D=C;C=d(B,30);B=A;A=temp;}H0=(H0+A)&0x0ffffffff;H1=(H1+B)&0x0ffffffff;H2=(H2+C)&0x0ffffffff;H3=(H3+D)&0x0ffffffff;H4=(H4+E)&0x0ffffffff;}var temp=e(H0)+e(H1)+e(H2)+e(H3)+e(H4);return temp.toLowerCase();}

function createCookie(name,value){
    var expires = "";
    var days = 1;
    if (days){
        var date = new Date();
        date.setTime(date.getTime()+(days*24*60*60*1000));
        expires = "; expires="+date.toGMTString();
    }
    document.cookie = name+"="+value+expires+"; path=/";
}

function page_reload(){
    window.location.href=window.location.href;
}

function add2basket(v1, v2, p){
    var o1 = document.getElementsByName(v1)[0].value;
    var o2 =document.getElementsByName(v2)[0].value;    
    if ((o1 != null) || (o2 != null)){
        createCookie('site_carts',o2);
        createCookie('input_carts',o1);
        if (p != null){
            window.location.href=p;
        }else{
            page_reload();
        }
    }
    return false;
}

function add3basket(v1, v2, p){
        createCookie('site_carts',v1);
        createCookie('input_carts',v2);
        if (p != null){
            window.location.href=p;
        }else{
            page_reload();
        }

    return false;
}


function addhidd(v1,t){
    document.getElementsByName(v1)[0].value=t.value;
    document.forms[0].submit();
}
function submitt(t){

    document.forms[0].submit();
}

function download_file(id1, id2, path)
{
    var r = Math.round(1000000*Math.random());
    createCookie('fds', 'fd=' + id1 + '&t=' + id2 + '&id=' + r);
    location.href = path + 'download.aspx?id=' + r;
	return false;
}
function goTo() {
    var sE = null, url;
    if(document.getElementById) {
        sE = document.getElementById('currency');
    } else if(document.all) {
        sE = document.all['currency'];
    }
    if(sE && (url = sE.options[sE.selectedIndex].value)) {
        location.href = url;
    }
}

function csfonload(){if(top!=self){top.location=self.location;}}
if (window.addEventListener){window.addEventListener("load", csfonload, false)}
else if (window.attachEvent){window.attachEvent("onload", csfonload)}
else if (document.getElementById) { window.onload = csfonload; }

function prdtattrsel(o) {
    if (o != null) {
        location.href = o.value;
        return true;
    }
    return false;
}

function setReplyTo(c0, c1) {

    var rc = c1;
    var replyto = document.getElementById(c0);

    replyto.value = rc;
}

function qtychange(plusminus, id, SKU) {
    var val = 0;
    var inpt = document.getElementById(id);
    if (!inpt) {
        alert('element doesnt exist');
        return "";
    }

    val = parseInt(document.getElementById(id).value);

    if (plusminus) {
        document.getElementById(id).value = val + 1;
    } else {
        if (val > 1) {
            document.getElementById(id).value = val - 1;
        }
    }

    updatebtn(document.getElementById(id).value, SKU);
}

function updatebtn(val, SKU) {
    jQuery(".btnaddtobasket").attr("id", "addtobasket_" + SKU + "_" + val);
}

jQuery(document).ready(function () {

    if (typeof document.body.style.maxHeight === "undefined") {
        var options = {
            zoomWidth: 502,
            zoomHeight: 502,
            yOffset: -51,
            showEffect: 'show',
            hideEffect: 'fadeout',
            fadeoutSpeed: 'slow',
            title: false,
            lens: false
        }
    } else {
        var options = {
            zoomWidth: 502,
            zoomHeight: 502,
            yOffset: -51,
            showEffect: 'show',
            hideEffect: 'fadeout',
            fadeoutSpeed: 'slow',
            title: false
        }
    }

    jQuery('a.zoom').jqzoom(options);
    jQuery('a.zoom').css("display", "none");
});
