function checkInvalidchar(charvalue)
{
	var invalid = "~/:<>`|^!';&*"
	for (i = 0; i < invalid.length; i++) {
		for (j = 0; j < invalid.length; j++) {
			if (charvalue.charAt(j) == invalid.charAt(i)) {
				alert("Only valid characters are allowed.");
				return false;
			}
		}
	}
	return true;
}


function getById(B) {
		return document.getElementById(B);
}


function getRequest() {
	var A;
	if (window.XMLHttpRequest) {
		A = new XMLHttpRequest()
	} else {
		if (window.ActiveXObject) {
			isIE = true;
			A = new ActiveXObject("Microsoft.XMLHTTP")
		}
	}
	return A
}

function sendRequest(target, params) {
	var xmlHttpReq = false;

	var self = this;
	// Mozilla/Safari
	if (window.XMLHttpRequest) {
	    self.xmlHttpReq = new XMLHttpRequest();
	}
	// IE
	else if (window.ActiveXObject) {
	    self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
	}
	//self.xmlHttpReq.open("POST", "YourPageHere.asp", true);
	
	self.xmlHttpReq.open("POST", target, true);
	self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');

	self.xmlHttpReq.setRequestHeader("Content-length", params.length);
	//self.xmlHttpReq.send("?YourQueryString=Value");
	self.xmlHttpReq.send(params);
}

function postToURL(url, values)
{
    values = values || {};

    var form = document.createElement("form", {action: url,
                                      method: "POST",
                                      style: "display: none"});
    for (var property in values)
    {
        if (values.hasOwnProperty(property))
        {
            var value = values[property];
            if (value instanceof Array)
            {
                for (var i = 0, l = value.length; i < l; i++)
                {
                    form.appendChild(document.createElement("input", {type: "hidden",
                                                             name: property,
                                                             value: value[i]}));
                }
            }
            else
            {
                form.appendChild(document.createElement("input", {type: "hidden",
                                                         name: property,
                                                         value: value}));
            }
        }
    }
    alert(url);
    document.body.appendChild(form);
    form.submit();
    document.body.removeChild(form);
}

function showForgotPasswordPopup(popupId) {
	hidePopup('loginPopup');
	document.getElementById("username_forgot").value = '';
	getById("errors_forgot").innerHTML = '';
	showPopup(popupId);
}

function showloginPopup(hidepopupId) {
	hidePopup(hidepopupId);
	showPopup('loginPopup');
}

function stopProfilePicUpload(success) {
	if(success == '') {
		getById("errors_profile_pic").innerHTML = 'some error has occured please upload again.';
	} else if(success == '-2'){
		getById("errors_profile_pic").innerHTML = 'You have exceeded the size limit. max is 4Mb.';
	} else {
		getById('profile_image').value = '';
		getById('profile_pic_id').innerHTML = '<img src=user_uploaded/' + success + '>';
		hidePopup('profilePicturePopup');
	}
	getById("errors_profile_pic").innerHTML = "";
	
	return true;
}

function startProfileUpload() {
	getById("errors_profile_pic").innerHTML = "<img src='gifs/ajax_loader.gif'/>";
	return true;	
}

function submitForgotPassword() {
	var B = getRequest();
	var isForgotPwd = getById("forgot_password").value;
	var email= getById("email_id").value;
	var security_code =  getById("fg_pwd_security_code").value;
	
	getById("errors_forgot_pwd").innerHTML = "<img src='gifs/ajax_loader.gif'/>";
	getById("forgot_main_data_div").style.visibility = 'hidden';
	getById("forgot_main_data_div").style.display = 'none';
	var params = "isForgotPwd="+ isForgotPwd +"&email_id=" + email +"&security_code=" + security_code ;
	
	B.open("POST", "user_action.php", true);
	B.setRequestHeader("Content-Type",
			"application/x-www-form-urlencoded; charset=UTF-8");
	
	B.onreadystatechange = function() {
		if (B.readyState == 4) {
			if (B.status == 200) {
				var response = B.responseText;
				getById('fg_pwd_captcha_img').src = 'gifs/captcha_loader.gif';
				
				if(response == 0){
					getById("errors_forgot_pwd").innerHTML = '';
					getById("forgot_info_id").innerHTML = '<br /><b>An email has been sent to your email account, Please follow the email.</b>';
				} else {
					getById("forgot_main_data_div").style.visibility = 'visible';
					getById("forgot_main_data_div").style.display = '';
					getById("fg_pwd_security_code").value = '';
					getById('fg_pwd_captcha_img').src = 'captchaSecurityImages.php?' + Math.random();
					getById("errors_forgot_pwd").innerHTML = response;
				}
			} else {
				if (B.status == 204) {
					alert("clearing table")
				}
			}
		}
	};
	B.send(params);

}

