////////////////////////////////////////////////////////////////////
/////////////// Validate functions                    //////////////
////////////////////////////////////////////////////////////////////
var TypeEmail = "Kérem adja meg az email címét!";
var TypePassowrd = "A jelszó mező kitöltése kötelező!";
var PasswordMin6Car = "A jelszó túl rövid minimum 6 karakternek kell lennie!";
var TypePasswordRe = "A jelszót megegyszer meg kell adni!";
var PasswordsNoEgal = "A megadott két jelszó nem egyezik!";
var TypeFirmName = "Kérem adja meg a cég nevét!";
var TypeContactName = "Kérem adja meg a kapcsolattartó nevét!";
var TypeVerifyCode = "Kérem adja meg a biztonsági kódot!";

var TypeName = "Kérem adja meg a nevét!";
var TypeMessage = "Kérem töltse ki az üzenet mezőt!";

var TypePasswordOld = "Kérem adja meg a régi jelszót!";
var TypePasswordNew = "Kérem adja meg az új jelszót!";
var TypePasswordNewRe = "Kérem adja meg az új jelszót mégegyszer!";

var TypeSiteName = "Kérem adja meg a weboldal nevét!";
var TypeSiteUrl = "Kérem adja meg a weboldal url-jét!";

var SelectAdvertisement = "Kérem válasszon egy hírdetést amit módosítani szeretne!";
var TypeAdvertisementName = "Kérem adja meg a hírdetés nevet!";
var TypeAdvertisementTitle = "Kérem adja meg a hírdetés címét!";
var TypeAdvertisementText = "Kérem adja meg a hírdetés szövegét!";
var TypeAdvertisementFooter = "Kérem adja meg a hírdetés láblécét!";
var TypeAdvertisementUrl = "Kérem adja meg a hírdetés url-jét!";
var TypeAddvertisementClick = "A napi átkantintási limitnek számjegyből kell, hogy állnia és 0 sem lehet!";

var CreditMinMail = "A napi átkattintási limitnek számjegyből kell állnia!";
var EmailMaybeWrong = "Az email cím nem tűnik valósnak!";

function CheckRegister(regtype)
{
	if (!CheckEmail(document.all.email, TypeEmail, true, false)) return false;

	if (!CheckControl(document.all.passwd, TypePassowrd, true, false)) return false;
	if (!CheckControlLength(document.all.passwd, PasswordMin6Car, 6)) return false;
	if (!CheckControl(document.all.repasswd, TypePasswordRe, true, false)) return false;
	  
	if (document.all.passwd.value != document.all.repasswd.value)
	{
		document.all.passwd.style.borderColor = "#ff0000";
		document.all.repasswd.style.borderColor = "#ff0000";
		alert(PasswordsNoEgal);
		document.all.passwd.value = "";
		document.all.repasswd.value = "";
		document.all.passwd.focus();
		return false;
	}else{
		document.all.passwd.style.borderColor = "#656565";
		document.all.repasswd.style.borderColor = "#656565";
	}

	if (!CheckControl(document.all.contactname, TypeContactName, true, false)) return false;
	if (!CheckControl(document.all.code, TypeVerifyCode, true, false)) return false;

	return true;
}

//-----
function CheckSendContact()
{
	if (!CheckControl(sendform.name, TypeName, true, false)) return false;
	if (!CheckEmail(sendform.email, TypeEmail, true, false)) return false;
	if (!CheckControl(sendform.message, TypeMessage, true, false)) return false;
	
	return true;
}

