function test_fax(fax_nr)
	{
	var lnk = '../fax/index.php?test_msg='+fax_nr;
	pop(lnk , 'faxtest' ,200,100,0  );
	}

function test_mail(e_mail)
	{
	var lnk = '../fax/index.php?test=e_mail&test_msg='+e_mail;
	pop(lnk , 'faxtest' ,200,100,0  );
	}

function check_login_box()
	{
	if( document.getElementById('USERID').value=='' ||  document.getElementById('LOGINID').value==''  )
		{
		alert ('Please enter your login details.');
		return false
		}
	}

//dropdawn scripts
function menu_show(id)
	{
	document.getElementById(id).className='show';
	}

function menu_show_stop(id)
	{
	document.getElementById(id).className='show';
	clearTimeout(timer);
	}

function menu_hide(id,timeout)
	{	
	timer = setTimeout("menu_hide2('"+id+"')",timeout);
	}

function menu_hide2(id)
	{
	document.getElementById(id).className='hide';
	}
//end dropdawn scripts



// JavaScript Document
// otworzokno i zaladuj obrazek
var desc;

function powi(ktory,wid, hei, dec)
{
if (!desc) {desc=' '};	
  pic_window = window.open("","gellery","width="+wid+",height="+hei+",titlebar=no,scrollbars=yes,resizable");
  pic_window.document.write("<html><head><meta http-equiv='Content-Type' content='text/html; charset=iso-8859-2'><TITLE>M2G Picture prewiev</TITLE></head><body bgcolor='#000000' text='#FFFFCC'><div align='center'><a href='javascript:self.close()' title='click to close'><img src='"+ktory+"' border='0'></a><br><br><font face=Verdana>"+desc+"</font></div></body></html>");

};
// otworz okno i zaladuj plik
var nu_window


function pop(windowUri ,windowName ,windowWidth,windowHeight,windowScroll  )
{
    var centerWidth = (window.screen.width - windowWidth) / 2;
    var centerHeight = (window.screen.height - windowHeight) / 2;

    newWindow = window.open(windowUri, windowName, 'resizable=0,scrollbars='+windowScroll+',width=' + windowWidth + ',height=' + windowHeight + ',left=' + centerWidth + ',top=' + centerHeight);

    newWindow.focus();
    return newWindow.name;
}

//---------------------------------------sho pseudo popup

function popup (id)
	{
	if ( document.getElementById(id).style.display=='block' )	
		
		{
		document.getElementById(id).style.display='none';
		}
	else
		{
		document.getElementById(id).style.display='block';
		}
	}


function pop_frame (id,wid,hei,pos_x,pos_y,param)
	{
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
 myWidth=parseInt(myWidth/2-(wid/2) );
 myHeight=140;
 //myHeight=parseInt(myHeight/2-(hei/2) );	
 		
		if ( document.getElementById(id).style.display=='block' )	
			{
			document.getElementById(id).style.display='none';
			document.getElementById(id).innerHTML='';	
			}
		else
			{
			var hei2=hei+21;
			document.getElementById(id).style.display='block';
			document.getElementById(id).style.width=wid+'px';
			document.getElementById(id).style.height=hei2+'px';	
			document.getElementById(id).style.position='absolute';
			document.getElementById(id).style.top=pos_x+'px';
			document.getElementById(id).style.left=pos_y+'px';		
				
			document.getElementById(id).style.top=myHeight+'px';
			document.getElementById(id).style.left=myWidth+'px';		
			
			document.getElementById(id).innerHTML ='<a onclick="change(\''+id+'\')" style="margin:1px 1px 1px 1px; float:right; padding:1px 4px 1px 5px"><img src="/new/tango/16/emblems/emblem-unreadable.png" width="16" height="16" /></a><iframe src="/popup.php?CONT='+ param +'" width="'+wid+'px" height="'+hei+'px" frameborder="0" scrolling="no"></iframe>' ;	
			}
	
	}