function changePassword() {
	var B = getRequest();
	var email= getById("change_pwd_email_id").value;
	var change_pwd_1= getById("change_pwd").value;
	var change_pwd_2= getById("change_pwd_2").value;
	var security_code =  getById("change_pwd_security_code").value;
	
	getById("errors_change_pwd").innerHTML = "<img src='gifs/ajax_loader.gif'/>";
	getById("change_pwd_main_data_div").style.visibility = 'hidden';
	getById("change_pwd_main_data_div").style.display = 'none';
	var params = "change_pwd_1="+ change_pwd_1+ "&change_pwd_2="+ change_pwd_2+"&email_id=" + email +"&security_code=" + security_code ;
	
	B.open("POST", "user_action.php", true);
	B.setRequestHeader("Content-Type",
			"application/x-www-form-urlencoded; charset=UTF-8");
	
	B.onreadystatechange = function() {
		if (B.readyState == 4) {
			if (B.status == 200) {
				var response = B.responseText;
				getById('change_pwd_captcha_img').src = 'gifs/captcha_loader.gif';
				if(response == 0){
					getById("errors_change_pwd").innerHTML = '';
					getById("change_pwd_info_id").innerHTML = '<br /><b>You have changed your password successfully. Please <a href="javascript: void(0);" onclick="javascript:showPopup(\'loginPopup\')">login here </a>to continue.</b>';
					getById("redirect_link").value = "home";
				} else {
					getById("change_pwd_main_data_div").style.visibility = 'visible';
					getById("change_pwd_main_data_div").style.display = '';
					getById("change_pwd_security_code").value = '';
					getById('change_pwd_captcha_img').src = 'captchaSecurityImages.php?' + Math.random();
					getById("errors_change_pwd").innerHTML = response;
				}
			} else {
				if (B.status == 204) {
					alert("clearing table")
				}
			}
		}
	};
	B.send(params);

}


function registrationPopup(popupId) {
	//alert(popupId);
	//getCaptchaImg();
	//getById('captcha_img').src = 'captchaSecurityImages.php';
	showPopup(popupId);
	//getById('captcha_img').src = 'captchaSecurityImages.php?' + Math.random();
	
}

function getCaptchaImg() {
	//alert('here');
	
	var B = getRequest();
	var params = '';
	
	B.open("POST", "captchaSecurityImages.php", true);
	
	B.onreadystatechange = function() {
		if (B.readyState == 4) {
			if (B.status == 200) {
				var response = B.responseText;
				getById('captcha_img').src = 'captchaSecurityImages.php?' + Math.random();   
			} else {
				getById('captcha_img').src = 'captchaSecurityImages.php?' + Math.random();
				if (B.status == 204) {
					alert("clearing table")
				}
			}
		}
	};
	B.send(params);
	
}

function submitLogin(id) {
	
	var B = getRequest();
	// var A = getDynamicContext();
	var username = document.getElementById("username").value;
	var password = document.getElementById("pass").value;
	
	
	var params = "username=" + username + "&pass=" + password + "&submit=submit";
	
	B.open("POST", "user_login.php", true);
	B.setRequestHeader("Content-Type",
			"application/x-www-form-urlencoded; charset=UTF-8");
	
	B.onreadystatechange = function() {
		if (B.readyState == 4) {
			if (B.status == 200) {
				var response = B.responseText;
				var redirect_link = getById("redirect_link").value;
				if(!checkEmpty(redirect_link)) {
					if(redirect_link == 'home') {
						location.href = 'index.php';
					}
				} else {
					if(response == "loggedIn") {
						hidePopup(id);
						location.reload(true);
					}else {
						getById("errors").innerHTML = response; 
					}
				}
			} else {
				if (B.status == 204) {
					alert("clearing table")
				}
			}
		}
	};
	B.send(params);

}

