function ReplacePic(label,pic){
    document.getElementById('PicActivity').src = pic;
	document.getElementById('pictureLabel').innerHTML=label;
	}
function closeRequired(){
	document.getElementById('alert_required').style.display='none';
}
function NewsFirst(id,count) {
    url = document.getElementById('UrlNews').value;
    id = document.getElementById('newsId' + count).value;
    document.getElementById('newsId' + count).value = document.getElementById('newsId1').value;
    document.getElementById('day' + count).innerHTML = document.getElementById('day1').innerHTML;
    document.getElementById('month' + count).innerHTML = document.getElementById('month1').innerHTML;
    document.getElementById('year' + count).innerHTML = document.getElementById('year1').innerHTML;
    contentObj = document.getElementById('TopNewsDesc');
    getAjaxFile(url+"/"+id);


}
var contentObj;   // refer  the  content of  <div>
function getAjaxFile(urlPage) {
    xmlHttp = CreateHttpObject()
    if (xmlHttp == null) {
        alert("Browser does not support HTTP Request")
        return
    }
    xmlHttp.onreadystatechange = stateChanged
    xmlHttp.open("GET", urlPage, true)
    xmlHttp.send(null)
}
function stateChanged(CatId) {
    if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
        contentObj.innerHTML = xmlHttp.responseText;
        //		importDate=document.getElementById('FlashDate').value;
        //		PassDate(importDate);
        init_dw_Scroll();

    }
}
function CreateHttpObject() {
    var objXMLHttp = null
    try {
        objXMLHttp = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e) {
        try {
            objXMLHttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch (err) {
            objXMLHttp = null;
        }
    }
    if (!objXMLHttp && typeof XMLHttpRequest != "undefined")
        objXMLHttp = new XMLHttpRequest();
    return objXMLHttp
}
function sendContact() {
    isValidText = true;
    isValuArea = true;
    isValidText = validateForm('FullName', 'email@@email', 'comment');
    if (isValidText) {
        document.getElementById('alert_required').style.display = 'none';
        document.getElementById('load').style.display = 'block';
        contact_name = document.getElementById("FullName").value;
        contact_email = document.getElementById("email").value;
        contact_subject = document.getElementById("comment").value;
        fromFlag = 1;
        // URL = "/Home/sendContact";
        URL = document.getElementById("Urlsend").value;
        var poststr = "contact_name=" + encodeURI(contact_name) + "&contact_email=" + encodeURI(contact_email) + "&contact_subject=" + encodeURI(contact_subject);
        //alert(poststr);
        postAjaxFile(URL, poststr);

    } else {
    document.getElementById('load').style.display = 'none';
    document.getElementById('alert_required').style.display = 'block';

    }
}
function postAjaxFile(urlPage, parameters) {
    xmlHttpPost = CreateHttpObject()
    if (xmlHttpPost == null) {
        alert("Browser does not support HTTP Request")
        return
    }

    xmlHttpPost.onreadystatechange = stateChangedPost;

    xmlHttpPost.open("POST", urlPage, true);
    xmlHttpPost.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

    xmlHttpPost.setRequestHeader("Content-length", parameters.length);
    xmlHttpPost.setRequestHeader("Connection", "close");
    xmlHttpPost.send(parameters)

}
function stateChangedPost() {
    if (xmlHttpPost.readyState == 4 || xmlHttpPost.readyState == "complete") {
        if (fromFlag == 1) {
            //alert("email has been sent")
            document.getElementById('alert_required').style.display = 'none';
            document.getElementById('load').style.display = 'none';
            document.getElementById('alert_send').style.display = 'block';

        }
    }
}
function validateForm() {
    isValid = true;
    var paramLength = arguments.length;
    for (i = 0; i < paramLength; i++) {
        parArray = arguments[i].split("@@")
        thislength = parArray.length;
        fieldName = parArray[0]

        if (thislength > 1) {
            fieldType = parArray[1];
            if (fieldType == 'email') {
                isValideEmail = validateEmail(document.getElementById(fieldName).value)
                if (!isValideEmail) {
                    oldClass = document.getElementById(fieldName).parentNode.className;
                    document.getElementById(fieldName).parentNode.className = oldClass + " required";
                    isValid = false;
                } else {
                    oldClass = document.getElementById(fieldName).parentNode.className;

                    document.getElementById(fieldName).parentNode.className = oldClass.replace(/ required/g, "");
                }

            } else if (fieldType == "confirm") {
                isValidPassword = validPassword(document.getElementById(fieldName).value, document.getElementById(fieldName + "_confirm").value)
                if (!isValidPassword) {
                    oldClass = document.getElementById(fieldName).parentNode.className
                    document.getElementById(fieldName).parentNode.className = oldClass + " required";
                    document.getElementById(fieldName + "_confirm").parentNode.className = oldClass + " required";
                    isValid = false;

                } else {

                    document.getElementById(fieldName).parentNode.className = "input_content";
                    document.getElementById(fieldName + "_confirm").parentNode.className = "input_content";
                    //isValid = true;

                }
            }
        } else {

            if (document.getElementById(fieldName).value == '') {
                oldClass = document.getElementById(fieldName).parentNode.className;
                document.getElementById(fieldName).parentNode.className = oldClass + " required";
                isValid = false;
            } else {
                oldClass = document.getElementById(fieldName).parentNode.className;
                document.getElementById(fieldName).parentNode.className = oldClass.replace(/ required/g, "");
            }
        }
    }
    return isValid;
}
function validateEmail(email) {
    var isValid = true
    var email = email
    AtPos = email.indexOf("@")
    StopPos = email.lastIndexOf(".")
    if (AtPos == -1 || StopPos == -1) {

        isValid = false;
        //alert(isValid)
    }

    return isValid;
}
