<script type="text/javascript">
var current_domain = '<?php echo $ultra_domainname;?>';

function MM_jumpMenu(targ,selObj,restore){ //v3.0
	var form = document.getElementById('formadvsearch');
	var dom = selObj.options[selObj.selectedIndex].text;
	
	if(dom != current_domain) {
		var uri = selObj.options[selObj.selectedIndex].value;
		var post_url = 'http://' + dom + '/' + uri;
		form.action = post_url;
		form.target = "_blank";
	}
	else {
		form.action = "";
		form.target = "_self";
	}
}
</script>

<?php
//echo var_export($_REQUEST, true);
$form_action = $homepage_url . '/search';
$form_target = "_self";
$catdom_id_search = (isset($_REQUEST['catdom_id_search']) && is_numeric($_REQUEST['catdom_id_search']) ) ? intval($_REQUEST['catdom_id_search']) : $domain_id;
if($catdom_id_search != $domain_id){
	$line_catdom_id_search = mysql_fetch_assoc(mysql_query("SELECT * FROM domaincategories WHERE catdom_id='$catdom_id_search'"));
	$form_action = "http://" . $line_catdom_id_search["domainname"] . '/';
	$form_target = "_blank";
}
?>
<section class="advanced-search">
    <form action="<?php echo $form_action;?>" target="<?php echo $form_target;?>" method="post"  name="formadvsearch" id="formadvsearch" class="form-horizontal">
    <div class="box box-default box-solid box-compact">
        <div class="box-header with-border">
            <i class="fa fa-search"></i>
            <b>Search Cyprus Network Portals</b>
        </div>
        <div class="box-body">
            <div class="well well-sm">
                <p>Select from the drop down menu the portal of your choice.<br />The results of the search will be displayed in a new browser window.</p>
            </div>
            <div>
                <div class="form-group">
                    <label class="control-label col-sm-3">Search in Portal </label>
                    <div class="col-sm-7">
                        <?php
                        $querycatdom_id = "SELECT * FROM  domaincategories WHERE parent_id='0' AND active='yes' ORDER BY domainname ASC";
                        $resultcatdom_id = mysql_query ($querycatdom_id);
                        if (mysql_num_rows($resultcatdom_id) <> 0){
                            ?>
                            <select class="form-control input-sm" name="catdom_id_search" id="catdom_id_search" onchange="MM_jumpMenu('parent',this,0);">
                                <?php
                                while($linecatdom_id = mysql_fetch_array($resultcatdom_id)){
                                    if($linecatdom_id["domainname"] != "www.cyprus-hotel.com") {
                                        ?>
                                        <option value="index.php?module_page=advanced_search&amp;catdom_id_search=<?php echo $linecatdom_id["catdom_id"];?>" <?php if($linecatdom_id["catdom_id"]==$catdom_id_search){echo 'selected="selected"';}?>>
                                        <?php echo $linecatdom_id["domainname"]; ?>
                                        </option>
                                        <?php
                                    }
                                }
                                ?>
                            </select>
                            <?php
                        }
                        else {
                            ?>
                            <p class="form-control-static">No domains defined yet.</p>
                            <?php
                        }
                        ?>
                    </div>
                </div>

                <?php
                if($catdom_id_search != 611){

                    $query_adv_sear_domain ="SELECT * FROM domaincategories WHERE parent_id='$catdom_id_search' AND active='yes' ORDER BY order_seq ASC";
                    //echo $query_adv_sear_domain;
                    $result_adv_sear_domain = mysql_query ($query_adv_sear_domain);
                    if($result_adv_sear_domain && mysql_num_rows($result_adv_sear_domain) > 0) {
                        //$line_adv_sear_domain = mysql_fetch_assoc($result_adv_sear_domain);
                        ?>
                        <div class="form-group">
                            <label class="control-label col-sm-3">
                            <?php
                            /*if(trim($line_adv_sear_domain["title_tr"]) == ""){
                                echo "Town";
                            }
                            else {
                                echo $line_adv_sear_domain["title_tr"];
                            }*/
                            echo 'Search in';
                            ?>
                            </label>
                            <div class="col-sm-7">
                                <select class="form-control input-sm" name="search[catdom_id]" id="search_catdom_id">
                                    <option value="" selected="selected">All</option>
                                    <?php
                                    while($linedistricts = mysql_fetch_assoc($result_adv_sear_domain)){
                                        ?>
                                        <option value="<?php echo $linedistricts["catdom_id"];?>"<?php if(isset($search["catdom_id"]) && $linedistricts["catdom_id"]==$search["catdom_id"]){echo 'selected="selected"';}?>>
                                            <?php echo str_replace("| ", "", $linedistricts["title_el"]); ?>
                                        </option>
                                        <?php
                                    }
                                    ?>
                                </select>
                            </div>
                        </div>
                        <?php
                    }
                }
                ?>
                <?php
                $query2 = "SELECT * FROM filters WHERE parent_id='$catdom_id_search' AND active='yes' ORDER BY order_seq";
                $result2 = mysql_query($query2) or die (mysql_error());
                if(mysql_num_rows($result2)<>0){
                    ?>
                    <div class="form-group">
                        <label class="control-label col-sm-3">Vortal Filters</label>
                        <div class="col-sm-7">
                            <div class="checkbox">
                                <?php
                                while($line2 = mysql_fetch_assoc($result2)){
                                    ?>
                                    <label>
                                        <input name="filter_ids[]" type="checkbox" id="filter_ids" value="<?php echo $line2["filter_id"];?>"/>
                                        <?php echo $line2["title_en"];?>
                                    </label>
                                    <?php
                                }
                                $count=1;
                                //}
                                ?>
                            </div>

                        </div>
                    </div>
                    <?php
                }
                ?>
                <div class="form-group">
                    <label class="control-label col-sm-3"> Keyword </label>
                    <div class="col-sm-7">
                        <input class="form-control input-sm" name="search[keyword]" type="text" id="adv_search_keyword"/>
                    </div>
                </div>

            </div>
        </div>
        <div class="box-footer text-center">
            <input name="search[now]" type="hidden" id="adv_search_now" value="yes"/>
            <input name="module_page" type="hidden" id="adv_module_page" value="search_adv"/>
            <button type="submit" name="Submit2" class="btn btn-primary btn-sm"><i class="fa fa-search"></i> Search</button>
            <button type="reset" name="reset" class="btn btn-default btn-sm"><i class="fa fa-times"></i> Reset</button>
        </div>
    </div>
    </form>
</section>