function submitRegistration(id) {
	var B = getRequest();
	// var A = getDynamicContext();
	var firstname = getById("firstname_rg").value;
	var lastname = getById("lastname_rg").value;
	var username = getById("username_rg").value;
	var emailAddress = getById("emailAddress_rg").value;
	var password = getById("pass_rg").value;
	var password2 = getById("pass2_rg").value;
	var security_code =  getById("security_code").value;
	var security_hint =  getById("security_hint_rg").value;
	if(!checkInvalidchar(username))
		return;
	var params = "firstname="+firstname+"&lastname="+lastname+"&username="+username+"&emailAddress=" +
	emailAddress + "&pass=" + password + "&pass2=" + password2 + "&security_code=" + security_code + "&security_hint=" + security_hint +"&submit=submit";
	//alert(params );
	//getById("rg_right_megazine_div").innerHTML = "<div align='center'><img src='gifs/ajax_loader.gif'/></div>";
	getById('f1_rg_submit_process').style.visibility = 'visible';
	B.open("POST", "user_registration.php", true);
	B.setRequestHeader("Content-Type",
			"application/x-www-form-urlencoded; charset=UTF-8");
	
	B.onreadystatechange = function() {
		if (B.readyState == 4) {
			if (B.status == 200) {
				var response = B.responseText;
				if(response == "registered") {
					getById('f1_rg_submit_process').style.visibility = 'hidden';
					getById("info_rg_success_msg").innerHTML = '<span style="font-style: italic; color: green;">' +
					'<b><u>Hey, you registered sucessfully please login to continue.</u></b></span>'
					+'<span class="green-txt10"><br /><b>What you can do after login? Rate people, suggest them the new style and fashion on Looks Book, upload your style and looks on Upload Looks or My Profile page.</b></span>'
					+'<span class="txt9grey"><br /> An email has also been sent to your email id for future help purpose.</span>';
					showloginPopup(id);
					//hidePopup(id);
					//location.reload(true);
					//getById("loginDiv").innerHTML = "welcome " + username; 
				} else {
					//getCaptchaImg();
					getById('f1_rg_submit_process').style.visibility = 'hidden';
					getById('captcha_img').src = 'captchaSecurityImages.php?' + Math.random();
					getById("errors_rg").innerHTML = response; 
				}
			} else {
				if (B.status == 204) {
					alert("clearing table")
				}
			}
		}
	};
	B.send(params);

}

function isImageDataDirty(){
	if(getById('imgSrcId') == 'undefined' || getById('imgSrcId') == null || getById('imgSrcId') == ''){
		alert('Please upload an image first.');
		return false;
	}
	for (var i = 0; i < document.forms['imageData'].elements.length; i++)
	{
	    var element = document.forms['imageData'].elements[i];
	    var type = element.type;
	    if (type == "text" || type == "textarea")
	    {
	        //var isDirty = false;
	    	if (element.value != element.defaultValue && element.value != '' 
	    		&& element.value != ' ' && element.value !=null && element.value !='null')
	        {
	    		return true;
	        }
	    } 
	}
	alert("Please fill all the required details.");
	return false;
}
    
function saveImageData() {
	if(!isImageDataDirty())
		return;
	getById('f1_look_details').style.visibility = 'visible';
	var B = getRequest();
	
	var title = removeDefault(getById("title"));
	var story_usp = removeDefault(getById("story_usp"));
	var item_1 = removeDefault(getById("item_1"));
	var item_2 = removeDefault(getById("item_2"));
	var item_details_2 = removeDefault(getById("item_details_2"));
	var item_details_1 = removeDefault(getById("item_details_1"));
	var who_look = removeDefault(getById("who_look"));
	var image_tags = removeDefault(getById("image_tags"));
	var money_factor = removeDefault(getById("money_factor"));
	
	var params = "title="+title+"&story_usp=" + story_usp + "&item_1=" + item_1 + "&item_2=" + 
	item_2 + "&item_details_2=" + item_details_2 + "&item_details_1=" + item_details_1 + 
	"&who_look=" + who_look + "&image_tags=" + image_tags + "&money_factor=" + money_factor;
	
	getById("errors_upld_img_data").style.display = 'none';
	getById("errors_upld_img_data").style.visibility = 'hidden';
	getById("info_upld_img_data").style.display = 'none';
	getById("info_upld_img_data").style.visibility = 'hidden';
	
	
	B.open("POST", "image_data.php", true);
	B.setRequestHeader("Content-Type",
			"application/x-www-form-urlencoded; charset=UTF-8");
	
	B.onreadystatechange = function() {
		if (B.readyState == 4) {
			if (B.status == 200) {
				var response = B.responseText;
				
				if(response == -3) {
					getById("errors_upld_img_data").style.display = '';
					getById("errors_upld_img_data").style.visibility = 'visible';
					getById("errors_upld_img_data").innerHTML = 'Error : Please Fill all the required fields.';
				} else {
					getById("info_upld_img_data").style.display = '';
					getById("info_upld_img_data").style.visibility = 'visible';					
					getById("info_upld_img_data").innerHTML = '<span style="font-style: italic; color: green;">'  + 
						'updated the fields sucessfully.' + '</span>';
				}
				getById('f1_look_details').style.visibility = 'hidden';
			} else {
				if (B.status == 204) {
					alert("clearing table")
				}
			}
		}
	};

	B.send(params);
}

