/*  TotalShop Javascript toolkit
 *  (c) 2006 TotalWeb <kal@totalweb.gr>
 *
 *  For commercial use, visit web site: http://www.totalweb.gr/
 *
/*--------------------------------------------------------------------------*/

var errorColor = '#ffaaaa';
var okColor = '#eeeeee';

//PAGE STUFF INIT
//============================
var themenu;

function initPage(){
	markRowsInit();	
	//FOR DYNAMIC BANNER
	try{showBanners();	}catch(e){}
}

//GENERAL STUFF
//=========================================

function getcookie(cookiename) {
	 var cookiestring=""+document.cookie;
	 var index1=cookiestring.indexOf(cookiename);
	 if (index1==-1 || cookiename=="") return ""; 
	 var index2=cookiestring.indexOf(';',index1);
	 if (index2==-1) index2=cookiestring.length; 
	 return unescape(cookiestring.substring(index1+cookiename.length+1,index2));
}

function setcookie(name,value){
	cookiestring=name+"="+escape(value)+";PATH=/"; //EXPIRES="+ getexpirydate(365)+";
	document.cookie=cookiestring;
}

function getexpirydate(nodays){
	var UTCstring;
	Today = new Date();
	nomilli=Date.parse(Today);
	Today.setTime(nomilli+nodays*24*60*60*1000);
	UTCstring = Today.toUTCString();
	return UTCstring;
}

function setBoxVisibility(obj,vis){
		
	if (!obj.id){		
		obj = document.getElementById('btn'+obj);
	}
	
	var div2change = 'box_'+obj.id.substr(3);
		
	if (vis==''){
		toggleVis(div2change);
	}else{
		setVis(div2change,vis);
	}
	
	//Set cookie
	setcookie(div2change+'_vis',document.getElementById(div2change).style.display);
	
	//Set icon
	if (document.getElementById(div2change).style.display =='none'){
		obj.src = 'images/slices/icon_add.gif';
	}else{
		obj.src = 'images/slices/icon_sub.gif';
	}
}

function checkVis(elem){
	if (getcookie('box_'+elem+'_vis')!='') setBoxVisibility(elem,getcookie('box_'+elem+'_vis')); 
}

function findObj(n, d) {
  var p,i,x;
  if(!d) d=document;
  if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document;
		n=n.substring(0,p);
  }
  if(!(x=d[n])&&d.all) x=d.all[n];
  for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n);
  return x;
}

function toggleVis(elem){
	obj=document.getElementById(elem);
	if(obj.style.display =='none'){
		obj.style.display ='block';
	}else{
		obj.style.display ='none';
	}
}

function setVis(elem, vis){
	if (document.getElementById(elem)){
		document.getElementById(elem).style.display = vis;		
	}
}

function popupWin(addr,sizeX,sizeY){
	myWin=window.open(addr,'','toolbar=0,location=0,directories=0,menuBar=0,scrollbars=1,resizable=1,width='+sizeX+',height='+sizeY);
}

function changePage(pg){	
	document.forms['frmFilter'].pg.value=pg;
	document.forms['frmFilter'].submit();
}

function changeOrder(ord){
	var orderVal;
	orderVal = document.forms['frmFilter'].hdnOrderNum.value;
	if(orderVal.indexOf('d')!=-1){
		document.forms['frmFilter'].hdnOrderNum.value=ord;
	}else{
		document.forms['frmFilter'].hdnOrderNum.value=ord+'d';
	}	
	document.forms['frmFilter'].submit();
}

var marked_row = new Array;

function markRowsInit() {
    var rows = document.getElementsByTagName('tr');
    for ( var i = 0; i < rows.length; i++ ) {
        // ... with the class 'r0' or 'r1' ...
        if ( 'r0' != rows[i].className.substr(0,2) && 'r1' != rows[i].className.substr(0,2) ) {
            continue;
        }
        if ( navigator.appName == 'Microsoft Internet Explorer' ) {
            rows[i].onmouseover = function() {
                this.className += '_hover';
            }
            rows[i].onmouseout = function() {
                this.className = this.className.replace( '_hover', '' );
            }
        }
    }
}


function fadeup(elementId,red,green,blue) {
	
	if (red ==255 && green == 255 && blue==255) {
		//document.getElementById(elementId).style.backgroundColor = "transparent";
		return true;
	}

	document.getElementById(elementId).style.backgroundColor = "rgb("+red+","+green+","+blue+")";

	red = red + Math.ceil((255 - red)/10);
	green = green + Math.ceil((255-green)/10);
	blue = blue + Math.ceil((255-blue)/10);

	setTimeout("fadeup('"+elementId+"',"+red+","+green+","+blue+")", 10);

}