function CheckModifyPasswd()
{
	if (!CheckControl(document.all.oldpasswd, TypePasswordOld, true, false)) return false;
	if (!CheckControl(document.all.newpasswd, TypePasswordNew, true, false)) return false;
	if (!CheckControlLength(document.all.newpasswd, PasswordMin6Car, 6)) return false;
	if (!CheckControl(document.all.renewpasswd, TypePasswordNewRe , true, false)) return false;

	if (document.all.newpasswd.value != document.all.renewpasswd.value)
	{
		document.all.newpasswd.style.borderColor = "#ff0000";	
		document.all.renewpasswd.style.borderColor = "#ff0000";				
		alert("Parolele noua introduse nu coincid!");
		document.all.newpasswd.value = "";
		document.all.renewpasswd.value = "";		
		document.all.newpasswd.focus();
		return false;
	}else{
		document.all.newpasswd.style.borderColor = "#656565";
		document.all.renewpasswd.style.borderColor = "#656565";		
	}
	
	return true;
}


function CheckModifyData()
{
	if (!CheckControl(document.all.firmname, TypeFirmName, true, false)) return false;
	if (!CheckControl(document.all.contactname, TypeContactName, true, false)) return false;
	
	return true;
}

var ColorName = "Kérem adja meg a színséma nevét!";
var SelectColor = "Kérem válasszon egy színsémát!";
var TypeTitleColor = "Kérem adja meg a hírdetés címének a színét!";
var TitleColorLength = "A hírdetés címének a színé 6 karakterből kell állnia!";

var TypeTextColor = "Kérem adja meg a hírdetés szövegének a színét!";
var TextColorLength = "A hírdetés szövegének a színé 6 karakterből kell állnia!";

var TypeFooterColor = "Kérem adja meg a hírdetés láblécének a színét!";
var FooterColorLength = "A hírdetés láblécének a színé 6 karakterből kell állnia!";

var TypeBackGroundColor = "Kérem adja meg a hírdetés háttérszínét!";
var BackGroundColorLength = "A hírdetés háttérszíne 6 karakterből kell állnia!";

var TypeBorderColor = "Kérem adja meg a keret színét";
var BorderColorLength = "A keret színének 6 karakterből kell állnia!";

var TypeMyBorderColor = "Kérem adja meg az alsó szöveg színét!";
var MyBorderColorLength = "Az alsó szöveg színének 6 karakterből kell állnia!";

var TypeMyBackGroundColor = "Kérem adja meg az alső szöveg háttérszínét!";
var MyBackGroundColor = "Az alsó szöveg háttérszínének 6 katakterből kell állnia!";

function CheckAddAdvertisementColor(type)
{
      if (type == "ADD")
      {
            if (!CheckControl(document.all.colorname, ColorName, true, false)) return false;
      }
      if (type == "MOD")
      {
            if (document.all.idcolor.value == "0")
            {
                  alert(SelectColor);
                  return false;
            }
      }
	if (!CheckControl(document.all.headercolor, TypeTitleColor, true, false)) return false;
	if (!CheckControlLengthEgal(document.all.headercolor, TitleColorLength, 7)) return false;

	if (!CheckControl(document.all.textcolor, TypeTextColor, true, false)) return false;
	if (!CheckControlLengthEgal(document.all.textcolor, TextColorLength, 7)) return false;

	if (!CheckControl(document.all.footercolor, TypeFooterColor, true, false)) return false;
	if (!CheckControlLengthEgal(document.all.footercolor, FooterColorLength, 7)) return false;

	if (!CheckControl(document.all.backgroundcolor, TypeBackGroundColor, true, false)) return false;
	if (!CheckControlLengthEgal(document.all.backgroundcolor, TypeBackGroundColor, 7)) return false;
	
	if (document.all.isborder.checked)
	{
		if (!CheckControl(document.all.bordercolor, TypeBorderColor, true, false)) return false;
		if (!CheckControlLengthEgal(document.all.bordercolor,BorderColorLength, 7)) return false;
	}
	
	if (!CheckControl(document.all.mytextcolor, TypeMyBorderColor, true, false)) return false;
	if (!CheckControlLengthEgal(document.all.mytextcolor, MyBorderColorLength, 7)) return false;

	if (!CheckControl(document.all.mybackgroundcolor, TypeMyBackGroundColor, true, false)) return false;
	if (!CheckControlLengthEgal(document.all.mybackgroundcolor, MyBackGroundColor, 7)) return false;
	
}