function removeDefault(obj){
	if(obj.value == obj.defaultValue || obj.value == ' ' || obj.value == null || obj.value =='null') 
		return '';
	else 
		return obj.value;
}

function checkEmpty(strfield1){
 if (strfield1 == "" || strfield1 == null || !isNaN(strfield1) || strfield1.charAt(0) == ' ')
  {
	 return true;
  }
 return false;
}

function showRegistrationPopup(id) {
	//getCaptchaImg();
	
	getById('captcha_img').src = 'captchaSecurityImages.php?' + Math.random();
	hidePopup('loginPopup');
		
	showPopup(id);
}

function validateFileExtension(fld) {
	if(checkEmpty(getById('isUserLoggedIn').value)){
		hidePopup('profilePicturePopup');
		showPopup('loginPopup');
		return false;
	}
	
	if(!/(\.bmp|\.gif|\.png|\.jpg|\.jpeg)$/i.test(fld.value)) {
		alert("Invalid image file type.");
		fld.form.reset();
		fld.focus();
		return false;
	}
	
	return true;
}

function startUpload() {
	//getById('imgloaded').style.visibility = 'hidden';
	getById('f1_upload_process').style.visibility = 'visible';
	return true;
}

function stopUpload(success) {
	if(success == '') {
		getById('errorMsg').innerHTML = 'some error has occured please upload again.';
	} else if(success == '-1'){
		//login first
		showPopup('loginPopup');
	} else if(success == '-2'){
		getById('errorMsg').innerHTML = 'You have exceeded the max size limit of 1.5MB.';
	} else {
		//getById('imgloaded').style.visibility = 'visible';
		getById('image_path').value = '';
		getById('imageDiv').innerHTML  =
		'<input type="file" name="image" id="image_path" style="padding: 1px; color: #3b5998;" onchange="return validateFileExtension(this)">';
		getById('imgloaded').innerHTML = success;
		getById('info_upload_msg').innerHTML = '<span style="font-style: italic; color: green;"><i><u>Image uploaded sucessfully. Will be approved within next few hours for displaying in ratings.</u></i></span>';
	}
	getById('f1_upload_process').style.visibility = 'hidden';
	return true;
}

function checkKey(evt, id) {
    evt = (evt) ? evt : event;
    var target = (evt.target) ? evt.target : evt.srcElement;
    //var form = target.form;
    var charCode = (evt.charCode) ? evt.charCode :
        ((evt.which) ? evt.which : evt.keyCode);
    if (charCode == 13) {
    	submitLogin(id);
    }
    return true;
}

function changeMouseImage(id, imgSrc){

    document.getElementById(id).src=imgSrc;

}

function valueFocus(e,d) {
	if(e.value == d) e.value = '';
}

function valueBlur(e, d) {
   if(e.value == '') e.value = d;
}


function ESCclose(evt) {
 if (evt.keyCode == 27)
  window.close();
}

function limitText(limitField, limitNum) {
    
	if (limitField.value.length > limitNum) {
        limitField.value = limitField.value.substring(0, limitNum);
        alert("Max length is " + limitNum +" char only.");
    } 
}

function checkAddBrandForm() {
	for (var i = 0; i < document.forms['addbrands'].elements.length; i++)
	{
	    var element = document.forms['addbrands'].elements[i];
	    var type = element.type;
	    if (type == "text" || type == "textarea")
	    {
	        //var isDirty = false;
	    	if (element.value != '' && element.value != ' ' && element.value !=null && element.value !='null')
	        {
	    		return true;
	        }
	    } 
	} 
	alert("Please fill all the required details.");
	return false;
}

function startAddBrand() {
	if(!checkAddBrandForm()) {
		alert('check');
		return false;
	}
	if (!validateFileExtension(getById('brand_image_path')))
		return false;
	
	getById('f1_upload_process').style.visibility = 'visible';
	return true;	
}

function stopAddBrand(success) {
	if(success == '') {
		getById("errors_rg").innerHTML = '<div class="info-errors-in" id="errorMsg">some error has occured please upload again.</div>';
	} else if(success == 'notfilled') {
		getById("errors_rg").innerHTML = 'please enter all the required fields.';
	} else if(success == '-1'){
		location.href = 'index.php';
	} else if(success == '-2'){
		getById("errors_rg").innerHTML = '<div class="info-errors-in" id="errorMsg">Image exceeds the max limit of 2MB.</div>';
	} else if(success == '-3'){
		getById("errors_rg").innerHTML = '<div class="info-errors-in" id="errorMsg">Not a valid URL.</div>';
	} else {
		hidePopup('addBrandPopup');
		getById("errors_rg").innerHTML = '';
		getById("title").value = '';
		getById("brand_url").value = '';
		getById("brand_image_path").value = '';
		getById("brand_desc").value = '';
		
		getById('brandLeftSection').style.display = '';
		getById('brandLeftSection').style.visibility = 'visible';
		getById('individual_brand').style.display = 'none';
		getById('individual_brand').style.visibility = 'hidden';
		
		getTopShotsHTML();
		
		getById("brand_page").value = 0;
		getNextRecentBrands(1); 
		
		//location.reload(true);
		//getById('outputAddBrand').innerHTML = success;
		
	}
	getById('f1_upload_process').style.visibility = 'hidden';
	return true;
}

