﻿var siteTitle = "سيارات مكتوب";
var logicalPath = "http://192.100.83.99/cars/";
function tabChange(prefix, num, cur) {
    for (var i = 1; i <= num; i++) {
        if ($$(prefix + i))
            $$(prefix + i).className = "";
    }
    if ($$(prefix + cur))
        $$(prefix + cur).className = "on";
}
function tabs_global(tabPrefix, imgPfix, contPfix, num, cur) {
    tabChange(tabPrefix, num, cur);
    for (var i = 1; i <= num; i++) {
        var strimgPfix = imgPfix + i.toString();
        var strcontPfix = contPfix + i.toString();
        if (imgPfix != "")
            $$(strimgPfix).style.display = "none";
        if ($$(strcontPfix))
            $$(strcontPfix).style.display = "none";
    }
    strcontPfix = contPfix + cur.toString();
    if ($$(strcontPfix)) {
        $$(strcontPfix).style.display = "block";
    }
    return false;
}
function ValidateEmail(ID, Msgs) {
    var EmailString = $$(ID).value;
    var EmailFormat = new RegExp(/\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/);
    if (EmailFormat.exec(EmailString) == null) {
        $$(ID).focus();
        alert(Msgs);
        return false;
    }
    return true;
}
/*CHECK if the exceeded specific length or not*/
function isValidLongText(txtID) {
    var strComment = new String($$(txtID).value);
    if (strComment.split(" ").length == 1) {
        if (strComment.length < 55) return true;
        return false;
    }
    for (var i = 0; i < strComment.split(" ").length; i++) {
        if (strComment.split(" ")[i].length > 40) {
            return false;
        }
    }
    return true;
}
/*CLEAN SPECIAL CHARS*/
function cleanInjection(txtID) {
    if ($$(txtID).type != "file") {
        var re = new RegExp("[/\!\@\#$\%\^\&\*_+\}\|\(\)\{:\?\.\<\>\'\"]", "g");
        $$(txtID).value = $$(txtID).value.trim().replace(re, "");
    }
}
var ClipSearchPage = 'SearchMedia-Clip-[KEYWORD]-1.htm';
var ZoomSearchPage = 'SearchMedia-Zoom-[KEYWORD]-1.htm';
var NewsSearchPage = 'SearchNews-[KEYWORD]-1.htm';
var ArabySearch = 'SearchAraby-[KEYWORD].htm';
function doSearch(txtID) {
    cleanInjection(txtID);
    if (!validateInput(txtID, 'الرجاء إدخال نص للبحث')) return false;
    switch (strSearchType) {
        case "Clip":
            self.location = ClipSearchPage.replace("[KEYWORD]", escape($$(txtID).value)); break;
        case "Zoom":
            self.location = ZoomSearchPage.replace("[KEYWORD]", escape($$(txtID).value)); break;
        case "News":
            self.location = NewsSearchPage.replace("[KEYWORD]", escape($$(txtID).value)); break;
        case "Internet":
            self.location = ArabySearch.replace("[KEYWORD]", escape($$(txtID).value)); break;
    }
    return false;
}
String.prototype.trim = function() {
    return this.replace(/^\s*/, "").replace(/\s*$/, "");
}
function validateInput(IDs, Msgs, btnID) {
    var strIDs = new String(IDs);
    var strMsgs = new String(Msgs);
    for (var i = 0; i < strIDs.split(",").length; i++) {
        var strCurrentID = strIDs.split(",")[i];
        var strCurrentMsg = strMsgs.split(",")[i];
        var isValid = true;
        switch ($$(strCurrentID).tagName.toLowerCase()) {
            case "select":
                if ($$(strCurrentID).value == -1)
                    isValid = false;
                break;

            case "input":
            case "textarea":
                if ($$(strCurrentID).type == "file") {
                    if ($$(strCurrentID).value != "" && $$(strCurrentID).value.toLowerCase().indexOf(".jpg") == -1) {
                        alert("(.Jpg) انواع الملفات المسموح بها فقط");
                        isValid = false;
                    }
                }
                if (strCurrentID.toLowerCase().indexOf("email") > -1) {
                    if (!ValidateEmail(strCurrentID, strCurrentMsg))
                        isValid = false;
                }
                else {
                    cleanInjection(strCurrentID);
                }

                if ($$(strCurrentID).type != "file")
                    if (!isValidLongText(strCurrentID)) {
                    alert("بعض الكلمات تحتوي على أحرف أكثر من المسموح");
                    $$(strCurrentID).select();
                    return false;
                }

                if ($$(strCurrentID).value == "")
                    isValid = false;
                break;
        }
        if (!isValid) {
            alert(strCurrentMsg);
            $$(strCurrentID).focus();
            return false;
        }
    }
    if ($$("divLoadingUpld")) $$("divLoadingUpld").style.display = "block";
    if ($$(btnID)) $$(btnID).style.display = "none";
    if ($$("btnDum")) $$("btnDum").style.display = "block"; 
    return true;
}