function setFlashStr(mov, w, h, vars, atDiv){
	document.getElementById(atDiv).innerHTML = '<obj'+'ect classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="'+w+'" height="'+h+'">  <param name="movie" value="'+mov+'"><param name="quality" value="high"><param name="FlashVars" value="'+vars+'"><emb'+'ed src="'+mov+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+w+'" height="'+h+'" FlashVars="'+vars+'"></emb'+'ed></obje'+'ct>';
}

//CART STUFF
function fixPrice(ctrl){

	if ( isNaN(ctrl.value) || ctrl.value.indexOf('.')>0 || ctrl.value=='' || ctrl.value.indexOf('-')>0 ){
		ctrl.value='0';	
	}

	var itemsQuantity=0;
	var itemsPrice=0;
	
	for(i=0;i<document.frmStep1.length;i++){
	
		if(document.frmStep1[i].name.indexOf('xtQuant_')>0){
			pId = document.frmStep1[i].name.substr(document.frmStep1[i].name.indexOf('_')+1);					
			itemsQuantity += eval(document.frmStep1[i].value);
			itemsPrice += eval(document.frmStep1['hdnPrice_'+pId].value) * eval(document.frmStep1[i].value);
		}
	}
	
	document.getElementById('txtItems').innerHTML = itemsQuantity.toFixed(0);
	document.getElementById('txtSum').innerHTML = itemsPrice.toFixed(2)+'&euro;';
}

function fillInShipData(doFill){
	var frm = document.frmStep2;
	if(doFill){		
		frm.txtShipFirstname.value = frm.txtBillFirstname.value;
		frm.txtShipLastname.value = frm.txtBillLastname.value;
		frm.txtShipCompany.value = frm.txtBillCompany.value;
		frm.txtShipAddress.value = frm.txtBillAddress.value;
		frm.txtShipcity.value = frm.txtBillcity.value;
		frm.txtShippostalCode.value = frm.txtBillpostalCode.value;
		frm.lstShipcountry.selectedIndex = frm.lstBillcountry.selectedIndex;
		frm.txtShipEmail.value = frm.txtBillEmail.value;
		frm.txtShipPhone.value = frm.txtBillPhone.value;
		frm.txtShipFax.value = frm.txtBillFax.value;		
	}else{
		frm.txtShipFirstname.value = '';
		frm.txtShipLastname.value = '';
		frm.txtShipCompany.value = '';
		frm.txtShipAddress.value = '';
		frm.txtShipcity.value = '';
		frm.txtShippostalCode.value = '';
		frm.lstShipcountry.selectedIndex = 0;
		frm.txtShipEmail.value = '';
		frm.txtShipPhone.value = '';
		frm.txtShipFax.value = '';	
	}	
}

//AJAX STUFF
//====================================

var xmlHttp;
var sumOfItemsLabel;

function SendCmd(url, callbackFunction){ 
	var url='includes/ajax/'+url+'&sid=' + Math.random() ;
	xmlHttp=GetXmlHttpObject(eval(callbackFunction));
	xmlHttp.open("GET", url , true);
	xmlHttp.send(null);
	//alert(url);
} 
//CALLBACKS


function GetXmlHttpObject(handler) { 
	var objXmlHttp=null;
	
	//if (navigator.userAgent.indexOf("Opera")>=0){
	//	alert("Opera browser is not supported") 
	//	return ;
	//}
	if (navigator.userAgent.indexOf("MSIE")>=0){ 
		var strName="Msxml2.XMLHTTP";
		if (navigator.appVersion.indexOf("MSIE 5.5")>=0){
			strName="Microsoft.XMLHTTP";
		} 
		try{ 
			objXmlHttp=new ActiveXObject(strName);
			objXmlHttp.onreadystatechange=handler ;
			return objXmlHttp;
		}catch(e){ 
			alert("Error. Scripting for ActiveX is disabled." ) ;
			return ;
		} 
	} 
	if (navigator.userAgent.indexOf("Mozilla")>=0 || navigator.userAgent.indexOf("Opera")>=0){
		objXmlHttp=new XMLHttpRequest();
		objXmlHttp.onload=handler;
		objXmlHttp.onerror=handler ;
		return objXmlHttp
	}
} 