function getTopShotsHTML() {
	var B = getRequest();
	var params = 'getTopShots=true';
	
	getById("topShotsId").innerHTML= "<div align='center'><img src='gifs/ajax_loader.gif'/></div>";
	
	B.open("POST", "brand_action.php", true);
	B.setRequestHeader("Content-Type",
			"application/x-www-form-urlencoded; charset=UTF-8");
	
	B.onreadystatechange = function() {
		if (B.readyState == 4) {
			if (B.status == 200) {
				getById("topShotsId").innerHTML= B.responseText;
				//getBrandComments();
			} else {
				if (B.status == 204) {
					alert("clearing table");
				}
			}
		}
	};
	B.send(params);
}

function showAddBrandsDiv() {
	getById('addBrandDiv').style.display = '';
	getById('addBrandDiv').style.visibility = 'visible';
	
}

function showBrandPage(id) {
	getById('brandLeftSection').style.display = 'none';
	getById('brandLeftSection').style.visibility = 'hidden';
	getById('individual_brand').style.display = '';
	getById('individual_brand').style.visibility = 'visible';
	getBrand(id);
}

function getBrand(id) {

	var B = getRequest();
	var params = 'ind_brandId=' + id;
	
	getById("recentCommentsDiv").innerHTML= "<div align='center'><img src='gifs/ajax_loader.gif'/></div>";
	getById('addCommentsDiv').style.visibility = 'hidden';
	
	B.open("POST", "brand_action.php", true);
	B.setRequestHeader("Content-Type",
			"application/x-www-form-urlencoded; charset=UTF-8");
	
	B.onreadystatechange = function() {
		if (B.readyState == 4) {
			if (B.status == 200) {
				getById("ind_brand_subsection").innerHTML= B.responseText;
				
				//getById("recentCommentsDiv").innerHTML= B.responseText;
				getById('addCommentsDiv').style.visibility = 'visible';
				getById("comment_text").value = '';
				getBrandComments();
			} else {
				if (B.status == 204) {
					alert("clearing table");
				}
			}
		}
	};
	B.send(params);
}


function addBrandComments() {
	if(getById("comment_text").value.length < 60){
		alert("please enter min 60 char");
		return;
	}
	
	var B = getRequest();
	var brand_id = getById("brand_id").value;
	var comment_text = getById("comment_text").value;
	
	if(checkEmpty(comment_text)) {
		alert('Please enter a valid text.');
		return;
	}
	var params = "brand_id=" + brand_id + "&comment_text=" + comment_text;
	getById("recentCommentsDiv").innerHTML= "<div align='center'><img src='gifs/ajax_loader.gif'/></div>";
	getById('addCommentsDiv').style.visibility = 'hidden';
	
	B.open("POST", "brand_action.php", true);
	B.setRequestHeader("Content-Type",
			"application/x-www-form-urlencoded; charset=UTF-8");
	
	B.onreadystatechange = function() {
		if (B.readyState == 4) {
			if (B.status == 200) {
				getById("recentCommentsDiv").innerHTML= B.responseText;
				getById('addCommentsDiv').style.visibility = 'visible';
				getById("comment_text").value = '';
			} else {
				if (B.status == 204) {
					alert("clearing table");
				}
			}
		}
	};
	B.send(params);
}

function getBrandComments() {
	var B = getRequest();
	var brand_id = getById("brand_id").value;
	var params = 'getCommentBrandId=' + brand_id;
	
	getById("recentCommentsDiv").innerHTML= "<div align='center'><img src='gifs/ajax_loader.gif'/></div>";
	getById('addCommentsDiv').style.visibility = 'hidden';
	
	B.open("POST", "brand_action.php", true);
	B.setRequestHeader("Content-Type",
			"application/x-www-form-urlencoded; charset=UTF-8");
	
	B.onreadystatechange = function() {
		if (B.readyState == 4) {
			if (B.status == 200) {
				getById("recentCommentsDiv").innerHTML= B.responseText;
				getById('addCommentsDiv').style.visibility = 'visible';
				getById("comment_text").value = '';
			} else {
				if (B.status == 204) {
					alert("clearing table");
				}
			}
		}
	};
	B.send(params);
}

