var goodAmount = new Array();
var goodAmountPriceM = new Array();
var goodAmountPriceN = new Array();
var goodAmountTotalM = "0";
var goodAmountTotalN = "0";
var show;
var regWin;
var checkWin;
var email;
var scheduleFrame;
var someFrame;
var isCorrect;
var cart;
var someLog;
var registered=false;
var theDate = new Date();
theDate.setYear(theDate.getYear()+1);

function popup(show, someTD, someDiv)
{
	var theDivColor=colorToHex(document.getElementById(someDiv).style.color.valueOf());
	
  if(show)
  {
	 
     someTD.style.backgroundImage="url(images/background3.gif)";
     if(theDivColor=="#000000"||theDivColor=="#0")
     {
       document.getElementById(someDiv).style.color="#000000";
     }
	 else if(theDivColor=="") {
		 
	}
	 else
	 {
		 
		document.getElementById(someDiv).style.color="#ffffff"; 
	}
  }
  else
  {
    someTD.style.backgroundImage="";
	
    if(theDivColor=="#ffffff")
    {
       document.getElementById(someDiv).style.color="#888d8b";
    }
  }
}
function colorToHex(color) {
	
    if (color.substr(0, 1) === '#') {
        return color;
    }else if(color == ''){
		return "";
	}else if(color=='black'){
		return "#000000";	
	}
    var digits = /(.*?)rgb\((\d+), (\d+), (\d+)\)/.exec(color);
    
    var red = parseInt(digits[2]);
    var green = parseInt(digits[3]);
    var blue = parseInt(digits[4]);
    
    var rgb = blue | (green << 8) | (red << 16);
	
    return digits[1] + '#' + rgb.toString(16);
	
}
function inside(aPage, aFrame, aDiv)
{
  var divName;
 
  var startNum;
  var nextMonth;
  var someNumber="&nbsp;";
  
  aFrame.document.close();
  
  if(aPage=="home")
  {
    aFrame.location.href="http://mi2c.com/mi2c.html";
  }
  if(aPage=="multimedia")
  {
    aFrame.location.href="http://mi2c.com/multimedia.html";
  }

  if(aPage=="contact")
  {       	
       aFrame.document.write("<html><head><title>contact</title><script language='javascript' type='text/javascript' src='jscript.js' ></script></head><body link='#000000' vlink='#000000' alink='#aaafab' ><div align='center' valign='center'><p style='font-size:20pt;font-weight:bold;color:#444444;'><br />&nbsp;<br /></p><a id='anchorid' href='mailto:info@mi2c.com' onMouseOut='changeBackground(\"false\")' onMouseOver='changeBackground(\"true\")'><font size='40pt' weight='bold' color='black'>info@mi2c.com</font></a></div></body></html>");
       regWin=aFrame;
  }
  if(aPage=="cv")
  {
    aFrame.location.href="http://mi2c.com/cv.html";
  }
  
  changeColor(aDiv);

}

function changeBackground(val){
 	if(val=="true"){
		document.getElementById("anchorid").style.color="#ffffff";
	}else{
		document.getElementById("anchorid").style.color="#000000";
	}
 
 }
function checkFormat(someString)
{
      someString=someString + "";
      if(someString.indexOf(".")<0)
      {
         someString=someString+".00"
         return someString;	
      }
      if(someString.indexOf(".")==someString.length-2)
      {
         someString=someString+"0"
         return someString;	
      }
      return someString;
}


