/**
* Main bigmarket.gr javascript file
**/

window.onload = ActivateFlash

var emailfilter=/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i

function checkmail(e){
   return emailfilter.test(e.value);
}

function decodeUtf8(source){
    var result = '';
    if (source!=null && source!=''){
    	var chars = source.split(";");
    	//alert("length: " + chars.length);
    	if (chars.length>0){
          for (i=0; i<chars.length - 1 ; i++){
	          var tmpstr = chars[i];
	          //alert("tmpstr: " + tmpstr + " - length: " + tmpstr.length);
	          if (tmpstr!=null && tmpstr!=''){
	            var code = tmpstr.substr(2, tmpstr.length);
	            //alert("code: " + code);
	            result += String.fromCharCode(code);	    
	            //alert("result: " + result);
          	  }
      	  }
    	}
    }
    return result;
}   

/**
* Open's the progress bar (div)
**/
function showProgressDiv(){
	document.getElementById('progressDiv').style.visibility="visible";
}

function ActivateFlash(){
    var objects = document.getElementsByTagName("object");
    for (var i = 0; i < objects.length; i++)
    {
      objects[i].outerHTML = objects[i].outerHTML;
    }
}
 
function displayLink(p_type, p_url, p_title, p_link_text) {

  var agt = navigator.userAgent.toLowerCase();
  var p_here = top.location.href

  if (p_type == 3)
  {
    if ((agt.indexOf("opera") != -1)) // || (agt.indexOf("firefox") != -1))
    {
      document.write("<a class=\"bottom-link\" href=\""+p_here+"\" title=\"" + p_title + "\" rel=\"sidebar\">" + p_link_text + "</a>");
    } else
    {
      document.write("<a class=\"bottom-link\" href=\"javascript:addBookmark('"+p_title+"',top.location.href);\" title=\"" + p_title + "\" >" + p_link_text + "</a>");
    }
  } else
  {
    if (agt.indexOf("opera") != -1) 
    {
      document.write("<a class=\"bottom-link\" href=\"" + p_url + "\" title=\"" + p_title + "\" rel=\"sidebar\">" + p_link_text + "</a>");
    } else
    {
      document.write("<a class=\"bottom-link\" href=\"javascript:addBookmark('"+p_title+"','"+p_url+"');\" title=\"" + p_title + "\" >" + p_link_text + "</a>");
    }
  }
}


function addBookmark(title,url) {

  var msg_netscape = "NetScape message";
  var msg_opera    = "This function does not work with this version of Opera.  Please bookmark us manually.";
  var msg_other    = "Your browser does not support automatic bookmarks.  Please bookmark us manually.";
  var agt          = navigator.userAgent.toLowerCase();


  if (agt.indexOf("opera") != -1) 
  {
    if (window.opera && window.print)
    {
      return true;
    } else 
    {
      alert(msg_other);
    }
  }    
  else if (agt.indexOf("firefox") != -1) window.sidebar.addPanel(title,url,"");
  else if ((agt.indexOf("msie") != -1) && (parseInt(navigator.appVersion) >=4)) window.external.AddFavorite(url,title); 
  else if (agt.indexOf("netscape") != -1) window.sidebar.addPanel(title,url,"")         
  else if (window.sidebar && window.sidebar.addPanel) window.sidebar.addPanel(title,url,""); 
  else alert(msg_other);
  
}

function showMap(actionUrl) {
	  mapWin = window.open(actionUrl, "mapWindows", "width=700,height=600,left=80,top=80,location=no,dependent=yes,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no");
	  mapWin.focus();
}

//Cookie Manipulation Functions- START
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function getCookieValue(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0; i < ca.length; i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}
//Cookie Manipulation Functions- END
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