function getNextRecentBrands(pager) {
	var B = getRequest();
	var brand_page = getById("brand_page").value;
	
	var params = 'brand_page=' + brand_page + '&pointer=' + pager;
	
	getById("recent_brands").innerHTML= "<div align='center'><img src='gifs/ajax_loader.gif'/></div>";
	
	B.open("POST", "brand_action.php", true);
	B.setRequestHeader("Content-Type",
			"application/x-www-form-urlencoded; charset=UTF-8");
	
	B.onreadystatechange = function() {
		if (B.readyState == 4) {
			if (B.status == 200) {
				
				getById("recent_brands").innerHTML= B.responseText;
				
			} else {
				if (B.status == 204) {
					alert("clearing table");
				}
			}
		}
	};
	B.send(params);
}

function addDiscussion(id) {
	var B = getRequest();
	var title = getById("add_title").value;
	var forum_msg = getById("add_msg").value;
	var params = 'add_forum=true&title=' + title + '&forum_msg=' + forum_msg;
	
	getById("errors_rg").innerHTML= "<div align='center'><img src='gifs/ajax_loader.gif'/></div>";
	//getById("popup_block").style.display = 'none';
	//getById('popup_block').style.visibility = 'hidden';
	
	B.open("POST", "forum_action.php", true);
	B.setRequestHeader("Content-Type",
			"application/x-www-form-urlencoded; charset=UTF-8");
	
	B.onreadystatechange = function() {
		if (B.readyState == 4) {
			if (B.status == 200) {
				var response = B.responseText;
				
				if(response == -2){
					getById("errors_rg").innerHTML= 'Please fill all the required details.';
				} else {
					getById("errors_rg").innerHTML= '';
					getById("add_title").value = '';
					getById("add_msg").value = '';
					hidePopup(id);
					getById("forum_heading_id").style.display = '';
					getById('forum_heading_id').style.visibility = 'visible';
					getById("forum_body_div").style.display = '';
					getById('forum_body_div').style.visibility = 'visible';
					getById("main_msg_DivId").style.display = 'none';
					getById('main_msg_DivId').style.visibility = 'hidden';
					getById("link_to_forum_book").style.display = 'none';
					getById('link_to_forum_book').style.visibility = 'hidden';
					getById('info_id').innerHTML= 'sucessfully added new discussion...';
					getById('forum_body_div').innerHTML= B.responseText;
				}
			} else {
				if (B.status == 204) {
					alert("clearing table");
				}
			}
		}
	};
	B.send(params);	
}
function getForumMsges(id) {
	var B = getRequest();
	var params = 'parent_id=' + id + '&show_forum_msg=true';
	getById("forum_heading_id").style.display = 'none';
	getById('forum_heading_id').style.visibility = 'hidden';
	getById("forum_body_div").style.display = 'none';
	getById('forum_body_div').style.visibility = 'hidden';
	getById("main_msg_DivId").style.display = '';
	getById('main_msg_DivId').style.visibility = 'visible';
	
	getById("main_msg_DivId").innerHTML= "<div align='center'><img src='gifs/ajax_loader.gif'/></div>";

	B.open("POST", "forum_action.php", true);
	B.setRequestHeader("Content-Type",
			"application/x-www-form-urlencoded; charset=UTF-8");
	
	B.onreadystatechange = function() {
		if (B.readyState == 4) {
			if (B.status == 200) {
				getById("link_to_forum_book").style.display = '';
				getById('link_to_forum_book').style.visibility = 'visible';
				
				getById('main_msg_DivId').innerHTML= B.responseText;
				getById('unzip_img_heading').innerHTML
				='<a href="#" onclick="javascript:showPopup(\'forum_msg_Popup\')"><img src="gifs/chat.png" border="0"/><STRONG><FONT face=Verdana size=2>Unzip ur fashion out, Post a Reply</FONT></STRONG></a>';
				
			} else {
				if (B.status == 204) {
					alert("clearing table");
				}
			}
		}
	};
	B.send(params);	
	
}