function CheckForgotEmail()
{
	if (!CheckEmail(document.all.email, TypeEmail, true, false)) return false;
	
	return true;
}

function ConfirmRequestCredit()
{
      var selectedItem = document.all.list.selectedIndex;
      var selectedText = document.all.list.options[selectedItem].text;
      if (confirm('Biztosan felakarja tölteni egyenlegét ' + selectedText + ' RON értékben?'))
      {
            return true;
      }
    
      return false;
}

function CheckAddPartnerSite()
{
	if (!CheckControl(document.all.sitename,TypeSiteName , true, false)) return false;
	if (!CheckControl(document.all.url,TypeSiteUrl, true, false)) return false;
}

var SelectSite = "Kérem válasszon egyet weboldalai közül!";
var SelectColor = "Kérem válasszon egyet a beállított színsémák közül!";
var SelectType = "Kérem válasszon egy hirdetési mintát!";

function CheckGetCode()
{
      if (document.all.idsite.value == "0")
      {
            alert(SelectSite);
            return false;
      }
      if (document.all.idcolor.value == "0")
      {
            alert(SelectColor);
            return false;
      }
      if (document.all.idtype.value == "0")
      {
            alert(SelectType);
            return false;
      }

      return true;
}

function CheckNewsLetterEmail()
{
	if (!CheckEmail(document.all.newletteremail, TypeEmail, true, false)) 
	{		return false;
	}
	
	return true;
}

////////////////////////////////////////////////////////////////////
/////////////// Client functions                    //////////////
////////////////////////////////////////////////////////////////////
function ResetAddAdvertisement()
{
	document.all.name.value = "";
	document.all.header.value = "";
	document.all.text.value = "";
	document.all.footer.value = "";
	document.all.url.value = "";
	document.all.clickday.value = "";
}

function CheckAddAdvertisement(type)
{
	if (type == "MOD")
	{
		if (document.all.adid.value == "0")
		{
			alert(SelectAdvertisement);
			return false;
		}
	}
	
	if (!CheckControl(document.all.name, TypeAdvertisementName, true, false)) return false;
	if (!CheckControl(document.all.header, TypeAdvertisementTitle, true, false)) return false;
	if (!CheckControl(document.all.text, TypeAdvertisementText, true, false)) return false;
	if (!CheckControl(document.all.url, TypeAdvertisementUrl, true, false)) return false;
	if (document.all.clickday.value != "" && !IsNumber(false, document.all.clickday.value))
	{
		alert(TypeAddvertisementClick);
		document.all.clickday.focus();
		return false;
	}
}

function ViewAddAdvertisement()
{
    url = "advertisement.php?type=PUB&header=" + document.all.header.value + "&text=" + document.all.text.value + "&footer="+document.all.footer.value + "&url=" + document.all.url.value;
    parent.frames[0].location = url;
}