var moveDownVarTimer;
function scrolling(contentID, ContainerID, Direction) {
    switch (Direction) {
        case "Right":
            if ($$(ContainerID).scrollLeft > 0) {
                clearTimeout(moveDownVarTimer);
                $$(ContainerID).scrollLeft -= 3;
                if (parseInt($$("imgScrl" + contentID.replace("di","")).alt, 10) > 0) {
                    $$("imgScrl" + contentID.replace("di", "")).alt = parseInt($$("imgScrl" + contentID.replace("di", "")).alt, 10) - 2;
                    $$("imgScrl" + contentID.replace("di", "")).style.left = $$("imgScrl" + contentID.replace("di", "")).alt + "px";
                }
            }
            else {
                return false;
                clearTimeout(moveDownVarTimer);
            }
            break;
        case "Left":
            if ($$(contentID).offsetWidth > $$(ContainerID).scrollLeft - $$(ContainerID).offsetWidth) {
                clearTimeout(moveDownVarTimer);
                $$(ContainerID).scrollLeft += 3;
                if (parseInt($$("imgScrl" + contentID.replace("di", "")).alt, 10) < 190) {
                    $$("imgScrl" + contentID.replace("di", "")).alt = parseInt($$("imgScrl" + contentID.replace("di", "")).alt, 10) + 2;
                    $$("imgScrl" + contentID.replace("di", "")).style.left = $$("imgScrl" + contentID.replace("di", "")).alt + "px";
                }
            }
            else {
                return false;
                clearTimeout(moveDownVarTimer);
            }
            break;
    }
    moveDownVarTimer = setTimeout("scrolling('" + contentID + "','" + ContainerID + "','" + Direction + "');", 10);
}
function stopscroll() { clearTimeout(moveDownVarTimer); }
function navTo(url) { self.location.href = url; }

