/* ========================================================================================= */
/* HELPER FUNCTIONS */
/* ========================================================================================= */
function beforeLogin() {
    if(document.dologin.email.value == '') { document.dologin.email.focus(); return false; }
    if(document.dologin.password.value == '') { document.dologin.password.focus(); return false; }
    return true;
}

function reloadTop(url) {
    if( parent && parent.frames[0]) {
         parent.frames[0].location.href = url;
    } 
}

function CheckLoggedIn(url) {
   authdata = GetCookie('authdata');
   authkey  = GetCookie('authkey');

   if (authdata && authkey)
       reloadTop(url);
}

function popUp(URL) {
    day = new Date();
    id = day.getTime();
    eval("page" + id + " = window.open(URL, '" + id + "','toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=585,height=365,left = 219.5,top = 91.5');");
}

function setColor(id) {
    o = document.getElementById(id);
    if ( o ) o.className = "error";

    id = 't'+id;
    o = document.getElementById(id);
    if ( o ) o.className = "error_text";
}

function checkSearchCall(){
    Sform=document.form1;
    q = Sform.q.value;
    g = Sform.g.value;
    u = Sform.u.value;
    d = '';

    if(q == '' && u == '' ){
        if(g == '' || d == '' ){
            return this.showSearchError();
        }
    }else{
        return true;
    }
}


/* ========================================================================================= */
/* NATURAL SEARCH */
/* ========================================================================================= */
// Disable frameset for d-ams	
	if (document && document.location && (hn = document.location.hostname)) {
		if (hn.indexOf('d-ams-122330') != -1) { enforce_frameset = false; }
	}
// Make sure we are in the frameset
    if (window.enforce_frameset &&  enforce_frameset == true) {       
        if( (top == self) )
        {
            var sref = check_referrer(document.referrer);
            var forward_url;
            forward_url = self.location;
            forward_url = forward_url+"";
            forward_url = urlencode(forward_url); 
            if(sref != '' && sref != 'false') {
                var url_params = '?sref='+urlencode(sref)+'&url='+forward_url;
            }    
            else {
                var url_params = '?url='+forward_url;                
            }           
            top.location.replace(wwwroot+'/index.php'+url_params);

        }
        else
        {
            var sref = "";
            //find out if the url contains the search referrer. (passed through from framing the page)            
            var qstring = window.location.search.substring(1); //everything behind the first "?"
            var qarray = new Array();
            qarray = qstring.split("&");
            for(i=0;i<qarray.length;i++){
                var tmp = qarray[i];
                if(tmp.substring(0,4) == "sref") {
                    var sref = tmp.substring(5,tmp.length);
                }
            }
            var sref = escape(check_referrer(sref));
            if(sref != '' && sref != 'false'){
                //ok got a referrer, now check whether it's a searchengine
                sref = check_referrer(unescape(sref));
            }
        }
    }

function urlencode(strText)
{
    var trimReg;
    var re;
    if( typeof(strText) == "string" )
    {
        if( strText != "" )
        {
            trimReg = /(^\s+)|(\s+$)/g;
            strText = strText.replace( trimReg, '');
            strText = escape(strText);
        }
    }
    return strText;
}

