function validate()
{
if( !document.searchform.searchtext.value || document.searchform.searchtext.value.length < 3) {
            document.searchform.searchtext.focus();
            alert('Search term too short, please try again');
            return false;
 }
}

function OpenWindow(page,name,w,h,scroll)
{
setari = 'height='+h+',width='+w+',scrollbars='+scroll+',resizable';
win = window.open('/brokenlink'+page,name,setari);
}

function OpenWindow1(page,name,w,h,scroll)
{
setari = 'height='+h+',width='+w+',scrollbars='+scroll+',resizable';
win = window.open(page,name,setari);
}

function checkform(form)
    {

        if (form.name.value == '')
            {
                alert ("Please enter your name.\n");
                form.name.focus();
                return false;
            }
        if (form.email.value == '')
            {
                 alert ("Please enter an E-mail address.\n");
                 form.email.focus();
                 return false;
            }
        var val = emailCheck(form.email.value);
        if (!val)
        {
            form.email.focus();
            return false;
        }
        if (form.questions.value == '')
            {
                alert ("Please enter your questions.\n");
                form.questions.focus();
                return false;
            }
        if (form.code.value == '')
            {
                alert ("Please enter image code.\n");
                form.code.focus();
                return false;
            }            
    }

function emailCheck (emailStr)
    {
        var emailPat=/(.+)@(.+)/;
        var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]";
        var validChars="\[^\\s" + specialChars + "\]"
        var quotedUser="(\"[^\"]*\")";
        var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
        var atom=validChars + '+';
        var word="(" + atom + "|" + quotedUser + ")";
        var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
        var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
        var matchArray=emailStr.match(emailPat);
        if (matchArray==null)
            {
             alert("The Email address entered seems incorrect (check @ and .'s)");
             return false;
            }
        var user=matchArray[1]
        var domain=matchArray[2]

        if (user.match(userPat)==null)
            {
                alert("The email address entered does not have a valid username.");
                return false;
            }

        var IPArray=domain.match(ipDomainPat);
        if (IPArray!=null)
            {
             for (var i=1;i<=4;i++)
                 {
                     if (IPArray[i]>255)
                         {
                             alert("The e-mail address entered appears to be invalid.");

                          return false;
                         }
                    }
                //return true;
            }

        var domainArray=domain.match(domainPat)
        if (domainArray==null)
            {
             alert("The email address entered does not have a valid domain name.");
                return false;
            }

        var atomPat=new RegExp(atom,"g");
        var domArr=domain.match(atomPat);
        var len=domArr.length;
        if (domArr[domArr.length-1].length<2 ||domArr[domArr.length-1].length>3)
            {
                alert("The email address entered does not end in a three-letter domain or two-letter country.");
                return false;
            }

        if (len<2)
            {
                var errStr="The email address entered is missing a hostname.";
                alert(errStr);
                return false;
            }

        return true;
    }

function add_favorites()
{
	var detect = navigator.userAgent.toLowerCase();
	//alert(detect);
	if(detect.indexOf('opera') + 1) alert("After you close this dialog please press CTRL+T to add to Favorites");
	else if(detect.indexOf('msie') + 1) window.external.AddFavorite(varsite,vardesc);
	else if(detect.indexOf('firefox') + 1) alert("After you close this dialog please press CTRL+D to add to Favorites");
	else if(detect.indexOf('netscape') + 1) alert("After you close this dialog please press CTRL+D to add to Favorites");
	else alert("Please use your browser's menu to add to Favorites");
}
function validate()
{
if( !document.searchform.searchtext.value || document.searchform.searchtext.value.length < 3) {
            document.searchform.searchtext.focus();
            alert('Search term too short, please try again');
            return false;
 }
}

function OpenWindow(page,name,w,h,scroll)
{
setari = 'height='+h+',width='+w+',scrollbars='+scroll+',resizable';
win = window.open('/brokenlink'+page,name,setari);
}

function OpenWindow1(page,name,w,h,scroll)
{
setari = 'height='+h+',width='+w+',scrollbars='+scroll+',resizable';
win = window.open(page,name,setari);
}

function verifyFormSubscribe(theForm){
    var msg='';

    if((theForm.input_email.value=='blank')||(theForm.input_email.value=='')){
            msg='Wrong email address!'
            theForm.input_email.focus();
    }else
    if((theForm.input_email.value.indexOf('@')<1)||
    (theForm.input_email.value.indexOf('@')>(theForm.input_email.value.length - 5))||
    (theForm.input_email.value.indexOf('.')<1)){
            msg='Wrong email address!'
            theForm.input_email.focus();
    }

    if(msg!=''){
            alert(msg);
            return false
    }else{
            return true;

    }
}

function showhide(divid){
document.getElementById(divid).style.display = (document.getElementById(divid).style.display=='none')?'':'none';
}

function saveads(id,rr)
{
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return;
} 

var url="/index.php?p=addwishlist&id="+id
url=url+"&action="+rr
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChanged ;	
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
return;
} 