function getNextForumsMsg(pager, id) {
	var B = getRequest();
	var forum_msg_page = getById("forum_msg_page").value;
	
	getById("errors_rg").innerHTML= "<div align='center'><img src='gifs/ajax_loader.gif'/></div>";

	var params = 'show_next_forum_msg=true&parent_id=' + id + '&forum_msg_page=' + forum_msg_page + '&pointer=' + pager;
	
	getById("forum_heading_id").style.display = 'none';
	getById('forum_heading_id').style.visibility = 'hidden';
	getById("forum_body_div").style.display = 'none';
	getById('forum_body_div').style.visibility = 'hidden';
	getById("main_msg_DivId").style.display = '';
	getById('main_msg_DivId').style.visibility = 'visible';
	
	getById("main_msg_DivId").innerHTML= "<div align='center'><img src='gifs/ajax_loader.gif'/></div>";

	B.open("POST", "forum_action.php", true);
	B.setRequestHeader("Content-Type",
			"application/x-www-form-urlencoded; charset=UTF-8");
	
	B.onreadystatechange = function() {
		if (B.readyState == 4) {
			if (B.status == 200) {
				getById("link_to_forum_book").style.display = '';
				getById('link_to_forum_book').style.visibility = 'visible';
				
				getById('main_msg_DivId').innerHTML= B.responseText;
				getById('unzip_img_heading').innerHTML
				='<a href="#" onclick="javascript:showPopup(\'forum_msg_Popup\')"><img src="gifs/chat.png" border="0"/><STRONG><FONT face=Verdana size=2>Unzip ur fashion out, Post a Reply</FONT></STRONG></a>';
				
			} else {
				if (B.status == 204) {
					alert("clearing table");
				}
			}
		}
	};
	B.send(params);	
	
}



function replyToForum(popupId) {
	var B = getRequest();
	var parent_id = getById('parent_id').value
	var forum_msg = getById("add_forum_msg").value;
	var params = 'reply_msg=true&parent_id=' + parent_id + '&add_forum_msg=' + forum_msg;
	
	getById("errors_msg").innerHTML= "<div align='center'><img src='gifs/ajax_loader.gif'/></div>";
	
	B.open("POST", "forum_action.php", true);
	B.setRequestHeader("Content-Type",
			"application/x-www-form-urlencoded; charset=UTF-8");
	
	B.onreadystatechange = function() {
		if (B.readyState == 4) {
			if (B.status == 200) {
				var response = B.responseText;
				
				if(response == -2){
					getById("errors_msg").innerHTML= 'Please fill all the required details.';
				} else {
					if(response == 'success') {
						getById("errors_msg").innerHTML= '';
						getById("add_forum_msg").value = '';
						hidePopup(popupId);
						getForumMsges(parent_id);
					}
				}
			} else {
				if (B.status == 204) {
					alert("clearing table");
				}
			}
		}
	};
	B.send(params);
}

function addLooksQuestion(popupId) {
	var B = getRequest();
	var looks_q_title = getById('looks_q_title').value
	var looks_q_question = getById("looks_q_question").value;
	var params = 'add_qsnt=true&looks_q_question=' + looks_q_question+ '&looks_q_title=' + looks_q_title;
	
	getById('errors_qsnt').style.display = '';
	getById('errors_qsnt').style.visibility = 'visible';
	
	getById("errors_qsnt").innerHTML= "<div align='center'><img src='gifs/ajax_loader.gif'/></div>";
	
	B.open("POST", "qsnt_action.php", true);
	B.setRequestHeader("Content-Type",
			"application/x-www-form-urlencoded; charset=UTF-8");
	
	B.onreadystatechange = function() {
		if (B.readyState == 4) {
			if (B.status == 200) {
				var response = B.responseText;
				
				if(response == -2){
					getById("errors_qsnt").innerHTML= 'Please fill all the required details.';
				} else if(response == -9){
					getById("errors_qsnt").innerHTML= 'some error has occured. please try again.';
					getById("looks_q_title").value = '';
					getById("looks_q_question").value = '';
				}  
				else {
					if(response == 'success') {
						getById("errors_qsnt").innerHTML= '';
						getById('errors_qsnt').style.display = 'none';
						getById('errors_qsnt').style.visibility = 'hidden';
						
						getById("looks_q_title").value = '';
						getById("looks_q_question").value = '';
						
						hidePopup(popupId);
						getById("response_qsnt").innerHTML = '<b><u> your question is added successfully. Response will be displyed and mailed to you soon. <u></b>';
						//getForumMsges(parent_id);
					}
				}
			} else {
				if (B.status == 204) {
					alert("clearing table");
				}
			}
		}
	};
	B.send(params);	
}

function getNextQsnts(pager) {
	var B = getRequest();
	var qsnt_page = getById("qsnt_page").value;
	
	var params = 'qsnt_page=' + qsnt_page + '&pointer=' + pager;
	
	getById("qsnt_main_body").innerHTML= "<div align='center'><img src='gifs/ajax_loader.gif'/></div>";
	
	B.open("POST", "qsnt_action.php", true);
	B.setRequestHeader("Content-Type",
			"application/x-www-form-urlencoded; charset=UTF-8");
	
	B.onreadystatechange = function() {
		if (B.readyState == 4) {
			if (B.status == 200) {
				getById("qsnt_main_body").innerHTML= B.responseText;
			} else {
				if (B.status == 204) {
					alert("clearing table");
				}
			}
		}
	};
	B.send(params);
}