function check_referrer(sref){

    var nss = false;
    if(sref && sref != '') {

        var searchEngines=new Array("startpagina.nl","search.yahoo.com","search.msn.",".altavista.com","suche.lycos.at","www.google.at","search.aon.at/newsearch/aon/","austronaut.at/page.php","www.google.com.au","images.google.com.au","www.looksmart.com.au","ninemsn.com.au","search.aol.com.au","www.goeureka.com.au","au.anzwers.yahoo.com","www.yellowpages.com.au/search/searchEntry.do","search.bigpond.com","www.google.be","search.fr.msn.be","altavista.advalvas.be/av2/","yellow.advalvas.be/av2/scripts/YellowSearch.dll","www.google.ca","ca.yahoo.com","www.toile.qc.ca","www.alltheweb.com","www.overture.com/d/search/p/altavista/odp/ca/","www.lycos.ca","search.lycos.com/default.asp","www.looksmart.com","search.bluewin.ch/bw/search/web/de/home.html","www.search.ch","www.google.ch","www.google.com","images.google.com","directory.google.com","www.baidu.com/","image.baidu.com/","site.baidu.com/","cns.3721.com/","seek.3721.com/","page.zhongsou.com/","hc360.zhongsou.com/","site.zhongsou.com/","search.sina.com.cn/","pic.sina.com.cn/","dir.sina.com.cn/","search.sohu.com/","image.search.sohu.com/","www.sogou.com/","nisearch.163.com/","psearch.163.com/","picsearch.163.com/","search.tom.com/","sitesearch.tom.com/","cn.websearch.yahoo.com/","cn.imagesearch.yahoo.com/","www.yisou.com/search","image.yisou.com/","www.8848.com/search.dll","www.google.de/search","images.google.de/images","suche.aol.de/suche/","suche.aol.de/shopping/suche/index.jsp","suche.freenet.de/suche","shopping.freenet.de/suchergebnis/index.html","brisbane.t-online.de/fast-cgi/tsc","shopping1.t-online.de/toi/scripts/query.php","suche.web.de/search/","dir.web.de","suche.lycos.de","webkatalog.lycos.de","www.google.es","images.google.es","buscador.terra.es","buscar.ya.com","www2.yatv.com","busca.wanadoo.es/search","www.google.fr","images.google.fr","www.recherche.aol.fr","www.images.aol.fr","vachercher.lycos.fr/cgi-bin/pursuit","rechercher.nomade.tiscali.fr/recherche.asp","search.ke.voila.fr","recherche.wanadoo.fr","search1-2.free.fr","www.overture.com/d/search/p/altavista","www.google.it","search.virgilio.it","arianna.libero.it","business.libero.it/arianna/","search.tiscali.it","www.google.nl","www.ilse.nl/searchresults.dbl","pagina.nl","tw.yahoo.com","www.google.com.tw","images.google.com.tw","www.pchome.com.tw","image.pchome.com.tw","dir.pchome.com.tw","www.yam.com","wps.yam.com","dir.yam.com","www.msn.com.tw","www.google.co.uk/search","images.google.co.uk/images","search.aol.co.uk/web_uk.adp","www.ask.co.uk/res.asp","search.lycos.co.uk/cgi-bin/pursuit","search.freeserve.com/servlet/search/","images.google.com","groups.google.com","www.google.com/search","aolsearch.aol.com","search.aol.com","s.teoma.com/","www.hotbot.com","www.overture.com/d/search/p/altavista/","www.wisenut.com","web.ask.com","pictures.ask.com","search.netscape.com","veilingkijker.nl","advertentiezoeker.nl","zoekwekker.nl","marktzoeker.nl","minimarkt.nl","marktgigant.nl","totaalzoeker.nl","seekwish.nl","advertentiekijker.nl","veilingvinder.nl","veilingkijker.com","veilingvergelijker.nl","veilingzoeker.nl");
        var serp = '';

        for (var i=0; i<searchEngines.length; i++)
        {
            if (sref.indexOf(searchEngines[i]) > -1) {
                nss = sref;
                serp = searchEngines[i];
                break;
            }
        }
    }
    return nss;
}

function startpagina(sref) {
    var spurl = 'startpagina.nl';
    var sps = false;
    var serp = '';

    if(sref && sref != '') {

        if(sref.indexOf(spurl) > -1) {
            sps = sref;
            serp = spurl;
        } 
    }
    return sps;
}