function ViewAddAdvertisementColor()
{
    header_color = "3C9BB9";
    text_color = "000000";
    footer_color = "EE8911";
    background_color = "ffffff";
    is_border = "0";
    border_color = "000000";
    mybackground_color = "3C9BB9";
    mytext_color = "ffffff";

    if (document.all.headercolor.value.length == 7)
        header_color = document.all.headercolor.value.substring(1);
    if (document.all.textcolor.value.length == 7)
        text_color = document.all.textcolor.value.substring(1);
    if (document.all.footercolor.value.length == 7)
        footer_color = document.all.footercolor.value.substring(1);
    if (document.all.backgroundcolor.value.length == 7)
        background_color = document.all.backgroundcolor.value.substring(1);
    if (document.all.isborder.checked)
        is_border = "1";
    if (document.all.bordercolor.value.length == 7)
        border_color = document.all.bordercolor.value.substring(1);

    if (document.all.mybackgroundcolor.value.length == 7)
        mybackground_color = document.all.mybackgroundcolor.value.substring(1);
    if (document.all.mytextcolor.value.length == 7)
        mytext_color = document.all.mytextcolor.value.substring(1);


    url = "advertisement.php?type=PAR&headercolor=" + header_color +
            "&textcolor=" + text_color +
            "&footercolor=" + footer_color +
            "&backgroundcolor=" + background_color +
            "&isborder="+is_border +
            "&bordercolor=" + border_color +
            "&mytextcolor=" + mytext_color +
            "&mybackgroundcolor=" + mybackground_color;
    parent.frames[0].location = url;
//    HMW_open_popup(url,'popup','width=126px,height=126px,top=200px,left=300px,location=no,menubar=no,resizable=no,scrollbars=no,status=no,titlebar=yes,toolbar=no');
}

function CheckMailCreditMin()
{
	if (!IsNumber(true, document.all.credit_min.value))
	{
		alert(CreditMinMail);
		document.all.credit_min.focus();
		return false;
	}
}

function GotFocus(type)
{
      document.getElementById("help").firstChild.nodeValue = ar[type];     
}
////////////////////////////////////////////////////////////////////
/////////////// Utilitis functions                    //////////////
////////////////////////////////////////////////////////////////////

//-----
function emptystr(s){
	if  ((s==null) || (s.length == 0))
		return true;
	else
		return false;
}

function CheckControl(controlname, message, mustfocus, mustclear)
{
	if (emptystr(controlname.value))
	{
		controlname.style.borderColor = "#ff0000";
		alert(message);
		if (mustfocus) controlname.focus();
		if (mustclear) controlname.value = "";
		
		return false;
	}else{
		controlname.style.borderColor = "#656565";
	}
	
	return true;
}

function CheckControlLength(controlname, message, len)
{
      if (controlname.value.length < len)
      {
            controlname.style.borderColor = "#ff0000";
            alert(message);
            return false;
      }else{
            controlname.style.borderColor = "#656565";
	}
	
	return true;
}

function CheckControlLengthEgal(controlname, message, len)
{
    if (controlname.value.length != len)
    {
		controlname.style.borderColor = "#ff0000";
        alert(message);
        return false;
    }else{
		controlname.style.borderColor = "#656565";
	}
	
	return true;
}

function CheckEmail(controlname, message, mustfocus, mustclear)
{
	if (!CheckControl(controlname, message, true, false)) return false;
	
	if (ValidateEmail(controlname.value)==false){
		controlname.style.borderColor = "#ff0000";	
		if (mustclear) controlname.value="";
		if (mustfocus) controlname.focus()
		return false
	}else{
		controlname.style.borderColor = "#656565";		
	} 
	
	return true;
}
//-----
function ValidateEmail(str) {

	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	   alert(EmailMaybeWrong)
	   return false
	}
	
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   alert(EmailMaybeWrong)
	   return false
	}
	
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
	   alert(EmailMaybeWrong)
	    return false
	}
	
	 if (str.indexOf(at,(lat+1))!=-1){
	   alert(EmailMaybeWrong)
	    return false
	 }
	
	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
	   alert(EmailMaybeWrong)
	    return false
	 }
	
	 if (str.indexOf(dot,(lat+2))==-1){
	   alert(EmailMaybeWrong)
	    return false
	 }
	
	 if (str.indexOf(" ")!=-1){
	   alert(EmailMaybeWrong)
	    return false
	 }

	 return true					
}


function IsNumber(zero, val_number)
{
    ret = false;
    ret = /^\d+$/.test(val_number);
    
    Z = + RegExp.input
	if (!zero)
		if (Z == 0) ret = false;
    
    return ret;
}

function HMW_open_popup(popA,popB,popC){
	 window.open(popA,popB,popC);
}