function addToCookie(aProduct, anAmount)
{
   var thisCookie;
   var stuff="";
   var found=false;
   if(document.cookie)
   {
      thisCookie=document.cookie.split("; ");
      for(i=0;i<thisCookie.length;i++)
      {
         if("purch"==thisCookie[i].split("=")[0])
         {
             found=true;
             stuff=thisCookie[i].split("=")[1];
             break;
             
         }
      }   
   }
   if(found) //if the purch crumb has been found
   {
      var amount ;
      var someProd;
      var anIndex;
      var amountOfItems = new Array();
      var someProd=stuff.split(",");
      found=false;
      for(i=0;i<someProd.length;i++)
      {
         if(articles[aProduct].prodNum==someProd[i].split("/")[0])
         {
             found=true;
             amountOfItems[i]=someProd[i].split("/")[1];
             anIndex=i;
         }
      }   
      if(found) //if the product to change has been found
      {
      	
      	  eatCookie("purch");
          var newPurch = "purch=";
          for(i=0;i<someProd.length;i++)
          {
          	if(i==anIndex) //if it is the article to change
          	{
          		var newAmount = (parseInt(someProd[i].split("/")[1])+ anAmount*1);
          		if(i>0)
          		{
          			
          		   newPurch = newPurch + ",";	
          		}
          		newPurch = newPurch + someProd[i].split("/")[0] + "/" + newAmount;
          	}
          	else
          	{
          		if(i>0)
          		{
          			
          		   newPurch = newPurch + ",";	
          		}
          		newPurch = newPurch +someProd[i] ;	
          	}
          }
          newPurch=newPurch+"; expires=" + theDate.toGMTString();
      }
      else
      {
      	
      	  eatCookie("purch");
          var newPurch = "purch=" + stuff + ",";		
          newPurch = newPurch + articles[aProduct].prodNum + "/" + anAmount;	
          newPurch=newPurch+"; expires=" + theDate.toGMTString();
      }
      document.cookie=newPurch;
   }
   else
   {
      document.cookie="purch=" + articles[aProduct].prodNum + "/" + anAmount + "; expires=" + theDate.toGMTString();
   }
   return;
}

function eatCookie(aCookie)
{
   var stale=new Date();
   var thisCookie;
   if(document.cookie)
   {
   	thisCookie=document.cookie.split("; ");
   	stale.setYear(stale.getYear()-2);
   	for(i=0;i<thisCookie.length;i++)
   	{
		if(aCookie==thisCookie[i].split("=")[0])
		{
		   document.cookie= aCookie + "=; expires=" + stale.toGMTString(); 
		}
   	}
   }
   	
}

function increment(someText)
{
   someText.value=(someText.value *1)+1;
}

function decrement(someText)
{
   if(someText.value>0)
   {
     someText.value=(someText.value *1)-1;
   }
}

function changeColor(aDiv)
{

  document.getElementById('divHome').style.color="#888d8b";
  document.getElementById('divMultimedia').style.color="#888d8b";
  document.getElementById('divContact').style.color="#888d8b";
  document.getElementById('divCV').style.color="#888d8b";
  document.getElementById(aDiv).style.color="#000000";
  
  return;

}
function firstColor()
{

  document.getElementById('divHome').style.color="#000000";
  document.getElementById('divHome').style.fontSize="19pt";
  document.getElementById('divMultimedia').style.color="#888d8b";
  document.getElementById('divMultimedia').style.fontSize="19pt";
  document.getElementById('divContact').style.color="#888d8b";
  document.getElementById('divContact').style.fontSize="19pt";
  document.getElementById('divCV').style.color="#888d8b";
  document.getElementById('divCV').style.fontSize="19pt";
  
  return;

}

function valEmail(email)
{
   var invalidChars=" /:;,";
   for(i=0;i<invalidChars.length;i++)
   {
     var badChar=invalidChars.charAt(i);
     if(email.indexOf(badChar,0)>-1){return false;}    
   }
   var atPos=email.indexOf("@",0);
   if(atPos<1){return false;}
   if(email.indexOf("@", atPos+1)>-1){return false;}
   if(email.charAt(email.indexOf("@",0)+1)=="."){return false;}
   var periodPos=email.indexOf(".", atPos+1);
   if(periodPos==-1){return false;}
   while(email.indexOf(".",periodPos+1)>-1)
   {
      periodPos=email.indexOf(".",periodPos+1);
   }
   var lastChars=email.substring(periodPos+1,email.length)
   if((lastChars.length==2) || (lastChars.length==3) || (lastChars=="info")){return true;}
   else {return false;}  
}

function killcookie()
{
	if(isTheUserLogged("0")=="true")
	{
		var stale=new Date();
		stale.setYear(stale.getYear()-2);
		document.cookie= "log=; expires=Wed, 16-Jan-2002 12:00:00 GMT; path=/"; 
	}
}