function check_searchengine_referrer() {
    //if there is a searchengine referrer, load the mediaplex link.
    //sref is a global variable
    if(sref && sref != '' && sref != 'false'){
        var sp = startpagina(sref);
        if(sp && sp != '' && sp != 'false') {
            document.write('<img src="http://adfarm.mediaplex.com/ad/ck/5026-25894-4040-0" border=0 width=1 height=1>');
        }
        else {
            var rotationId = '5026-26952-11208-0';

            //strip sref passthrough parameter from location href.
            var strref = "?sref="+sref;
            var lengthhref = (document.location.href.length) - (strref.length);
            var locationhref = document.location.href.substring(0,lengthhref);

            //write tag to mediaplex
            var im = 'http://a'+'dfarm.mediaplex.com/a'+'d/lt/'+rotationId;
            im += '?mpt='+escape((new Date()).toGMTString())+"";
            im += '&mpcl='+locationhref+"";
            im += '&mpvl='+escape(unescape(sref))+"";

            document.write('<img src="'+im+'" border=0 width=1 height=1>');
        }
    }
}

function checkFPSearchCall(){
    Sform=document.search;
    q = Sform.q.value;
    g = Sform.g.value;
    if(q == '' && g == '0' ){
        return false;
    }else{
        return true;
    }
}

//Used to show/disable url link
function showBlock($var) {
    var a=document.getElementById($var);
    var b=document.getElementById("i" + $var);

    if (a.style.display == "") {
        a.style.display = "none";
        a.value = "http://";
        b.innerHTML = 'link toevoegen';
    }
    else
    {
        a.style.display = "";
        b.innerHTML = 'link verwijderen';
    }
}

/* ========================================================================================= */
/* VALIDATE ITEM SYI/RYI */
/* ========================================================================================= */
var myForm;

//browser detection
var strUserAgent = navigator.userAgent.toLowerCase();
var isIE = strUserAgent.indexOf("msie") > -1;
var isNS6 = strUserAgent.indexOf("netscape6") > -1;
var isNS4 = !isIE && !isNS6  && parseFloat(navigator.appVersion) < 5; 

//regular expressions
var reValidChars = /[0-9\.,]/;
var reKeyboardChars = /[\x00\x03\x08\x0D\x16\x18\x1A]/;
var reClipboardChars = /[cvxz]/i;

function maskKeyPress(e) {
    var iKeyCode, strKey, objInput;
    if (!e) var e = window.event;

    //if this ad has original price type of 99 then ignore this check
    if (!myForm) myForm = document.forms['ad_form'];
    if (myForm.orig_price_type && myForm.orig_price_type.value==99)
        return true;

    if (isIE)
    { iKeyCode = e.keyCode; objInput = e.srcElement; }
    else
    { iKeyCode = e.which; objInput = e.target; }
    strKey = String.fromCharCode(iKeyCode);
    if (!reValidChars.test(strKey) && !reKeyboardChars.test(strKey) && !checkClipboardCode(e, strKey))
        return false;
}

function checkClipboardCode(objEvent, strKey) {
  	if (isNS6)
	    	return objEvent.ctrlKey && reClipboardChars.test(strKey);
  	else
	    	return false;
}

function ltrim(argvalue) {

  while (1) {
    if (argvalue.substring(0, 1) != " ")
      break;
    argvalue = argvalue.substring(1, argvalue.length);
  }

  return argvalue;
}

function rtrim(argvalue) {

  while (1) {
    if (argvalue.substring(argvalue.length - 1, argvalue.length) != " ")
      break;
    argvalue = argvalue.substring(0, argvalue.length - 1);
  }

  return argvalue;
}

function trim(argvalue) {
  var tmpstr = ltrim(argvalue);

  return rtrim(tmpstr);

}