function stateChanged() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{ 
valoare1=xmlHttp.responseText;
document.getElementById('saveadid').innerHTML =valoare1;
var show = document.getElementById("saveadid");
var showStyle = show.style;
showStyle.display = "";
showStyle.padding = "15px 8px 8px 8px";
} 
} 



function GetXmlHttpObject()
{ 
var objXMLHttp=null
if (window.XMLHttpRequest)
{
objXMLHttp=new XMLHttpRequest()
}
else if (window.ActiveXObject)
{
objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
}
return objXMLHttp
} 


var xmlHttp
var innerstr;
var pagsunt;
var idto;


  
function f1rate(text,rate,star){
	document.getElementById('voteazatu').innerHTML=text;
	for(var i=1;i<=rate;i++){
		document.getElementById('rateid'+i).src=star;
	}
}

function frate(id,nota){
	if (id>0 && (nota<=5  && nota>=1)){
	idto=id;
	xmlHttp=GetXmlHttpObjectxx()
	if (xmlHttp==null)
	{
	document.getElementById('voturiid').innerHTML='Error while vote' ;
	return
	} 
	var url="/index.php"
	url=url+"?p=rate&id="+id+"&nota="+nota
	url=url+"&sid="+Math.random()
	xmlHttp.onreadystatechange=stateChangednew ;
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
	}
}
 
function frate2(id){
	if (id>0){
	
	xmlHttp=GetXmlHttpObjectxx1()
	if (xmlHttp==null)
	{
	return
	} 
	var url="/index.php"
	url=url+"?p=vot&id="+id
	url=url+"&sid="+Math.random()
	xmlHttp.onreadystatechange=stateChangeds ;
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
	}
}
 
function wait(msecs)
{
var start = new Date().getTime();
var cur = start
while(cur - start < msecs)
{
cur = new Date().getTime();
}
} 

function stateChangednew() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{ 
document.getElementById('voturiid').innerHTML=xmlHttp.responseText ;
if (xmlHttp.responseText.indexOf("Thank you!")>0){
	wait(1000);
	frate2(idto);
	//alert(idto);
}
//Multumim pentru vot!
} 
} 
 
function stateChangeds() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{ 
document.getElementById('voturiid').innerHTML=xmlHttp.responseText ;
} 
}
 
function GetXmlHttpObjectxx()
{ 
var objXMLHttp=null
if (window.XMLHttpRequest)
{
objXMLHttp=new XMLHttpRequest()
}
else if (window.ActiveXObject)
{
objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
}
return objXMLHttp
} 

function GetXmlHttpObjectxx1()
{ 
var objXMLHttp=null
if (window.XMLHttpRequest)
{
objXMLHttp=new XMLHttpRequest()
}
else if (window.ActiveXObject)
{
objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
}
return objXMLHttp
} 


function stateChangeds() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{ 
document.getElementById('voturiid').innerHTML=xmlHttp.responseText ;
} 
}


function faddmail(id)
{
if(trim(document.getElementById('comformail').numeid.value)==''){
alert('The Name field was left blank!'); 
return false;
}
if(trim(document.getElementById('comformail').emailid.value)==''){
alert('The Email Address you entered appears to be invalid!'); 
return false;
}
if(trim(document.getElementById('comformail').emailpid.value)==''){
alert('The Friend Email Address you entered appears to be invalid!'); 
return false;
}
if(trim(document.getElementById('comformail').spamid.value)==''){
alert('Please enter anti spam number!'); 
return false;
}
if(trim(document.getElementById('comformail').mesajid.value)==''){
alert('Please enter a message!'); 
return false;
}
pagsunt='casutamail';
pagsunt1='comentariim';
	if (id>0){
	
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
	alert('Error');
	return false;
	} 
	var url="/index.php"
	url=url+"?p=trimite&id="+id
	url=url+"&nume="+addSlashes(document.getElementById('comformail').numeid.value)
	url=url+"&email="+addSlashes(document.getElementById('comformail').emailid.value)
	url=url+"&emailp="+addSlashes(document.getElementById('comformail').emailpid.value)		
	url=url+"&spam="+addSlashes(document.getElementById('comformail').spamid.value)		
	url=url+"&mesaj="+addSlashes(document.getElementById('comformail').mesajid.value)
	url=url+"&sid="+Math.random()
	xmlHttp.onreadystatechange=stateChangedr ;
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
	}
}

function hideinfo(){
	//document.getElementById('comformail').numeid.value='';
	//document.getElementById('comformail').emailid.value='';
	document.getElementById('comformail').emailpid.value='';	
	document.getElementById('comformail').spamid.value='';
	document.getElementById('comformail').mesajid.value='';	
}

function stateChangedr() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{ 
document.getElementById(pagsunt1).innerHTML=xmlHttp.responseText ;
showhide(pagsunt);
}
}

function trim(var1){
	var re1 = /\s*((\S+\s*)*)/;
	var re2 = /((\s*\S+)*)\s*/;
	return var1.replace(re1, "$1").replace(re2, "$2");
}

function addSlashes(var1){
	var re = /('|")/g;
	return var1.replace(/\n/ig,' ').replace(re,"\\"+"$1");
	
}