//--------------------chenge height of item
function changesize(itemId,action,size)
{
var object,object_size;
object=document.getElementById(itemId);
object_size=object.offsetHeight;
if (action==1 )
	{
	if (object_size<1010)
		{		
		object_size=object_size+size;
		object.style.height= object_size+"px";
		}
	}
else if (action==3 )
	{
	object.style.height=size+"px";
	}
else
	{
	if (object_size>200)
		{
		object_size=object_size-size;
		object.style.height= object_size+"px";
		}
	}
}
//-----------------check backet before sent
function checkField(min_price,free_price,deli_cost,type)
	{
	var price = document.getElementById('bask').value;
	if (price<0.01)
		{
		alert ('Please choose your meal first.');
		return false;
		}
	else if (price < min_price && type!='collection')
		{
			
		var show1 = format(min_price,3);
		var show2 = ( min_price - price);
			show2 = format(show2,3);
		var agree = confirm ('Minimum delivery price for this shop is .'+show1+'. Your order will be rounded to this price.\n\nSpend '+show2+' more. \nOrder now (OK) or continue shopping (Cancel)');
			if (agree)
				return true ;
			else
				return false ;
			
		}
	else if (price < free_price && type!='collection')
		{
		var show1 = format(free_price,3);
		var show2 = format(deli_cost,3);
		var show3 = ( free_price - price);
			show3 = format(show3,3);
		var agree = confirm ('Free delivery price for this shop is '+show1+'. '+show2+' delivery charge will be added.\n\nSpend '+show3+' more for free delivery. \nOrder now (OK) or continue shopping (Cancel) ');
			if (agree)
				return true ;
			else
				return false ;
			
		}		
	else
		return true;			
	}
	
//number format
function format (obj, decimal) {
	 //decimal  - the number of decimals after the digit from 0 to 3
//-- Returns the passed number as a string in the xxx,xxx.xx format.
	   anynum=eval(obj);
	   divider =10;
	   switch(decimal){
			case 0:
				divider =1;
				break;
			case 1:
				divider =10;
				break;
			case 2:
				divider =100;
				break;
			default:  	 //for 3 decimal places
				divider =1000;
		}

	   workNum=Math.abs((Math.round(anynum*divider)/divider));

	   workStr=""+workNum

	   if (workStr.indexOf(".")==-1){workStr+="."}

	   dStr=workStr.substr(0,workStr.indexOf("."));dNum=dStr-0
	   pStr=workStr.substr(workStr.indexOf("."))

	   while (pStr.length-1< decimal){pStr+="0"}

	   if(pStr =='.') pStr ='';

	   //--- Adds a comma in the thousands place.    
	   if (dNum>=1000) {
		  dLen=dStr.length
		  dStr=parseInt(""+(dNum/1000))+","+dStr.substring(dLen-3,dLen)
	   }

	   //-- Adds a comma in the millions place.
	   if (dNum>=1000000) {
		  dLen=dStr.length
		  dStr=parseInt(""+(dNum/1000000))+","+dStr.substring(dLen-7,dLen)
	   }
	   retval = dStr + pStr
	   //-- Put numbers in parentheses if negative.
	   if (anynum<0) {retval="("+retval+")";}

	  
	//You could include a dollar sign in the return value.
	  var sign = 'KD';
	  retval =  sign+retval
	  
	  
	  
	  return retval;
 }
 
 
 
 /*check email*/
function trim(s)
{
  return s.replace(/^\s+|\s+$/, '');
}

function validateEmail(fld) {
    var error="";
    var tfld = fld.value;                        // value of field with whitespace trimmed off
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
   
    if (fld.value == "") {
        fld.className = 'falseField';
        return false;
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        fld.className = 'falseField';
        return false;
    } else if (fld.value.match(illegalChars)) {
       return false;
        error = "The email address contains illegal characters.\n";
    } else {
        fld.className = 'trueField';
    }
    return true;
}

/*check phone number*/
function validatePhone(fld) {
    var error = "";
    var stripped = fld.value.replace(/[\(\)\.\-\a-zA-Z ]/g, '');    
		fld.value=stripped;
   if (fld.value == "") {
        fld.className = 'falseField';
		return false;
    } else if (isNaN(parseInt(stripped))) {
        fld.className = 'falseField';
		return false;	
    } else if ( stripped.length !=8   ) {
        fld.className = 'falseField';
		return false;
    } else {
	fld.className = 'trueField';
    return true;
	}
}

function validateName(fld) {
    var error = "";
    var stripped = fld.value.replace(/ /g, '');    

   if (fld.value == "") {
        fld.className = 'falseField';
		return false;	
    } else if ( stripped.length <3  ) {
        fld.className = 'falseField';
		return false;
    } else {
	fld.className = 'trueField';
    return true;
	}
}