function validate_price (formSubmit) {

        var i, ch, price_txt;
	var e = window.event;

	if (!myForm) myForm = document.forms['ad_form'];
	
        //set a flag to ignore price validation if the original price type was 99
        var bSkipPriceValidation = false;
        if (myForm.orig_price_type && myForm.orig_price_type.value==99)
		bSkipPriceValidation = true;

	if (!bSkipPriceValidation) {

        	price_txt = myForm.price.value;
		if( price_txt == '' ) return true;

		if( myForm.price_type && myForm.price_type.selectedIndex > 0 ) {
			myForm.price_type.selectedIndex = 0;
		}

		//check each character is valid
        	for (i=0;i<price_txt.length;i++) {
            		ch = price_txt.charAt(i);
	    		if (!reValidChars.test(ch)) {
				alert('U mag geen rare tekens of letters\ngebruiken in het prijs veld,\nbij. het € symbol.\nVoer uw prijs in als euro\'s komma centen.\nVoorbeeld: 1.200,00');
				myForm.price.select();
				myForm.price.focus();
                		return false;
            		}
        	}

		if( price_txt.length > 2 && price_txt.indexOf(',') == -1 ) {
			if( price_txt.substr(price_txt.length - 2, 1) == '.' ) {
				var price_tmp = price_txt.substr(0, price_txt.length - 2) + ',' + price_txt.substr(price_txt.length - 1, 1) + '0';
				if( confirm("Het bedrag is niet juist.\nBedoelde u"+" "+price_tmp+" ?") )
					price_txt = price_tmp;
			}
			if( price_txt.substr(price_txt.length - 3, 1) == '.' ) {
				var price_tmp = price_txt.substr(0, price_txt.length - 3) + ',' + price_txt.substr(price_txt.length - 2, 2);
				if( confirm("Het bedrag is niet juist.\nBedoelde u"+" "+price_tmp+" ?") )
					price_txt = price_tmp;
			}
		}

		price_txt = price_txt.replace(/\./g, '');

		var tmp_array = price_txt.split(',');
		if( tmp_array.length > 2 ) {
			if( formSubmit ) {
				alert('Het bedrag is onjuist.\nVoer uw prijs in als euro\'s komma centen.\nVoorbeeld: 1.200,00');
				myForm.price.select();
				myForm.price.focus();
				return false;
			}
			return;
		}

		var euros = tmp_array[0];
  		euros = parseInt(euros, 10);
  
		var price_tmp = '';
		if( !tmp_array[1] ) { var cents = '00'; } else { var cents = tmp_array[1]+'00'; cents = cents.substr(0,2); }
		if( isNaN(euros) || isNaN(cents) ) {
			if( formSubmit ) {
				alert('Het bedrag is onjuist.\nVoer uw prijs in als euro\'s komma centen.\nVoorbeeld: 1.200,00');
				myForm.price.select();
				myForm.price.focus();
				return false;
			}
			return;
		}

		euros = euros.toString();
		cents = cents.toString();

		if( cents.length < 2 )
			{ cents = '00' + cents; cents = cents.substr(0,2); }

		var j = 0;
		for(var i=0; i<euros.length; i++) {
			j = euros.length - i - 1;
			if( i > 0 && i % 3 == 0 ) { price_tmp='.'+price_tmp; }
			price_tmp=euros.substr(j,1)+price_tmp;
		}
		price_tmp = price_tmp+','+cents;
        
        	//check the value is not above the maximum allowed value of 9999999999.99
        	var actValue = parseFloat(euros+"."+cents);
        	if (actValue > 9999999999.99) {
			alert('Uw prijs is te hoog om door Marktplaats\nverwerkt te kunnen worden.\nDe maximum prijs is € 9.999.999.999,99');
			myForm.price.select();
			myForm.price.focus();
			return false;
        	}

		myForm.price.value = price_tmp;
	}

	return true;
}

    function hide(divId) {
        if (document.layers) document.layers[divId].visibility = 'hide';
        else if (document.all) document.all[divId].style.visibility = 'hidden';
        else if (document.getElementById) document.getElementById(divId).style.visibility = 'hidden';
    
        if (document.layers) document.layers[divId].display = 'none';
        else if (document.all) document.all[divId].style.display = 'none';
        else if (document.getElementById) document.getElementById(divId).style.display = 'none';
    }
    //shows corresponding div
    function show(divId) {
        if (document.layers) document.layers[divId].visibility = 'show';
        else if (document.all) document.all[divId].style.visibility = 'visible';
        else if (document.getElementById) document.getElementById(divId).style.visibility = 'visible';
    
        if (document.layers) document.layers[divId].display = 'inline';
        else if (document.all) document.all[divId].style.display = 'inline';
        else if (document.getElementById) document.getElementById(divId).style.display = 'inline';
    }
    function showCity (b) {
			var tr = document.getElementById('trcity');
			var inp = document.getElementById('105');
			var zci = document.getElementById('zipCodeInfo');
			var pcr = document.getElementById('pc_req');
			if (b) {
				if (tr) tr.style.display = '';
				if (inp) { inp.value = ''; inp.disabled = true; inp.style.backgroundColor='#eee'; zipcode = ''; }
				if (zci) { zci.innerHTML = ''; }
				if (pcr) { pcr.style.display = 'none'; }
			}
			else {
				if (tr) tr.style.display = 'none';
				if (inp) { inp.disabled = false; inp.style.backgroundColor=''; }
				if (pcr) { pcr.style.display = ''; }
			}
	}
	function editEmail () {
			var em_input = document.getElementById('em_input');
			var em_text = document.getElementById('em_text');
			var hided_agreement = document.getElementById('hided_agreement');
			
			if(em_text) em_text.style.display = 'none';
			if(em_input) em_input.style.display = '';
			if(hided_agreement) hided_agreement.style.display = '';
            editNickName();
            editPhone();
	}
	function editNickName () {
			var name_input = document.getElementById('name_input');
			var name_text = document.getElementById('name_text');
			
			if(name_text) name_text.style.display = 'none';
			if(name_input) name_input.style.display = '';
	}
	
    function editZipcode () {
			var zipcode_input = document.getElementById('zipcode_input');
			var zipcode_text = document.getElementById('zipcode_text');
			var zipcode_inputb = document.getElementById('zipcode_inputb');
			var zipcode_textb = document.getElementById('zipcode_textb');
			
			if(zipcode_text) zipcode_text.style.display = 'none';
			if(zipcode_input) zipcode_input.style.display = '';
			if(zipcode_textb) zipcode_textb.style.display = 'none';
			if(zipcode_inputb) zipcode_inputb.style.display = '';
	}
	
    function editPhone () {
			var phone_input = document.getElementById('phone_input');
			var phone_text = document.getElementById('phone_text');
			
			if(phone_text) phone_text.style.display = 'none';
			if(phone_input) phone_input.style.display = '';
	}
	
    function checkZipChange(zipcodenow){
			if(zipcode != zipcodenow){
				zipcode = zipcodenow;
				updateZipCode(zipcodenow);
			}
	}
	function showDep(offered){
	        var bidding_dep = document.getElementById('bidding_dep');
			var price_dep = document.getElementById('price_dep');
            if (offered) {
				if (bidding_dep) bidding_dep.style.display = '';
				if (price_dep) price_dep.style.display = '';
			}
			else {
			    if (bidding_dep) bidding_dep.style.display = 'none';
				if (price_dep) price_dep.style.display = 'none';
			}
	}