function setCookie(c_name, value, expiredays) {
    var exdate = new Date();
    exdate.setDate(exdate.getDate() + expiredays);
    document.cookie = c_name + "=" + escape(value) + ";" + ((expiredays == null) ? "" : ";expires=" + exdate.toGMTString());
}
function doVote(QID, box) {
     for (var i = 0; i < document.getElementsByName("rbVote" + QID).length; i++) {
        var tmpRdbtn = document.getElementsByName("rbVote" + QID).item(i);
        if (tmpRdbtn.checked) {
            setCookie("vote_" + QID, "1", 3);
            if (box == "Question")
                AJAXGet("Aspx_pages/Ajax_Submit.aspx?ajaxType=vote&AID=" + tmpRdbtn.value + "&r=" + parseInt(Math.random() * 100, 10), loadQuestion, "get");
            else
                AJAXGet("Aspx_pages/Ajax_Submit.aspx?ajaxType=vote&AID=" + tmpRdbtn.value + "&r=" + parseInt(Math.random() * 100, 10), loadVote, "get");
        }
    }
}
function CreatedFavoriteLink() {
    title = siteTitle;
    url = logicalPath;
    if (window.sidebar) {
        window.sidebar.addPanel(title, url, "");
    }
    else if (window.external) {
        window.external.AddFavorite(url, title);
    }
    else if (window.opera && window.print) {
        return true;
    }
}
/***********ADS**********/
 //configuration
 var documentURL = document.URL;
 if(documentURL)
  { 
  	if(documentURL.indexOf("#"))
  	 {
  		documentURL = documentURL.replace('#', '%23');
  	 }
  }
 
 OAS_url ='http://oas.maktoob.com/RealMedia/ads/';
 OAS_query = '?';
 OAS_sitepage = 'maktoob.com/cars';
 
 //OAS Analytics begin
 var d=document;
 var OAS_rdl = '';
 var OAS_CA = 'N';
 var OAS_taxonomy = '&channel=cars'+ '&if_nt_ua=' + navigator.userAgent + '&if_nt_murl=' + documentURL; //Custom Taxonomy, format &a=b&c=d
 if((d.referrer)&&(d.referrer!="[unknown origin]")) {
 	if(d.referrer.indexOf("?") == -1) {
 		OAS_rdl += '&tax23_RefDocLoc='+d.referrer.toString();
 	} else {
 		var rdl=d.referrer;
 		var rdl1=rdl.indexOf("?");
 		var rdl2=rdl.substring(0,rdl1);
 		OAS_rdl += '&tax23_RefDocLoc='+rdl2;
 	}
 }
 function cookie_check(ifd,ife) {
 	var s=ife.indexOf(ifd);
 	if(s==-1) return "";
 	s+=ifd.length;
 	var e=ife.indexOf(";",s);
 	if(e==-1) e=ife.length;
 	return ife.substring(s,e);
 }
 function write_cookie() {
 	var d=new Date();
 	var m=d.getTime();
 	document.cookie="OAS_SC1="+m.toString()+";path=/;";
 	var v=cookie_check("OAS_SC1=",document.cookie);
 	if(v!=m.toString())return false;
 	d.setTime(m+3600000);
 	return true;
 }
 if(write_cookie())OAS_CA="Y";
 //end OAS Analytics
 OAS_query += 'XE' + OAS_taxonomy + OAS_rdl + "&if_nt_CookieAccept=" + OAS_CA + '&XE';
 
 //end of configuration
 OAS_version = 10;
 OAS_rn = '001234567890'; OAS_rns = '1234567890';
 OAS_rn = new String (Math.random()); OAS_rns = OAS_rn.substring (2, 11);
 function OAS_NORMAL(pos) {
 	document.write('<A HREF="' + OAS_url + 'click_nx.ads/' + OAS_sitepage + '/1' + OAS_rns + '@' + OAS_listpos + '!' + pos + OAS_query + '" TARGET=_top>');
 	document.write('<IMG SRC="' + OAS_url + 'adstream_nx.ads/' + OAS_sitepage + '/1' + OAS_rns + '@' + OAS_listpos + '!' + pos + OAS_query + '" BORDER=0 ALT="Click!"></A>');
 }

OAS_version = 11;
if (navigator.userAgent.indexOf('Mozilla/3') != -1)
OAS_version = 10;
if (OAS_version >= 11)
document.write('<sc'+'ript language=JavaScript1.1 SRC="' + OAS_url + 'adstream_mjx.ads/' + OAS_sitepage + '/1' + OAS_rns + '@' + OAS_listpos + OAS_query + '"><\/script>');
document.write('');
function OAS_AD(pos) {
	if (OAS_version >= 11 && typeof(OAS_RICH)!='undefined')
	OAS_RICH(pos);
	else
	OAS_NORMAL(pos);
}
