//if (window.top != window.self)
//{
// 	window.top.location=window.self.location;
//}

var f_level;
var cur_menu = '';
var old_name = '';
var old_file_name = '';
var showing_menu = 0;

function checkEmail(f)
{
	errors = "The following errors have been found: \n\n";
	valid = true;

    if (f.name.value == "")
    {
        errors += "- Name must be completed.\n";
        valid = false;
    }

    if (f.email.value == "")
    {
        errors += "- Email Address must be completed.\n";
        valid = false;
    }
    else if (!validateEmail(f.email.value))
    {
        valid = false;
        errors += "- E-mail address is not a proper e-mail address\n";
    }

    if (!valid)
    {
        errors += "\nPlease try again";
        alert(errors);
    }

	return valid;
}

/*
 * validate email address, check for illegal characters, check there is one
 * @ sign and at least one . after it. return true or false
 */
function validateEmail(tempEmail)
{

   var valid = true;
   len = tempEmail.length;

   if(len==0){
        valid = false;
   }


   spaces = tempEmail.indexOf(' ');
        // check for spaces
        if(spaces != -1)
                valid = false;

   ampers = tempEmail.indexOf('&');
        // check for ampersands
        if(ampers != -1)
                valid = false;

   at = tempEmail.indexOf('@');
        // check there is a at sign
        if(at == -1)
                valid = false;

   atmore = tempEmail.indexOf('@',(at+1));
        // check for more at signs
        if(atmore != -1)
                valid = false;

   dot = tempEmail.indexOf('.',at);
        // check for a dot after the at sign
        if(dot== -1)
                valid = false;

   if((at == 0)||(at== len))
   {
        // check where the at sign is
        valid = false;
   }

   return valid;
}

function readCookie(cName) 
{
 var val="";
 if (document.cookie.indexOf(cName) != -1) {
    strt = (document.cookie.indexOf(cName)+cName.length)+1;
    end = document.cookie.indexOf(";",strt);
    if(end == -1) 
    {
      end = document.cookie.length;
    }
    val += unescape(document.cookie.substring(strt,end));
 }
 return val;

}

function setCookie(valName,val) 
{
   document.cookie = valName + "=" + escape(val) + "; path=/;";
}


//if(readCookie("seenPopup")=="")
//{
	//setCookie("seenPopup","true");
	//showPromotion();
//}

function showPromotion()
{
    newWin = window.open("enterpromotion.php","promo","toolbars=no,width=250,height=250");
    newWin.focus();
}

function show_menu(doit, i_id, file_name) {
		 var Obj;
		 if (old_name.length) {
			 Obj = document.getElementById(old_name);
			 Obj.src = old_file_name;
		 }
		 Obj = document.getElementById(i_id);
		 old_name = i_id;
		 old_file_name = Obj.src;
		 Obj.src = file_name;

		 showing_menu = 0;
		 hide_menu();
		 cur_menu = 'menu_'+doit;
		 Obj = document.getElementById(cur_menu);
	     Obj.style.visibility = 'visible';
		 showing_menu = 1;
}

function hide_all() {
		 var Obj;
		 if (showing_menu == 0) {
			 if (old_name.length) {
				 Obj = document.getElementById(old_name);
				 Obj.src = old_file_name;
			 }
			 hide_menu();
			 f_level = 0;
		 }
}

function hide_menu() {
		 if (showing_menu) {
		 } else {
		     if (cur_menu != '') {
				 Obj = document.getElementById(cur_menu);
				 Obj.style.visibility = 'hidden';
				 cur_menu = '';
			 }
		 }
}

function redirect(theme,format)
{
	 document.location = "theme.php?theme_id=" + theme + "&format=" + format;
}