/* ========================================================================================= */
/* FOTO CODE RYI
/* ========================================================================================= */

if (!images) {
var images = new Array();
    images['1'] = false;
    images['2'] = false;
    images['3'] = false;
}

    function reset (i) {
        // Reset the image
        o = document.getElementById('image_'+i);
        if (o) {
            o.innerHTML = i;
            o.className = 'img_counter';
        }
        n = i-1;
        // Remove verwijder 
        cell = document.getElementById('image_verwijder_'+i);
        if (cell) cell.innerHTML = '';
        
        // For change ad screen
        chkfotodelete = document.getElementById('chkfotodelete_'+i);
        if (chkfotodelete)
            chkfotodelete.value = 1;
    }

    function addReset(i) {
        cell = document.getElementById('image_verwijder_'+i);
        if (cell) {
            cell.innerHTML = '';
            Node = document.createElement("a");
            Node.href = "javascript:reset('"+i+"');";
            Node.appendChild(document.createTextNode('Verwijder'));
            cell.appendChild(Node);
        }
    }



/* ========================================================================================= */
/* NEW WINDOW 2 */
/* ========================================================================================= */

var win=null;
var submitted=false;

function NewWindow(mypage,myname,w,h,scroll,pos)
{
    if(pos=="random")
    {
        LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;
        TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;
    }
    else
    {
        if(pos=="center")
        {
            LeftPosition=(screen.width)?(screen.width-w)/2:100;
            TopPosition=(screen.height)?(screen.height-h)/2:100;
        }
    }

    if((pos!="center" && pos!="random") || pos==null)
    {
        LeftPosition=0;TopPosition=20
    }

    settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
    win=window.open(mypage,myname,settings);
     // Some problems with RTE and event bubbling:
     e = window.event;
     if (e) {
         if (!e.stopPropagation) 
            e.cancelBubble = true;
         //e.stopPropagation();
         e = ''; // Reset e because this function can be used multiple times with differnt e's
    }
}