function getNextForums(pager) {
	var B = getRequest();
	var forum_page = getById("forum_page").value;
	
	var params = 'forum_page=' + forum_page + '&pointer=' + pager;
		
	getById('forum_body_div').innerHTML= "<div align='center'><img src='gifs/ajax_loader.gif'/></div>";

	//getById("popup_block").style.display = 'none';
	//getById('popup_block').style.visibility = 'hidden';
	
	B.open("POST", "forum_action.php", true);
	B.setRequestHeader("Content-Type",
			"application/x-www-form-urlencoded; charset=UTF-8");
	
	B.onreadystatechange = function() {
		if (B.readyState == 4) {
			if (B.status == 200) {
				var response = B.responseText;
				
				if(response == -2){
					getById("errors_rg").innerHTML= 'Please fill all the required details.';
				} else {
					getById("errors_rg").innerHTML= '';
					getById("add_title").value = '';
					getById("add_msg").value = '';
					getById("forum_heading_id").style.display = '';
					getById('forum_heading_id').style.visibility = 'visible';
					getById("forum_body_div").style.display = '';
					getById('forum_body_div').style.visibility = 'visible';
					getById("main_msg_DivId").style.display = 'none';
					getById('main_msg_DivId').style.visibility = 'hidden';
					getById("link_to_forum_book").style.display = 'none';
					getById('link_to_forum_book').style.visibility = 'hidden';
					getById('forum_body_div').innerHTML= B.responseText;
				}
			} else {
				if (B.status == 204) {
					alert("clearing table");
				}
			}
		}
	};
	B.send(params);
}

function getNextArticle(pager) {
	var B = getRequest();
	var article_page = getById("article_page").value;
	
	var params = 'article_page=' + article_page + '&pointer=' + pager;
	
	getById("all_article_main_body").innerHTML= "<div align='center'><img src='gifs/ajax_loader.gif'/></div>";
	
	B.open("POST", "article_action.php", true);
	B.setRequestHeader("Content-Type",
			"application/x-www-form-urlencoded; charset=UTF-8");
	
	B.onreadystatechange = function() {
		if (B.readyState == 4) {
			if (B.status == 200) {
				getById("all_article_main_body").innerHTML= B.responseText;
			} else {
				if (B.status == 204) {
					alert("clearing table");
				}
			}
		}
	};
	B.send(params);
}

function getArticle(id) {
	var B = getRequest();
	
	var params = 'show_article=true&article_id=' + id;
	
	getById('all_article_main_body').style.display = 'none';
	getById('all_article_main_body').style.visibility = 'hidden';
	getById("article_body").style.display = '';
	
	getById('article_body').style.visibility = 'visible';
	
	getById('article_body').innerHTML= "<div align='center'><img src='gifs/ajax_loader.gif'/></div>";
	
	B.open("POST", "article_action.php", true);
	B.setRequestHeader("Content-Type",
			"application/x-www-form-urlencoded; charset=UTF-8");
	
	B.onreadystatechange = function() {
		if (B.readyState == 4) {
			if (B.status == 200) {
				getById('article_left_img').style.display = 'none';
				getById('article_left_img').style.visibility = 'hidden';
				getById("link_all_articles").style.display = '';
				getById('link_all_articles').style.visibility = 'visible';
				
				getById("article_body").innerHTML= B.responseText;
			} else {
				if (B.status == 204) {
					alert("clearing table");
				}
			}
		}
	};
	B.send(params);	
}

function showArticlePage(id) {
	var B = getRequest();
	
	var params = 'show_article=true&article_id=' + id;
	
	getById('all_article_main_body').style.display = 'none';
	getById('all_article_main_body').style.visibility = 'hidden';
	
	getById("article_body").style.display = '';
	getById('article_body').style.visibility = 'visible';
	getById('article_body').innerHTML= "<div align='center'><img src='gifs/ajax_loader.gif'/></div>";
	
	B.open("POST", "article_action.php", true);
	B.setRequestHeader("Content-Type",
			"application/x-www-form-urlencoded; charset=UTF-8");
	
	B.onreadystatechange = function() {
		if (B.readyState == 4) {
			if (B.status == 200) {
				
				getById("article_body").innerHTML= B.responseText;
			} else {
				if (B.status == 204) {
					alert("clearing table");
				}
			}
		}
	};
	B.send(params);	
}
function showMemberProfileInfo() {
	//alert('showMemberProfileInfo');
}