function preview( origin )
{
    //oproepen van preview popup met preview van de advertentie erin
    var for_sale = "";
	var title = document.forms['mp_place_item'].title.value;
    var description = document.forms['mp_place_item'].description.value;
    var nickname = document.forms['mp_place_item'].sellername.value;
    var phone = document.forms['mp_place_item'].phone.value;
    var city = document.forms['mp_place_item'].city.value;
    var zip = document.forms['mp_place_item'].database_zip_code.value;

    if((description.length==0) && enableRTE()) {
    	   description = convertToMP(false);
    }

    var linebreak = "\r\n";
	if (origin == "place_item") {
		if (typeof(document.forms['mp_place_item'].for_sale) != "undefined") {

	    	if ( document.forms['mp_place_item'].for_sale.value == 'offered' )
	        	var for_sale = 1;
		    else
	        	var for_sale = 0;
        } else {
        	var for_sale = 'not_avail';	// probably contact ads
        }
    } else if(origin == "edit_item") { 
        if (typeof(document.forms['mp_place_item'].for_sale) != "undefined") {
            for (i=0;i<document.forms['mp_place_item'].for_sale.length;i++)
            {
	            if (document.forms['mp_place_item'].for_sale[i].checked)
                {
		          if ( document.forms['mp_place_item'].for_sale[i].value == 'offered' )
	        	      var for_sale = 1;
		          else
	        	      var for_sale = 0;
                }
            }
        } else {
        	var for_sale = 'not_avail';	// probably contact ads
        }
    } else {
		if ( document.forms['mp_place_item'].paid_or_free) {
    		if ( document.forms['mp_place_item'].paid_or_free[0].checked )
        		var for_sale = 1;
    		if ( document.forms['mp_place_item'].paid_or_free[1].checked )
        		var for_sale = 0;
    		if ( !document.forms['mp_place_item'].paid_or_free[0].checked && !document.forms['mp_place_item'].paid_or_free[1].checked )
        		var for_sale = 'empty';
        } else {
        	var for_sale = 'empty';
        }
    }
    var price = "";
    if ( document.forms['mp_place_item'].price )
        price = document.forms['mp_place_item'].price.value;
    else 
        price = "";
    if( document.forms['mp_place_item'].price_type )
        var price_type = document.forms['mp_place_item'].price_type.value;
    else
        var price_type = 'not_avail';	// probably contact ads
    if(price) price_type = 0;
    var category_id = document.forms['mp_place_item'].category_id.value;
    var zipCodeInfo = document.getElementById('zipCodeInfo');
    var paypal = document.forms['mp_place_item'].paypal.checked;
    var allow_bid = "";
    if( document.forms['mp_place_item'].allow_bid )
        allow_bid = document.forms['mp_place_item'].allow_bid.checked;
    var skype = "";
    if( document.forms['mp_place_item'].skype )
        skype = document.forms['mp_place_item'].skype.checked;
    var url = "";
    if( document.forms['mp_place_item'].url )
        url = document.forms['mp_place_item'].url.value;
	var paid = "";
	if ( document.forms['mp_place_item'].paid_or_free) {
        paid = document.forms['mp_place_item'].paid_or_free.value;
    }
        
    document.frmpreview.action="/preview_item.php";

    //popup scherm met de naam preview openen
    NewWindow('','preview','800','520','yes','center');

    win.document.write('<html><head></head>');
    win.document.write('<body>');
    win.document.write('<form name=\'myform\' action=\'/preview_item.php\' method=\'post\'>');
    win.document.write('<input type="hidden" name="description" value="'+description.replace(/\"/g, '&quot;')+'">');
    win.document.write('<input type="hidden" name="price" value="'+price+'">');
    win.document.write('<input type="hidden" name="price_type" value="'+price_type+'">');
    win.document.write('<input type="hidden" name="title" value="'+title.replace(/\"/g, '&quot;')+'">');
    win.document.write('<input type="hidden" name="sellername" value="'+nickname.replace(/\"/g, '&quot;')+'">');
    win.document.write('<input type="hidden" name="phone" value="'+phone.replace(/\"/g, '&quot;')+'">');
    win.document.write('<input type="hidden" name="for_sale" value="'+for_sale+'">');
    win.document.write('<input type="hidden" name="category_id" value="'+category_id+'">');
    win.document.write('<input type="hidden" name="paypal" value="'+paypal+'">');
    win.document.write('<input type="hidden" name="allow_bid" value="'+allow_bid+'">');
    win.document.write('<input type="hidden" name="skype" value="'+skype+'">');
    win.document.write('<input type="hidden" name="city" value="'+city+'">');
    win.document.write('<input type="hidden" name="database_zip_code" value="'+zip+'">');
    win.document.write('<input type="hidden" name="url" value="'+url.replace(/\"/g, '&quot;')+'">');
    win.document.write('<input type="hidden" name="paid" value="'+paid+'">');

    // set a hidden variable which contains the no of images the user is going to upload
    var image_count = 0;
    var max_no_images;
    for (max_no_images = 1; max_no_images < 4; max_no_images++) {
        if (document.getElementById('image_' + max_no_images)) {
            if (isNaN(document.getElementById('image_' + max_no_images).innerHTML))
                image_count++;
        }
    }
    win.document.write('<input type="hidden" name="image_count" value="'+image_count+'">');
    // end of logic for setting no. of images being uploaded

    win.document.write('</form>');
    win.document.write('Loading..');
    win.document.write('<script>document.myform.submit();</script>');
    win.document.write('</body></html>');
    win.focus();
}

/* =============================================================================
    JAVASCRIPT OBJECTS
   ============================================================================= */

function $() {
  var elements = new Array();
  for (var i = 0; i < arguments.length; i++) {
    var element = arguments[i];
    if (typeof element == 'string')
      element = document.getElementById(element);
    if (arguments.length == 1)
      return element;
    elements.push(element);
  }
  return elements;
}

Object.extend = function(destination, source) {
  for (property in source) 
    destination[property] = source[property];
  return destination;
}

/* === ELEMENTS ================================================================ */

if (!window.Element) 
  var Element = new Object();

Object.extend(Element, {
  updateHTML: function(element, html) {
    if ($(element))
        $(element).innerHTML = html;
  },

  visible: function(element) {
    return $(element).style.display != 'none';
  },

  toggle: function() {
    for (var i = 0; i < arguments.length; i++) {
      var element = $(arguments[i]);
      Element[Element.visible(element) ? 'hide' : 'show'](element);
    }
  },

  hide: function() {
    for (var i = 0; i < arguments.length; i++) {
      var element = $(arguments[i]);
      element.style.display = 'none';
    }
  },

  show: function() {
    for (var i = 0; i < arguments.length; i++) {
      var element = $(arguments[i]);
      element.style.display = '';
    }
  }
});

/* === BANNER CODE ============================================================= */

mpBan = new Object();

Object.extend(mpBan, {
    mpBanDone: function(zone,width,height) {
        width  = parseFloat(width);
        height = parseFloat(height);
        if ($('mpban_'+zone) && width > 0 && height > 0)
            mpBan.resizeIFrame(zone,width,height);
    },

    resizeIFrame: function(zone,width,height) {
        $('mpban_'+zone).style.width  = width;
        $('mpban_'+zone).style.height = height;
    }
});

/* === THE END ================================================================ */

